summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cpprefactoringchanges.cpp
diff options
context:
space:
mode:
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