Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Q
qt-creator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Tobias Hunger
qt-creator
Commits
a5156e62
"README.md" did not exist on "70d6b50fc7c22f3c142f8626694334d6782b02f1"
Commit
a5156e62
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Introduced MatchingText::shouldInsertNewline() and use it to insert lines after a class definition.
parent
9a799da6
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/cplusplus/MatchingText.cpp
+41
-5
41 additions, 5 deletions
src/libs/cplusplus/MatchingText.cpp
src/libs/cplusplus/MatchingText.h
+3
-0
3 additions, 0 deletions
src/libs/cplusplus/MatchingText.h
with
44 additions
and
5 deletions
src/libs/cplusplus/MatchingText.cpp
+
41
−
5
View file @
a5156e62
...
...
@@ -30,11 +30,13 @@
#include
"BackwardsScanner.h"
#include
<Token.h>
#include
<QtDebug>
#include
<QtGui/QTextDocument>
#include
<QtCore/QtDebug>
using
namespace
CPlusPlus
;
enum
{
MAX_NUM_LINES
=
40
0
};
enum
{
MAX_NUM_LINES
=
2
0
};
static
bool
maybeOverrideChar
(
const
QChar
&
ch
)
{
...
...
@@ -160,6 +162,28 @@ QString MatchingText::insertMatchingBrace(const QTextCursor &cursor, const QStri
return
result
;
}
bool
MatchingText
::
shouldInsertNewline
(
const
QTextCursor
&
tc
)
const
{
QTextDocument
*
doc
=
tc
.
document
();
int
pos
=
tc
.
selectionEnd
();
// count the number of empty lines.
int
newlines
=
0
;
for
(
int
e
=
doc
->
characterCount
();
pos
!=
e
;
++
pos
)
{
const
QChar
ch
=
doc
->
characterAt
(
pos
);
if
(
!
ch
.
isSpace
())
break
;
else
if
(
ch
==
QChar
::
ParagraphSeparator
)
++
newlines
;
}
if
(
newlines
<=
1
&&
doc
->
characterAt
(
pos
)
!=
QLatin1Char
(
'}'
))
return
true
;
return
false
;
}
QString
MatchingText
::
insertParagraphSeparator
(
const
QTextCursor
&
tc
)
const
{
BackwardsScanner
tk
(
tc
,
QString
(),
MAX_NUM_LINES
);
...
...
@@ -189,8 +213,15 @@ QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
if
(
current
.
is
(
T_EOF_SYMBOL
))
break
;
else
if
(
current
.
is
(
T_CLASS
)
||
current
.
is
(
T_STRUCT
)
||
current
.
is
(
T_UNION
))
return
QLatin1String
(
"};"
);
// found a class key.
else
if
(
current
.
is
(
T_CLASS
)
||
current
.
is
(
T_STRUCT
)
||
current
.
is
(
T_UNION
))
{
// found a class key.
QString
str
=
QLatin1String
(
"};"
);
if
(
shouldInsertNewline
(
tc
))
str
+=
QLatin1Char
(
'\n'
);
return
str
;
}
else
if
(
current
.
is
(
T_NAMESPACE
))
return
QLatin1String
(
"}"
);
// found a namespace declaration
...
...
@@ -250,7 +281,12 @@ QString MatchingText::insertParagraphSeparator(const QTextCursor &tc) const
}
// if we reached this point there is a good chance that we are parsing a function definition
return
QLatin1String
(
"}"
);
QString
str
=
QLatin1String
(
"}"
);
if
(
shouldInsertNewline
(
tc
))
str
+=
QLatin1Char
(
'\n'
);
return
str
;
}
// match the block
...
...
This diff is collapsed.
Click to expand it.
src/libs/cplusplus/MatchingText.h
+
3
−
0
View file @
a5156e62
...
...
@@ -44,6 +44,9 @@ public:
QString
insertMatchingBrace
(
const
QTextCursor
&
tc
,
const
QString
&
text
,
const
QChar
&
la
,
int
*
skippedChars
)
const
;
QString
insertParagraphSeparator
(
const
QTextCursor
&
tc
)
const
;
private:
bool
shouldInsertNewline
(
const
QTextCursor
&
tc
)
const
;
};
}
// end of namespace CPlusPlus
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment