Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
88480381
Commit
88480381
authored
Dec 08, 2010
by
Christian Kamm
Browse files
C++ indenter: Fix for access declarations and initializer lists.
Reviewed-by: Erik Verbruggen
parent
e49a8d9a
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppqtstyleindenter.cpp
View file @
88480381
...
...
@@ -58,6 +58,26 @@ bool CppQtStyleIndenter::isElectricCharacter(const QChar &ch) const
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
,
const
QTextBlock
&
block
,
const
QChar
&
typedChar
,
...
...
@@ -74,12 +94,9 @@ void CppQtStyleIndenter::indentBlock(QTextDocument *doc,
codeFormatter
.
indentFor
(
block
,
&
indent
,
&
padding
);
if
(
isElectricCharacter
(
typedChar
))
{
// : is only electric if the line has a 'case' or 'default'
if
(
typedChar
==
QLatin1Char
(
':'
)
&&
!
(
block
.
text
().
contains
(
QLatin1String
(
"case"
))
||
block
.
text
().
contains
(
QLatin1String
(
"default"
))))
{
// : should not be electric for labels
if
(
typedChar
==
QLatin1Char
(
':'
)
&&
!
colonIsElectric
(
block
.
text
()))
return
;
}
// only reindent the current line when typing electric characters if the
// indent is the same it would be if the line were empty
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment