aboutsummaryrefslogtreecommitdiffstats
path: root/src/plugins/projectexplorer/jsonwizard
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/projectexplorer/jsonwizard
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/projectexplorer/jsonwizard')
-rw-r--r--src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
index 013de06c0a..e0a06c824e 100644
--- a/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
+++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardgeneratorfactory.cpp
@@ -36,7 +36,6 @@
#include <coreplugin/dialogs/promptoverwritedialog.h>
#include <texteditor/icodestylepreferences.h>
#include <texteditor/icodestylepreferencesfactory.h>
-#include <texteditor/indenter.h>
#include <texteditor/normalindenter.h>
#include <texteditor/storagesettings.h>
#include <texteditor/tabsettings.h>
@@ -94,18 +93,22 @@ bool JsonWizardGenerator::formatFile(const JsonWizard *wizard, GeneratedFile *fi
auto baseProject = qobject_cast<Project *>(wizard->property("SelectedProject").value<QObject *>());
ICodeStylePreferencesFactory *factory = TextEditorSettings::codeStyleFactory(languageId);
+ QTextDocument doc(file->contents());
+ QTextCursor cursor(&doc);
Indenter *indenter = nullptr;
- if (factory)
- indenter = factory->createIndenter();
+ if (factory) {
+ indenter = factory->createIndenter(&doc);
+ indenter->setFileName(Utils::FileName::fromString(file->path()));
+ }
if (!indenter)
- indenter = new NormalIndenter();
-
+ indenter = new NormalIndenter(&doc);
ICodeStylePreferences *codeStylePrefs = codeStylePreferences(baseProject, languageId);
indenter->setCodeStylePreferences(codeStylePrefs);
- QTextDocument doc(file->contents());
- QTextCursor cursor(&doc);
+
cursor.select(QTextCursor::Document);
- indenter->indent(&doc, cursor, QChar::Null, codeStylePrefs->currentTabSettings());
+ indenter->indent(cursor,
+ QChar::Null,
+ codeStylePrefs->currentTabSettings());
delete indenter;
if (TextEditorSettings::storageSettings().m_cleanWhitespace) {
QTextBlock block = doc.firstBlock();