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
8a73554d
Commit
8a73554d
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Initialize the members.
parent
4abd0aef
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/libs/utils/changeset.cpp
+37
-21
37 additions, 21 deletions
src/libs/utils/changeset.cpp
src/libs/utils/changeset.h
+12
-4
12 additions, 4 deletions
src/libs/utils/changeset.h
with
49 additions
and
25 deletions
src/libs/utils/changeset.cpp
+
37
−
21
View file @
8a73554d
...
@@ -44,7 +44,7 @@
...
@@ -44,7 +44,7 @@
namespace
Utils
{
namespace
Utils
{
ChangeSet
::
ChangeSet
()
ChangeSet
::
ChangeSet
()
:
string
(
0
),
cursor
(
0
)
:
m_
string
(
0
),
m_
cursor
(
0
)
{
{
}
}
...
@@ -85,6 +85,14 @@ bool ChangeSet::hasMoveInto(int pos, int length)
...
@@ -85,6 +85,14 @@ bool ChangeSet::hasMoveInto(int pos, int length)
return
false
;
return
false
;
}
}
bool
ChangeSet
::
isEmpty
()
const
{
if
(
m_replaceList
.
isEmpty
()
&&
m_moveList
.
isEmpty
())
return
true
;
return
false
;
}
QList
<
ChangeSet
::
Replace
>
ChangeSet
::
replaceList
()
const
QList
<
ChangeSet
::
Replace
>
ChangeSet
::
replaceList
()
const
{
{
return
m_replaceList
;
return
m_replaceList
;
...
@@ -95,6 +103,14 @@ QList<ChangeSet::Move> ChangeSet::moveList() const
...
@@ -95,6 +103,14 @@ QList<ChangeSet::Move> ChangeSet::moveList() const
return
m_moveList
;
return
m_moveList
;
}
}
void
ChangeSet
::
clear
()
{
m_string
=
0
;
m_cursor
=
0
;
m_replaceList
.
clear
();
m_moveList
.
clear
();
}
void
ChangeSet
::
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
)
void
ChangeSet
::
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
)
{
{
Q_ASSERT
(
!
hasOverlap
(
pos
,
length
));
Q_ASSERT
(
!
hasOverlap
(
pos
,
length
));
...
@@ -145,24 +161,24 @@ void ChangeSet::doReplace(const Replace &replace)
...
@@ -145,24 +161,24 @@ void ChangeSet::doReplace(const Replace &replace)
}
}
}
}
if
(
string
)
{
if
(
m_
string
)
{
string
->
replace
(
replace
.
pos
,
replace
.
length
,
replace
.
replacement
);
m_
string
->
replace
(
replace
.
pos
,
replace
.
length
,
replace
.
replacement
);
}
else
if
(
cursor
)
{
}
else
if
(
m_
cursor
)
{
cursor
->
setPosition
(
replace
.
pos
);
m_
cursor
->
setPosition
(
replace
.
pos
);
cursor
->
setPosition
(
replace
.
pos
+
replace
.
length
,
QTextCursor
::
KeepAnchor
);
m_
cursor
->
setPosition
(
replace
.
pos
+
replace
.
length
,
QTextCursor
::
KeepAnchor
);
cursor
->
insertText
(
replace
.
replacement
);
m_
cursor
->
insertText
(
replace
.
replacement
);
}
}
}
}
void
ChangeSet
::
doMove
(
const
Move
&
move
)
void
ChangeSet
::
doMove
(
const
Move
&
move
)
{
{
QString
text
;
QString
text
;
if
(
string
)
{
if
(
m_
string
)
{
text
=
string
->
mid
(
move
.
pos
,
move
.
length
);
text
=
m_
string
->
mid
(
move
.
pos
,
move
.
length
);
}
else
if
(
cursor
)
{
}
else
if
(
m_
cursor
)
{
cursor
->
setPosition
(
move
.
pos
);
m_
cursor
->
setPosition
(
move
.
pos
);
cursor
->
setPosition
(
move
.
pos
+
move
.
length
,
QTextCursor
::
KeepAnchor
);
m_
cursor
->
setPosition
(
move
.
pos
+
move
.
length
,
QTextCursor
::
KeepAnchor
);
text
=
cursor
->
selectedText
();
text
=
m_
cursor
->
selectedText
();
}
}
Replace
cut
;
Replace
cut
;
...
@@ -186,22 +202,22 @@ void ChangeSet::doMove(const Move &move)
...
@@ -186,22 +202,22 @@ void ChangeSet::doMove(const Move &move)
void
ChangeSet
::
write
(
QString
*
s
)
void
ChangeSet
::
write
(
QString
*
s
)
{
{
string
=
s
;
m_
string
=
s
;
write_helper
();
write_helper
();
string
=
0
;
m_
string
=
0
;
}
}
void
ChangeSet
::
write
(
QTextCursor
*
textCursor
)
void
ChangeSet
::
write
(
QTextCursor
*
textCursor
)
{
{
cursor
=
textCursor
;
m_
cursor
=
textCursor
;
write_helper
();
write_helper
();
cursor
=
0
;
m_
cursor
=
0
;
}
}
void
ChangeSet
::
write_helper
()
void
ChangeSet
::
write_helper
()
{
{
if
(
cursor
)
if
(
m_
cursor
)
cursor
->
beginEditBlock
();
m_
cursor
->
beginEditBlock
();
{
{
Replace
cmd
;
Replace
cmd
;
while
(
!
m_replaceList
.
isEmpty
())
{
while
(
!
m_replaceList
.
isEmpty
())
{
...
@@ -218,8 +234,8 @@ void ChangeSet::write_helper()
...
@@ -218,8 +234,8 @@ void ChangeSet::write_helper()
doMove
(
cmd
);
doMove
(
cmd
);
}
}
}
}
if
(
cursor
)
if
(
m_
cursor
)
cursor
->
endEditBlock
();
m_
cursor
->
endEditBlock
();
}
}
}
// end namespace Utils
}
// end namespace Utils
This diff is collapsed.
Click to expand it.
src/libs/utils/changeset.h
+
12
−
4
View file @
8a73554d
...
@@ -52,17 +52,18 @@ namespace Utils {
...
@@ -52,17 +52,18 @@ namespace Utils {
class
QTCREATOR_UTILS_EXPORT
ChangeSet
class
QTCREATOR_UTILS_EXPORT
ChangeSet
{
{
QString
*
string
;
QTextCursor
*
cursor
;
public:
public:
struct
Replace
{
struct
Replace
{
Replace
()
:
pos
(
0
),
length
(
0
)
{}
int
pos
;
int
pos
;
int
length
;
int
length
;
QString
replacement
;
QString
replacement
;
};
};
struct
Move
{
struct
Move
{
Move
()
:
pos
(
0
),
length
(
0
),
to
(
0
)
{}
int
pos
;
int
pos
;
int
length
;
int
length
;
int
to
;
int
to
;
...
@@ -71,8 +72,12 @@ public:
...
@@ -71,8 +72,12 @@ public:
public
:
public
:
ChangeSet
();
ChangeSet
();
bool
isEmpty
()
const
;
QList
<
Replace
>
replaceList
()
const
;
QList
<
Replace
>
replaceList
()
const
;
QList
<
Move
>
moveList
()
const
;
QList
<
Move
>
moveList
()
const
;
// ### TODO: merge with replaceList
void
clear
();
void
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
);
void
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
);
void
move
(
int
pos
,
int
length
,
int
to
);
void
move
(
int
pos
,
int
length
,
int
to
);
...
@@ -89,6 +94,9 @@ private:
...
@@ -89,6 +94,9 @@ private:
void
write_helper
();
void
write_helper
();
private
:
QString
*
m_string
;
QTextCursor
*
m_cursor
;
QList
<
Replace
>
m_replaceList
;
QList
<
Replace
>
m_replaceList
;
QList
<
Move
>
m_moveList
;
QList
<
Move
>
m_moveList
;
};
};
...
...
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