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
7586847b
Commit
7586847b
authored
15 years ago
by
Roberto Raggi
Browse files
Options
Downloads
Patches
Plain Diff
Added getters
parent
e43bd82a
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
+28
-18
28 additions, 18 deletions
src/libs/utils/changeset.cpp
src/libs/utils/changeset.h
+15
-11
15 additions, 11 deletions
src/libs/utils/changeset.h
with
43 additions
and
29 deletions
src/libs/utils/changeset.cpp
+
28
−
18
View file @
7586847b
...
@@ -56,7 +56,7 @@ static bool overlaps(int posA, int lengthA, int posB, int lengthB) {
...
@@ -56,7 +56,7 @@ static bool overlaps(int posA, int lengthA, int posB, int lengthB) {
bool
ChangeSet
::
hasOverlap
(
int
pos
,
int
length
)
bool
ChangeSet
::
hasOverlap
(
int
pos
,
int
length
)
{
{
{
{
QListIterator
<
Replace
>
i
(
replaceList
);
QListIterator
<
Replace
>
i
(
m_
replaceList
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
const
Replace
&
cmd
=
i
.
next
();
const
Replace
&
cmd
=
i
.
next
();
if
(
overlaps
(
pos
,
length
,
cmd
.
pos
,
cmd
.
length
))
if
(
overlaps
(
pos
,
length
,
cmd
.
pos
,
cmd
.
length
))
...
@@ -64,7 +64,7 @@ bool ChangeSet::hasOverlap(int pos, int length)
...
@@ -64,7 +64,7 @@ bool ChangeSet::hasOverlap(int pos, int length)
}
}
}
}
{
{
QListIterator
<
Move
>
i
(
moveList
);
QListIterator
<
Move
>
i
(
m_
moveList
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
const
Move
&
cmd
=
i
.
next
();
const
Move
&
cmd
=
i
.
next
();
if
(
overlaps
(
pos
,
length
,
cmd
.
pos
,
cmd
.
length
))
if
(
overlaps
(
pos
,
length
,
cmd
.
pos
,
cmd
.
length
))
...
@@ -76,7 +76,7 @@ bool ChangeSet::hasOverlap(int pos, int length)
...
@@ -76,7 +76,7 @@ bool ChangeSet::hasOverlap(int pos, int length)
bool
ChangeSet
::
hasMoveInto
(
int
pos
,
int
length
)
bool
ChangeSet
::
hasMoveInto
(
int
pos
,
int
length
)
{
{
QListIterator
<
Move
>
i
(
moveList
);
QListIterator
<
Move
>
i
(
m_
moveList
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
const
Move
&
cmd
=
i
.
next
();
const
Move
&
cmd
=
i
.
next
();
if
(
cmd
.
to
>=
pos
&&
cmd
.
to
<
pos
+
length
)
if
(
cmd
.
to
>=
pos
&&
cmd
.
to
<
pos
+
length
)
...
@@ -85,6 +85,16 @@ bool ChangeSet::hasMoveInto(int pos, int length)
...
@@ -85,6 +85,16 @@ bool ChangeSet::hasMoveInto(int pos, int length)
return
false
;
return
false
;
}
}
QList
<
ChangeSet
::
Replace
>
ChangeSet
::
replaceList
()
const
{
return
m_replaceList
;
}
QList
<
ChangeSet
::
Move
>
ChangeSet
::
moveList
()
const
{
return
m_moveList
;
}
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
));
...
@@ -94,7 +104,7 @@ void ChangeSet::replace(int pos, int length, const QString &replacement)
...
@@ -94,7 +104,7 @@ void ChangeSet::replace(int pos, int length, const QString &replacement)
cmd
.
pos
=
pos
;
cmd
.
pos
=
pos
;
cmd
.
length
=
length
;
cmd
.
length
=
length
;
cmd
.
replacement
=
replacement
;
cmd
.
replacement
=
replacement
;
replaceList
+=
cmd
;
m_
replaceList
+=
cmd
;
}
}
void
ChangeSet
::
move
(
int
pos
,
int
length
,
int
to
)
void
ChangeSet
::
move
(
int
pos
,
int
length
,
int
to
)
...
@@ -105,14 +115,14 @@ void ChangeSet::move(int pos, int length, int to)
...
@@ -105,14 +115,14 @@ void ChangeSet::move(int pos, int length, int to)
cmd
.
pos
=
pos
;
cmd
.
pos
=
pos
;
cmd
.
length
=
length
;
cmd
.
length
=
length
;
cmd
.
to
=
to
;
cmd
.
to
=
to
;
moveList
+=
cmd
;
m_
moveList
+=
cmd
;
}
}
void
ChangeSet
::
doReplace
(
const
Replace
&
replace
)
void
ChangeSet
::
doReplace
(
const
Replace
&
replace
)
{
{
int
diff
=
replace
.
replacement
.
size
()
-
replace
.
length
;
int
diff
=
replace
.
replacement
.
size
()
-
replace
.
length
;
{
{
QMutableListIterator
<
Replace
>
i
(
replaceList
);
QMutableListIterator
<
Replace
>
i
(
m_
replaceList
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
Replace
&
c
=
i
.
next
();
Replace
&
c
=
i
.
next
();
if
(
replace
.
pos
<
c
.
pos
)
if
(
replace
.
pos
<
c
.
pos
)
...
@@ -122,7 +132,7 @@ void ChangeSet::doReplace(const Replace &replace)
...
@@ -122,7 +132,7 @@ void ChangeSet::doReplace(const Replace &replace)
}
}
}
}
{
{
QMutableListIterator
<
Move
>
i
(
moveList
);
QMutableListIterator
<
Move
>
i
(
m_
moveList
);
while
(
i
.
hasNext
())
{
while
(
i
.
hasNext
())
{
Move
&
c
=
i
.
next
();
Move
&
c
=
i
.
next
();
if
(
replace
.
pos
<
c
.
pos
)
if
(
replace
.
pos
<
c
.
pos
)
...
@@ -163,13 +173,13 @@ void ChangeSet::doMove(const Move &move)
...
@@ -163,13 +173,13 @@ void ChangeSet::doMove(const Move &move)
paste
.
length
=
0
;
paste
.
length
=
0
;
paste
.
replacement
=
text
;
paste
.
replacement
=
text
;
replaceList
.
append
(
cut
);
m_
replaceList
.
append
(
cut
);
replaceList
.
append
(
paste
);
m_
replaceList
.
append
(
paste
);
Replace
cmd
;
Replace
cmd
;
while
(
!
replaceList
.
isEmpty
())
{
while
(
!
m_
replaceList
.
isEmpty
())
{
cmd
=
replaceList
.
first
();
cmd
=
m_
replaceList
.
first
();
replaceList
.
removeFirst
();
m_
replaceList
.
removeFirst
();
doReplace
(
cmd
);
doReplace
(
cmd
);
}
}
}
}
...
@@ -194,17 +204,17 @@ void ChangeSet::write_helper()
...
@@ -194,17 +204,17 @@ void ChangeSet::write_helper()
cursor
->
beginEditBlock
();
cursor
->
beginEditBlock
();
{
{
Replace
cmd
;
Replace
cmd
;
while
(
!
replaceList
.
isEmpty
())
{
while
(
!
m_
replaceList
.
isEmpty
())
{
cmd
=
replaceList
.
first
();
cmd
=
m_
replaceList
.
first
();
replaceList
.
removeFirst
();
m_
replaceList
.
removeFirst
();
doReplace
(
cmd
);
doReplace
(
cmd
);
}
}
}
}
{
{
Move
cmd
;
Move
cmd
;
while
(
!
moveList
.
isEmpty
())
{
while
(
!
m_
moveList
.
isEmpty
())
{
cmd
=
moveList
.
first
();
cmd
=
m_
moveList
.
first
();
moveList
.
removeFirst
();
m_
moveList
.
removeFirst
();
doMove
(
cmd
);
doMove
(
cmd
);
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
src/libs/utils/changeset.h
+
15
−
11
View file @
7586847b
...
@@ -55,22 +55,32 @@ class QTCREATOR_UTILS_EXPORT ChangeSet
...
@@ -55,22 +55,32 @@ class QTCREATOR_UTILS_EXPORT ChangeSet
QString
*
string
;
QString
*
string
;
QTextCursor
*
cursor
;
QTextCursor
*
cursor
;
public:
struct
Replace
{
struct
Replace
{
int
pos
;
int
pos
;
int
length
;
int
length
;
QString
replacement
;
QString
replacement
;
};
};
QList
<
Replace
>
replaceList
;
struct
Move
{
struct
Move
{
int
pos
;
int
pos
;
int
length
;
int
length
;
int
to
;
int
to
;
};
};
QList
<
Move
>
moveList
;
public
:
ChangeSet
();
QList
<
Replace
>
replaceList
()
const
;
QList
<
Move
>
moveList
()
const
;
void
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
);
void
move
(
int
pos
,
int
length
,
int
to
);
void
write
(
QString
*
s
);
void
write
(
QTextCursor
*
textCursor
);
private
:
bool
hasOverlap
(
int
pos
,
int
length
);
bool
hasOverlap
(
int
pos
,
int
length
);
bool
hasMoveInto
(
int
pos
,
int
length
);
bool
hasMoveInto
(
int
pos
,
int
length
);
...
@@ -79,14 +89,8 @@ class QTCREATOR_UTILS_EXPORT ChangeSet
...
@@ -79,14 +89,8 @@ class QTCREATOR_UTILS_EXPORT ChangeSet
void
write_helper
();
void
write_helper
();
public
:
QList
<
Replace
>
m_replaceList
;
ChangeSet
();
QList
<
Move
>
m_moveList
;
void
replace
(
int
pos
,
int
length
,
const
QString
&
replacement
);
void
move
(
int
pos
,
int
length
,
int
to
);
void
write
(
QString
*
s
);
void
write
(
QTextCursor
*
textCursor
);
};
};
}
// namespace Utils
}
// namespace Utils
...
...
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