Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
F
flatpak-qt-creator
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Marco Bubke
flatpak-qt-creator
Commits
e4886468
Commit
e4886468
authored
Jul 05, 2010
by
Christian Kamm
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
C++ indenter: Store tab size and use it to calculate the column position
parent
19db6c98
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
1 deletion
+30
-1
src/plugins/cpptools/cppcodeformatter.cpp
src/plugins/cpptools/cppcodeformatter.cpp
+25
-1
src/plugins/cpptools/cppcodeformatter.h
src/plugins/cpptools/cppcodeformatter.h
+5
-0
No files found.
src/plugins/cpptools/cppcodeformatter.cpp
View file @
e4886468
...
...
@@ -39,6 +39,7 @@ using namespace CppTools::Internal;
CodeFormatter
::
CodeFormatter
()
:
m_indentDepth
(
0
)
,
m_tabSize
(
4
)
{
}
...
...
@@ -46,6 +47,11 @@ CodeFormatter::~CodeFormatter()
{
}
void
CodeFormatter
::
setTabSize
(
int
tabSize
)
{
m_tabSize
=
tabSize
;
}
void
CodeFormatter
::
recalculateStateAfter
(
const
QTextBlock
&
block
)
{
restoreBlockState
(
block
.
previous
());
...
...
@@ -723,6 +729,24 @@ const Token &CodeFormatter::tokenAt(int idx) const
return
m_tokens
.
at
(
idx
);
}
int
CodeFormatter
::
column
(
int
index
)
const
{
int
col
=
0
;
if
(
index
>
m_currentLine
.
length
())
index
=
m_currentLine
.
length
();
const
QChar
tab
=
QLatin1Char
(
'\t'
);
for
(
int
i
=
0
;
i
<
index
;
i
++
)
{
if
(
m_currentLine
[
i
]
==
tab
)
{
col
=
((
col
/
m_tabSize
)
+
1
)
*
m_tabSize
;
}
else
{
col
++
;
}
}
return
col
;
}
QStringRef
CodeFormatter
::
currentTokenText
()
const
{
return
m_currentLine
.
midRef
(
m_currentToken
.
begin
(),
m_currentToken
.
length
());
...
...
@@ -843,7 +867,7 @@ void QtStyleCodeFormatter::onEnter(int newState, int *indentDepth, int *savedInd
{
const
State
&
parentState
=
state
();
const
Token
&
tk
=
currentToken
();
const
int
tokenPosition
=
tk
.
begin
(
);
const
int
tokenPosition
=
column
(
tk
.
begin
()
);
const
bool
firstToken
=
(
tokenIndex
()
==
0
);
const
bool
lastToken
=
(
tokenIndex
()
==
tokenCount
()
-
1
);
...
...
src/plugins/cpptools/cppcodeformatter.h
View file @
e4886468
...
...
@@ -31,6 +31,8 @@ public:
int
indentFor
(
const
QTextBlock
&
block
);
void
invalidateCache
(
QTextDocument
*
document
);
void
setTabSize
(
int
tabSize
);
protected:
virtual
void
onEnter
(
int
newState
,
int
*
indentDepth
,
int
*
savedIndentDepth
)
const
=
0
;
virtual
void
adjustIndent
(
const
QList
<
CPlusPlus
::
Token
>
&
tokens
,
int
lexerState
,
int
*
indentDepth
)
const
=
0
;
...
...
@@ -130,6 +132,7 @@ protected:
int
tokenCount
()
const
;
const
CPlusPlus
::
Token
&
currentToken
()
const
;
const
CPlusPlus
::
Token
&
tokenAt
(
int
idx
)
const
;
int
column
(
int
position
)
const
;
bool
isBracelessState
(
int
type
)
const
;
...
...
@@ -170,6 +173,8 @@ private:
// should store indent level and padding instead
int
m_indentDepth
;
int
m_tabSize
;
friend
class
Internal
::
CppCodeFormatterData
;
};
...
...
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