Commit 88480381 authored by Christian Kamm's avatar Christian Kamm
Browse files

C++ indenter: Fix for access declarations and initializer lists.

Reviewed-by: Erik Verbruggen
parent e49a8d9a
...@@ -58,6 +58,26 @@ bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const ...@@ -58,6 +58,26 @@ bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const
return false; return false;
} }
static bool colonIsElectric(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"))) {
return true;
}
// 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;
}
void CppQtStyleIndenter::indentBlock(QTextDocument *doc, void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
const QTextBlock &block, const QTextBlock &block,
const QChar &typedChar, const QChar &typedChar,
...@@ -74,12 +94,9 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc, ...@@ -74,12 +94,9 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
codeFormatter.indentFor(block, &indent, &padding); codeFormatter.indentFor(block, &indent, &padding);
if (isElectricCharacter(typedChar)) { if (isElectricCharacter(typedChar)) {
// : is only electric if the line has a 'case' or 'default' // : should not be electric for labels
if (typedChar == QLatin1Char(':') if (typedChar == QLatin1Char(':') && !colonIsElectric(block.text()))
&& !(block.text().contains(QLatin1String("case"))
|| block.text().contains(QLatin1String("default")))) {
return; return;
}
// only reindent the current line when typing electric characters if the // only reindent the current line when typing electric characters if the
// indent is the same it would be if the line were empty // indent is the same it would be if the line were empty
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment