summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodeformatter.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-07-06 14:41:34 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-07-06 14:53:54 +0200
commit74ed3e8a115d6a5eeaaf52e7f37eeb80d89c95c1 (patch)
tree1503de58105737b0d9e293529c12cd65bcc7b5e1 /src/plugins/cpptools/cppcodeformatter.cpp
parent7528b2c63a5b2ff5466c755997f064a012dc4f00 (diff)
downloadqt-creator-74ed3e8a115d6a5eeaaf52e7f37eeb80d89c95c1.tar.gz
C++ indenter: Add more functions to manage the indenter state.
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r--src/plugins/cpptools/cppcodeformatter.cpp41
1 files changed, 40 insertions, 1 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index 582293ff10..89915daef5 100644
--- a/src/plugins/cpptools/cppcodeformatter.cpp
+++ b/src/plugins/cpptools/cppcodeformatter.cpp
@@ -455,6 +455,8 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
{
QStack<State> previousState = initialState();
QTextBlock it = endBlock.document()->firstBlock();
+
+ // find the first block that needs recalculation
for (; it.isValid() && it != endBlock; it = it.next()) {
TextBlockUserData *userData = BaseTextDocumentLayout::userData(it);
CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
@@ -469,10 +471,47 @@ void CodeFormatter::updateStateUntil(const QTextBlock &endBlock)
previousState = cppData->m_endState;
}
+
+ if (it == endBlock)
+ return;
+
+ // update everthing until endBlock
for (; it.isValid() && it != endBlock; it = it.next()) {
- //qDebug() << "recalc line" << it.blockNumber() + 1;
recalculateStateAfter(it);
}
+
+ // invalidate everything below by marking the state in endBlock as invalid
+ TextBlockUserData *userData = BaseTextDocumentLayout::userData(endBlock);
+ CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
+ if (cppData)
+ cppData->setBlockRevision(-1);
+}
+
+void CodeFormatter::updateLineStateChange(const QTextBlock &block)
+{
+ if (!block.isValid())
+ return;
+
+ QStack<State> oldEndState;
+
+ TextBlockUserData *userData = BaseTextDocumentLayout::userData(block);
+ CppCodeFormatterData *cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
+ if (cppData)
+ oldEndState = cppData->m_endState;
+
+ recalculateStateAfter(block);
+
+ if (oldEndState.isEmpty() || oldEndState != cppData->m_endState) {
+ // invalidate everything below by marking the next block's state as invalid
+ QTextBlock next = block.next();
+ if (!next.isValid())
+ return;
+
+ userData = BaseTextDocumentLayout::userData(next);
+ cppData = static_cast<CppCodeFormatterData *>(userData->codeFormatterData());
+ if (cppData)
+ cppData->setBlockRevision(-1);
+ }
}
CodeFormatter::State CodeFormatter::state(int belowTop) const