summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/cppcodeformatter.cpp
diff options
context:
space:
mode:
authorChristian Kamm <christian.d.kamm@nokia.com>2010-08-31 09:45:01 +0200
committerChristian Kamm <christian.d.kamm@nokia.com>2010-08-31 09:45:01 +0200
commit1862282bee2406ea4540ecc2f80b58bfc344a52b (patch)
tree2c74901fa8b2ee974b5972f4c05d6ec441e640fc /src/plugins/cpptools/cppcodeformatter.cpp
parent16367a03cab641898a8589c957a680e7591b148b (diff)
downloadqt-creator-1862282bee2406ea4540ecc2f80b58bfc344a52b.tar.gz
C++ indenter: Fix nested array/struct initializers.
Diffstat (limited to 'src/plugins/cpptools/cppcodeformatter.cpp')
-rw-r--r--src/plugins/cpptools/cppcodeformatter.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/plugins/cpptools/cppcodeformatter.cpp b/src/plugins/cpptools/cppcodeformatter.cpp
index 591c1f2d16..a162488088 100644
--- a/src/plugins/cpptools/cppcodeformatter.cpp
+++ b/src/plugins/cpptools/cppcodeformatter.cpp
@@ -1008,6 +1008,9 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
const int tokenPosition = column(tk.begin());
const bool firstToken = (tokenIndex() == 0);
const bool lastToken = (tokenIndex() == tokenCount() - 1);
+ int nextTokenStart = 0;
+ if (!lastToken)
+ nextTokenStart = column(tokenAt(tokenIndex() + 1).begin());
switch (newState) {
case namespace_start:
@@ -1136,10 +1139,14 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
break;
case brace_list_open:
- if (parentState.type != initializer)
- *indentDepth = parentState.savedIndentDepth + m_indentSize;
- else if (lastToken) {
- *savedIndentDepth = state(1).savedIndentDepth;
+ if (!lastToken) {
+ if (parentState.type == initializer)
+ *savedIndentDepth = tokenPosition;
+ *indentDepth = nextTokenStart;
+ } else {
+ // avoid existing continuation indents
+ if (parentState.type == initializer)
+ *savedIndentDepth = state(1).savedIndentDepth;
*indentDepth = *savedIndentDepth + m_indentSize;
}
break;
@@ -1256,6 +1263,7 @@ void QtStyleCodeFormatter::adjustIndent(const QList<CPlusPlus::Token> &tokens, i
} else if (topState.type != defun_open
&& topState.type != block_open
&& topState.type != substatement_open
+ && topState.type != brace_list_open
&& !topWasMaybeElse) {
*indentDepth = topState.savedIndentDepth;
}