summaryrefslogtreecommitdiff
path: root/src/plugins/texteditor/indenter.h
diff options
context:
space:
mode:
authorIvan Donchevskii <ivan.donchevskii@qt.io>2019-01-16 09:37:54 +0100
committerIvan Donchevskii <ivan.donchevskii@qt.io>2019-01-22 09:52:15 +0000
commitd7058e1afedfe609ff6e81222bd2137922bf7de3 (patch)
tree62d16136c8336646b8ef0ad4d220b7e0e8331203 /src/plugins/texteditor/indenter.h
parent8b5beeb952448540a3834333b694919563d81ee2 (diff)
downloadqt-creator-d7058e1afedfe609ff6e81222bd2137922bf7de3.tar.gz
ClangFormat: Refactor indenter to allow ClangFormat unit-tests
We do not build texteditor files in unit-tests so some tricks were required to make ClangFormatIndenter available. First simple unit-test proofs it builds and runs. Change-Id: I81d5ea099bd27fd1c1ed8b5b7877299dcc62a67f Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Diffstat (limited to 'src/plugins/texteditor/indenter.h')
-rw-r--r--src/plugins/texteditor/indenter.h84
1 files changed, 43 insertions, 41 deletions
diff --git a/src/plugins/texteditor/indenter.h b/src/plugins/texteditor/indenter.h
index 300e92a135..5b4b97fbfa 100644
--- a/src/plugins/texteditor/indenter.h
+++ b/src/plugins/texteditor/indenter.h
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2019 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of Qt Creator.
@@ -25,21 +25,16 @@
#pragma once
-#include "texteditor_global.h"
-
-#include "tabsettings.h"
+#include <utils/fileutils.h>
+#include <utils/optional.h>
#include <QMap>
+#include <QTextBlock>
#include <vector>
-QT_BEGIN_NAMESPACE
-class QTextDocument;
-class QTextCursor;
-class QTextBlock;
-class QChar;
-QT_END_NAMESPACE
-
-namespace Utils { class FileName; }
+namespace Utils {
+class FileName;
+}
namespace TextEditor {
@@ -48,7 +43,7 @@ class TabSettings;
using IndentationForBlock = QMap<int, int>;
-class TEXTEDITOR_EXPORT Replacement
+class Replacement
{
public:
Replacement(int offset, int length, const QString &text)
@@ -63,50 +58,57 @@ public:
using Replacements = std::vector<Replacement>;
-class TEXTEDITOR_EXPORT Indenter
+class Indenter
{
public:
- Indenter();
- virtual ~Indenter();
+ explicit Indenter(QTextDocument *doc)
+ : m_doc(doc)
+ {}
+
+ void setFileName(const Utils::FileName &fileName) { m_fileName = fileName; }
+
+ virtual ~Indenter() = default;
// Returns true if key triggers an indent.
- virtual bool isElectricCharacter(const QChar &ch) const;
+ virtual bool isElectricCharacter(const QChar & /*ch*/) const { return false; }
+
+ virtual void setCodeStylePreferences(ICodeStylePreferences * /*preferences*/) {}
+
+ virtual void invalidateCache() {}
+
+ virtual int indentFor(const QTextBlock & /*block*/, const TabSettings & /*tabSettings*/)
+ {
+ return -1;
+ }
+
+ // Expects a list of blocks in order of occurrence in the document.
+ virtual IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
+ const TabSettings & /*tabSettings*/)
+ = 0;
+ virtual Utils::optional<TabSettings> tabSettings() const = 0;
// Indent a text block based on previous line. Default does nothing
- virtual void indentBlock(QTextDocument *doc,
- const QTextBlock &block,
+ virtual void indentBlock(const QTextBlock &block,
const QChar &typedChar,
- const TabSettings &tabSettings);
+ const TabSettings &tabSettings)
+ = 0;
// Indent at cursor. Calls indentBlock for selection or current line.
- virtual void indent(QTextDocument *doc,
- const QTextCursor &cursor,
+ virtual void indent(const QTextCursor &cursor,
const QChar &typedChar,
- const TabSettings &tabSettings,
- bool autoTriggered = true);
+ const TabSettings &tabSettings)
+ = 0;
// By default just calls indent with default settings.
- virtual Replacements format(QTextDocument *doc,
- const Utils::FileName &fileName,
- const QTextCursor &cursor,
- const TabSettings &tabSettings);
+ virtual Replacements format(const QTextCursor &cursor, const TabSettings &tabSettings) = 0;
// Reindent at cursor. Selection will be adjusted according to the indentation
// change of the first block.
- virtual void reindent(QTextDocument *doc, const QTextCursor &cursor, const TabSettings &tabSettings);
-
- virtual void setCodeStylePreferences(ICodeStylePreferences *preferences);
-
- virtual void invalidateCache(QTextDocument *doc);
-
- virtual int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings);
-
- // Expects a list of blocks in order of occurrence in the document.
- virtual IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
- const TextEditor::TabSettings &tabSettings);
+ virtual void reindent(const QTextCursor &cursor, const TabSettings &tabSettings) = 0;
- virtual bool hasTabSettings() const { return false; }
- virtual TabSettings tabSettings() const { return TabSettings(); }
+protected:
+ QTextDocument *m_doc;
+ Utils::FileName m_fileName;
};
} // namespace TextEditor