summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpprefactoringchanges.cpp
diff options
context:
space:
mode:
authorLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-06-22 21:33:45 +0200
committerLeander Schulten <Leander.Schulten@rwth-aachen.de>2020-07-14 09:03:17 +0000
commitd51a419458c035dddacb4ecd316aa62cbd6315a7 (patch)
tree2038874465c4518d71eab72603303cfea28f4855 /src/plugins/cpptools/cpprefactoringchanges.cpp
parent6ac8bf2f0a48e49dc145a9b6f2a9cfb460fd4f76 (diff)
downloadqt-creator-d51a419458c035dddacb4ecd316aa62cbd6315a7.tar.gz
CppTools: Use indenter from TextDocument or create one
So if you use the ClangFormat Plugin, the ClangFormatIndenter is used and not the CppQtStyleIndenter. Change-Id: I7e71867cd4b48525ddc2f9b2dce8f13a65c3ad88 Reviewed-by: David Schulz <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cpptools/cpprefactoringchanges.cpp')
-rw-r--r--src/plugins/cpptools/cpprefactoringchanges.cpp37
1 files changed, 26 insertions, 11 deletions
diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp
index c063e1efdd..5ebd490ea6 100644
--- a/src/plugins/cpptools/cpprefactoringchanges.cpp
+++ b/src/plugins/cpptools/cpprefactoringchanges.cpp
@@ -34,6 +34,11 @@
#include <utils/qtcassert.h>
+#include <cpptools/cpptoolsconstants.h>
+#include <texteditor/icodestylepreferencesfactory.h>
+#include <texteditor/textdocument.h>
+#include <texteditor/texteditorsettings.h>
+
#include <QTextDocument>
using namespace CPlusPlus;
@@ -42,6 +47,13 @@ namespace CppTools {
class CppRefactoringChangesData : public TextEditor::RefactoringChangesData
{
+ static std::unique_ptr<TextEditor::Indenter> createIndenter(QTextDocument *textDocument)
+ {
+ TextEditor::ICodeStylePreferencesFactory *factory
+ = TextEditor::TextEditorSettings::codeStyleFactory(CppTools::Constants::CPP_SETTINGS_ID);
+ return std::unique_ptr<TextEditor::Indenter>(factory->createIndenter(textDocument));
+ }
+
public:
explicit CppRefactoringChangesData(const Snapshot &snapshot)
: m_snapshot(snapshot)
@@ -53,23 +65,26 @@ public:
const QString &fileName,
const TextEditor::TextDocument *textDocument) const override
{
- const TextEditor::TabSettings &tabSettings =
- ProjectExplorer::actualTabSettings(fileName, textDocument);
-
- CppQtStyleIndenter indenter(selection.document());
- indenter.indent(selection, QChar::Null, tabSettings);
+ if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
+ textDocument->indenter()->indent(selection, QChar::Null, textDocument->tabSettings());
+ } else {
+ const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
+ auto indenter = createIndenter(selection.document());
+ indenter->indent(selection, QChar::Null, tabSettings);
+ }
}
void reindentSelection(const QTextCursor &selection,
const QString &fileName,
const TextEditor::TextDocument *textDocument) const override
{
- const TextEditor::TabSettings &tabSettings =
- ProjectExplorer::actualTabSettings(fileName, textDocument);
-
- CppQtStyleIndenter indenter(selection.document());
- indenter.reindent(selection,
- tabSettings);
+ if (textDocument) { // use the indenter from the textDocument if there is one, can be ClangFormat
+ textDocument->indenter()->reindent(selection, textDocument->tabSettings());
+ } else {
+ const auto &tabSettings = ProjectExplorer::actualTabSettings(fileName, textDocument);
+ auto indenter = createIndenter(selection.document());
+ indenter->reindent(selection, tabSettings);
+ }
}
void fileChanged(const QString &fileName) override