diff options
author | Leandro Melo <leandro.melo@nokia.com> | 2012-01-12 13:23:48 +0100 |
---|---|---|
committer | Leandro Melo <leandro.melo@nokia.com> | 2012-01-12 15:32:02 +0100 |
commit | f04be782ab6350563ac3ed87e8ef6028a0140042 (patch) | |
tree | 8dfa2b4036f446f8d341e9744ae00758d2611361 /src/plugins/cpptools/cpprefactoringchanges.cpp | |
parent | 80a62301449b12dd8e541208c8b1a8e7bb1c6d14 (diff) | |
download | qt-creator-f04be782ab6350563ac3ed87e8ef6028a0140042.tar.gz |
C++: Preserve original indentation in extract function
Also extend the refactoring changes to allow for reindenting.
Task-number: QTCREATORBUG-6797
Change-Id: I515c9a37d9e62e1d5de52ff99bd492e739a81885
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>
Diffstat (limited to 'src/plugins/cpptools/cpprefactoringchanges.cpp')
-rw-r--r-- | src/plugins/cpptools/cpprefactoringchanges.cpp | 29 |
1 files changed, 12 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cpprefactoringchanges.cpp b/src/plugins/cpptools/cpprefactoringchanges.cpp index 4624689c61..b75fa51c0e 100644 --- a/src/plugins/cpptools/cpprefactoringchanges.cpp +++ b/src/plugins/cpptools/cpprefactoringchanges.cpp @@ -32,6 +32,7 @@ #include "cpprefactoringchanges.h" #include "cppcodestylepreferences.h" +#include "cppqtstyleindenter.h" #include <TranslationUnit.h> #include <AST.h> @@ -62,28 +63,22 @@ public: const QString &fileName, const TextEditor::BaseTextEditorWidget *textEditor) const { - // ### shares code with CPPEditor::indent() - QTextDocument *doc = selection.document(); + const TextEditor::TabSettings &tabSettings = + ProjectExplorer::actualTabSettings(fileName, textEditor); - QTextBlock block = doc->findBlock(selection.selectionStart()); - const QTextBlock end = doc->findBlock(selection.selectionEnd()).next(); + CppQtStyleIndenter indenter; + indenter.indent(selection.document(), selection, QChar::Null, tabSettings); + } + virtual void reindentSelection(const QTextCursor &selection, + const QString &fileName, + const TextEditor::BaseTextEditorWidget *textEditor) const + { const TextEditor::TabSettings &tabSettings = ProjectExplorer::actualTabSettings(fileName, textEditor); - // TODO: add similar method like above one - CppTools::QtStyleCodeFormatter codeFormatter(tabSettings, - CppToolsSettings::instance()->cppCodeStyle()->codeStyleSettings()); - codeFormatter.updateStateUntil(block); - - do { - int indent; - int padding; - codeFormatter.indentFor(block, &indent, &padding); - tabSettings.indentLine(block, indent + padding, padding); - codeFormatter.updateLineStateChange(block); - block = block.next(); - } while (block.isValid() && block != end); + CppQtStyleIndenter indenter; + indenter.reindent(selection.document(), selection, tabSettings); } virtual void fileChanged(const QString &fileName) |