aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/glsleditor
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/glsleditor
parent8b5beeb952448540a3834333b694919563d81ee2 (diff)
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/glsleditor')
-rw-r--r--src/plugins/glsleditor/glsleditor.cpp2
-rw-r--r--src/plugins/glsleditor/glslindenter.cpp50
-rw-r--r--src/plugins/glsleditor/glslindenter.h18
3 files changed, 34 insertions, 36 deletions
diff --git a/src/plugins/glsleditor/glsleditor.cpp b/src/plugins/glsleditor/glsleditor.cpp
index 33a4dafa47..c018e15f90 100644
--- a/src/plugins/glsleditor/glsleditor.cpp
+++ b/src/plugins/glsleditor/glsleditor.cpp
@@ -319,7 +319,7 @@ GlslEditorFactory::GlslEditorFactory()
setDocumentCreator([]() { return new TextDocument(Constants::C_GLSLEDITOR_ID); });
setEditorWidgetCreator([]() { return new GlslEditorWidget; });
- setIndenterCreator([]() { return new GlslIndenter; });
+ setIndenterCreator([](QTextDocument *doc) { return new GlslIndenter(doc); });
setSyntaxHighlighterCreator([]() { return new GlslHighlighter; });
setCommentDefinition(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(new GlslCompletionAssistProvider);
diff --git a/src/plugins/glsleditor/glslindenter.cpp b/src/plugins/glsleditor/glslindenter.cpp
index b2c533f1e2..87b12f98e9 100644
--- a/src/plugins/glsleditor/glslindenter.cpp
+++ b/src/plugins/glsleditor/glslindenter.cpp
@@ -38,26 +38,25 @@
namespace GlslEditor {
namespace Internal {
+GlslIndenter::GlslIndenter(QTextDocument *doc)
+ : TextEditor::TextIndenter(doc)
+{}
GlslIndenter::~GlslIndenter() = default;
bool GlslIndenter::isElectricCharacter(const QChar &ch) const
{
- return ch == QLatin1Char('{')
- || ch == QLatin1Char('}')
- || ch == QLatin1Char(':')
- || ch == QLatin1Char('#');
+ return ch == QLatin1Char('{') || ch == QLatin1Char('}') || ch == QLatin1Char(':')
+ || ch == QLatin1Char('#');
}
-void GlslIndenter::indentBlock(QTextDocument *doc,
- const QTextBlock &block,
+void GlslIndenter::indentBlock(const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings)
{
- Q_UNUSED(doc)
-
// TODO: do something with it
- CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
- CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
+ CppTools::QtStyleCodeFormatter
+ codeFormatter(tabSettings,
+ CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(block);
int indent;
@@ -77,19 +76,19 @@ void GlslIndenter::indentBlock(QTextDocument *doc,
tabSettings.indentLine(block, indent + padding, padding);
}
-void GlslIndenter::indent(QTextDocument *doc,
- const QTextCursor &cursor,
+void GlslIndenter::indent(const QTextCursor &cursor,
const QChar &typedChar,
- const TextEditor::TabSettings &tabSettings,
- bool /*autoTriggered*/)
+ const TextEditor::TabSettings &tabSettings)
{
if (cursor.hasSelection()) {
- QTextBlock block = doc->findBlock(cursor.selectionStart());
- const QTextBlock end = doc->findBlock(cursor.selectionEnd()).next();
+ QTextBlock block = m_doc->findBlock(cursor.selectionStart());
+ const QTextBlock end = m_doc->findBlock(cursor.selectionEnd()).next();
// TODO: do something with it
CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
- CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
+ CppTools::CppToolsSettings::instance()
+ ->cppCodeStyle()
+ ->codeStyleSettings());
codeFormatter.updateStateUntil(block);
QTextCursor tc = cursor;
@@ -104,14 +103,15 @@ void GlslIndenter::indent(QTextDocument *doc,
} while (block.isValid() && block != end);
tc.endEditBlock();
} else {
- indentBlock(doc, cursor.block(), typedChar, tabSettings);
+ indentBlock(cursor.block(), typedChar, tabSettings);
}
}
int GlslIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings)
{
- CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
- CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
+ CppTools::QtStyleCodeFormatter
+ codeFormatter(tabSettings,
+ CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(block);
int indent;
@@ -121,12 +121,12 @@ int GlslIndenter::indentFor(const QTextBlock &block, const TextEditor::TabSettin
return indent;
}
-TextEditor::IndentationForBlock
-GlslIndenter::indentationForBlocks(const QVector<QTextBlock> &blocks,
- const TextEditor::TabSettings &tabSettings)
+TextEditor::IndentationForBlock GlslIndenter::indentationForBlocks(
+ const QVector<QTextBlock> &blocks, const TextEditor::TabSettings &tabSettings)
{
- CppTools::QtStyleCodeFormatter codeFormatter(tabSettings,
- CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
+ CppTools::QtStyleCodeFormatter
+ codeFormatter(tabSettings,
+ CppTools::CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings());
codeFormatter.updateStateUntil(blocks.last());
diff --git a/src/plugins/glsleditor/glslindenter.h b/src/plugins/glsleditor/glslindenter.h
index 75495f8303..beb6aaa849 100644
--- a/src/plugins/glsleditor/glslindenter.h
+++ b/src/plugins/glsleditor/glslindenter.h
@@ -25,31 +25,29 @@
#pragma once
-#include <texteditor/indenter.h>
+#include <texteditor/textindenter.h>
namespace GlslEditor {
namespace Internal {
-class GlslIndenter : public TextEditor::Indenter
+class GlslIndenter : public TextEditor::TextIndenter
{
public:
+ explicit GlslIndenter(QTextDocument *doc);
~GlslIndenter() override;
bool isElectricCharacter(const QChar &ch) const override;
- void indentBlock(QTextDocument *doc,
- const QTextBlock &block,
+ void indentBlock(const QTextBlock &block,
const QChar &typedChar,
const TextEditor::TabSettings &tabSettings) override;
- void indent(QTextDocument *doc,
- const QTextCursor &cursor,
+ void indent(const QTextCursor &cursor,
const QChar &typedChar,
- const TextEditor::TabSettings &tabSettings,
- bool autoTriggered = true) override;
+ const TextEditor::TabSettings &tabSettings) override;
int indentFor(const QTextBlock &block, const TextEditor::TabSettings &tabSettings) override;
- TextEditor::IndentationForBlock indentationForBlocks(const QVector<QTextBlock> &blocks,
- const TextEditor::TabSettings &tabSettings) override;
+ TextEditor::IndentationForBlock indentationForBlocks(
+ const QVector<QTextBlock> &blocks, const TextEditor::TabSettings &tabSettings) override;
};
} // namespace Internal