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
Tobias Hunger
qt-creator
Commits
e086c67e
Commit
e086c67e
authored
Jul 06, 2010
by
Christian Kamm
Browse files
C++ editor: Use the new indenter to make indenting selections fast.
parent
74ed3e8a
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/plugins/cppeditor/cppeditor.cpp
View file @
e086c67e
...
...
@@ -1512,14 +1512,9 @@ bool CPPEditor::isInComment(const QTextCursor &cursor) const
return
false
;
}
void
CPPEditor
::
indentBlock
(
QTextDocument
*
doc
,
QTextBlock
block
,
QChar
typedChar
)
static
CppTools
::
QtStyleCodeFormatter
setupCodeFormatter
(
const
TextEditor
::
TabSettings
&
ts
)
{
Q_UNUSED
(
doc
)
Q_UNUSED
(
typedChar
)
const
TabSettings
&
ts
=
tabSettings
();
CppTools
::
QtStyleCodeFormatter
codeFormatter
;
codeFormatter
.
setIndentSize
(
ts
.
m_indentSize
);
codeFormatter
.
setTabSize
(
ts
.
m_tabSize
);
if
(
ts
.
m_indentBraces
&&
ts
.
m_doubleIndentBlocks
)
{
// gnu style
...
...
@@ -1538,12 +1533,46 @@ void CPPEditor::indentBlock(QTextDocument *doc, QTextBlock block, QChar typedCha
codeFormatter
.
setIndentDeclarationBraces
(
false
);
codeFormatter
.
setIndentDeclarationMembers
(
true
);
}
return
codeFormatter
;
}
void
CPPEditor
::
indentBlock
(
QTextDocument
*
doc
,
QTextBlock
block
,
QChar
typedChar
)
{
Q_UNUSED
(
doc
)
Q_UNUSED
(
typedChar
)
const
TabSettings
&
ts
=
tabSettings
();
CppTools
::
QtStyleCodeFormatter
codeFormatter
=
setupCodeFormatter
(
ts
);
codeFormatter
.
updateStateUntil
(
block
);
const
int
depth
=
codeFormatter
.
indentFor
(
block
);
ts
.
indentLine
(
block
,
depth
);
}
void
CPPEditor
::
indent
(
QTextDocument
*
doc
,
const
QTextCursor
&
cursor
,
QChar
typedChar
)
{
Q_UNUSED
(
doc
)
Q_UNUSED
(
typedChar
)
maybeClearSomeExtraSelections
(
cursor
);
if
(
cursor
.
hasSelection
())
{
QTextBlock
block
=
doc
->
findBlock
(
cursor
.
selectionStart
());
const
QTextBlock
end
=
doc
->
findBlock
(
cursor
.
selectionEnd
()).
next
();
const
TabSettings
&
ts
=
tabSettings
();
CppTools
::
QtStyleCodeFormatter
codeFormatter
=
setupCodeFormatter
(
ts
);
codeFormatter
.
updateStateUntil
(
block
);
do
{
ts
.
indentLine
(
block
,
codeFormatter
.
indentFor
(
block
));
codeFormatter
.
updateLineStateChange
(
block
);
block
=
block
.
next
();
}
while
(
block
.
isValid
()
&&
block
!=
end
);
}
else
{
indentBlock
(
doc
,
cursor
.
block
(),
typedChar
);
}
}
bool
CPPEditor
::
event
(
QEvent
*
e
)
{
switch
(
e
->
type
())
{
...
...
src/plugins/cppeditor/cppeditor.h
View file @
e086c67e
...
...
@@ -237,6 +237,7 @@ private:
bool
sortedMethodOverview
()
const
;
CPlusPlus
::
Symbol
*
findDefinition
(
CPlusPlus
::
Symbol
*
symbol
,
const
CPlusPlus
::
Snapshot
&
snapshot
);
virtual
void
indentBlock
(
QTextDocument
*
doc
,
QTextBlock
block
,
QChar
typedChar
);
virtual
void
indent
(
QTextDocument
*
doc
,
const
QTextCursor
&
cursor
,
QChar
typedChar
);
TextEditor
::
ITextEditor
*
openCppEditorAt
(
const
QString
&
fileName
,
int
line
,
int
column
=
0
);
...
...
src/plugins/texteditor/basetexteditor.h
View file @
e086c67e
...
...
@@ -476,6 +476,8 @@ protected:
*/
virtual
bool
openLink
(
const
Link
&
link
);
void
maybeClearSomeExtraSelections
(
const
QTextCursor
&
cursor
);
protected
slots
:
virtual
void
slotUpdateExtraAreaWidth
();
virtual
void
slotModificationChanged
(
bool
);
...
...
@@ -500,8 +502,6 @@ private:
void
updateHighlights
();
void
updateCurrentLineHighlight
();
void
maybeClearSomeExtraSelections
(
const
QTextCursor
&
cursor
);
void
drawFoldingMarker
(
QPainter
*
painter
,
const
QPalette
&
pal
,
const
QRect
&
rect
,
bool
expanded
,
...
...
Write
Preview
Supports
Markdown
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