summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2014-04-30 22:55:59 +0300
committerOrgad Shaneh <orgads@gmail.com>2014-05-15 11:40:56 +0200
commitefe316f81188df1f412d48edeeafc744ed9f71c1 (patch)
treeb0857b6684fdae682f73480f215aab7b89a7ceb9
parent152f9c36463ed5f128f30e237e9697ae8fca810b (diff)
downloadqt-creator-efe316f81188df1f412d48edeeafc744ed9f71c1.tar.gz
CppTools: Define '<' and '>' as electrical characters
Required for auto-indenting stream operations. For example: std::cout << foo << bar; without explicitly invoking the indenter. Change-Id: I3a88083af5295709dfecb384538078e236119b0b Reviewed-by: Nikolai Kosjar <nikolai.kosjar@digia.com> Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
-rw-r--r--src/plugins/cpptools/cppqtstyleindenter.cpp43
1 files changed, 26 insertions, 17 deletions
diff --git a/src/plugins/cpptools/cppqtstyleindenter.cpp b/src/plugins/cpptools/cppqtstyleindenter.cpp
index ebb845390f..eb557a9bde 100644
--- a/src/plugins/cpptools/cppqtstyleindenter.cpp
+++ b/src/plugins/cpptools/cppqtstyleindenter.cpp
@@ -58,30 +58,39 @@ bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const
case '}':
case ':':
case '#':
+ case '<':
+ case '>':
return true;
}
return false;
}
-static bool colonIsElectric(const QString &text)
+static bool isElectricInLine(const QChar ch, const QString &text)
{
- // switch cases and access declarations should be reindented
- if (text.contains(QLatin1String("case"))
- || text.contains(QLatin1String("default"))
- || text.contains(QLatin1String("public"))
- || text.contains(QLatin1String("private"))
- || text.contains(QLatin1String("protected"))
- || text.contains(QLatin1String("signals"))
- || text.contains(QLatin1String("Q_SIGNALS"))) {
- return true;
+ switch (ch.toLatin1()) {
+ case ':':
+ // switch cases and access declarations should be reindented
+ if (text.contains(QLatin1String("case"))
+ || text.contains(QLatin1String("default"))
+ || text.contains(QLatin1String("public"))
+ || text.contains(QLatin1String("private"))
+ || text.contains(QLatin1String("protected"))
+ || text.contains(QLatin1String("signals"))
+ || text.contains(QLatin1String("Q_SIGNALS"))) {
+ return true;
+ }
+
+ // fall-through
+ // lines that start with : might have a constructor initializer list
+ case '<':
+ case '>': {
+ // Electrical if at line beginning (after space indentation)
+ const QString trimmedtext = text.trimmed();
+ return !trimmedtext.isEmpty() && trimmedtext.at(0) == ch;
+ }
}
- // lines that start with : might have a constructor initializer list
- const QString trimmedtext = text.trimmed();
- if (!trimmedtext.isEmpty() && trimmedtext.at(0) == QLatin1Char(':'))
- return true;
-
- return false;
+ return true;
}
void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
@@ -100,7 +109,7 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
if (isElectricCharacter(typedChar)) {
// : should not be electric for labels
- if (typedChar == QLatin1Char(':') && !colonIsElectric(block.text()))
+ if (!isElectricInLine(typedChar, block.text()))
return;
// only reindent the current line when typing electric characters if the