diff --git a/src/libs/utils/changeset.cpp b/src/libs/utils/changeset.cpp index 32be3cf15bc7bdbc774b11892d2d2ccd8d923121..06fb65b855ea16a9bf8c10f701caf7a962311a5a 100644 --- a/src/libs/utils/changeset.cpp +++ b/src/libs/utils/changeset.cpp @@ -56,7 +56,7 @@ static bool overlaps(int posA, int lengthA, int posB, int lengthB) { bool ChangeSet::hasOverlap(int pos, int length) { { - QListIterator<Replace> i(replaceList); + QListIterator<Replace> i(m_replaceList); while (i.hasNext()) { const Replace &cmd = i.next(); if (overlaps(pos, length, cmd.pos, cmd.length)) @@ -64,7 +64,7 @@ bool ChangeSet::hasOverlap(int pos, int length) } } { - QListIterator<Move> i(moveList); + QListIterator<Move> i(m_moveList); while (i.hasNext()) { const Move &cmd = i.next(); if (overlaps(pos, length, cmd.pos, cmd.length)) @@ -76,7 +76,7 @@ bool ChangeSet::hasOverlap(int pos, int length) bool ChangeSet::hasMoveInto(int pos, int length) { - QListIterator<Move> i(moveList); + QListIterator<Move> i(m_moveList); while (i.hasNext()) { const Move &cmd = i.next(); if (cmd.to >= pos && cmd.to < pos + length) @@ -85,6 +85,16 @@ bool ChangeSet::hasMoveInto(int pos, int length) 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) { Q_ASSERT(!hasOverlap(pos, length)); @@ -94,7 +104,7 @@ void ChangeSet::replace(int pos, int length, const QString &replacement) cmd.pos = pos; cmd.length = length; cmd.replacement = replacement; - replaceList += cmd; + m_replaceList += cmd; } 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.length = length; cmd.to = to; - moveList += cmd; + m_moveList += cmd; } void ChangeSet::doReplace(const Replace &replace) { int diff = replace.replacement.size() - replace.length; { - QMutableListIterator<Replace> i(replaceList); + QMutableListIterator<Replace> i(m_replaceList); while (i.hasNext()) { Replace &c = i.next(); if (replace.pos < c.pos) @@ -122,7 +132,7 @@ void ChangeSet::doReplace(const Replace &replace) } } { - QMutableListIterator<Move> i(moveList); + QMutableListIterator<Move> i(m_moveList); while (i.hasNext()) { Move &c = i.next(); if (replace.pos < c.pos) @@ -163,13 +173,13 @@ void ChangeSet::doMove(const Move &move) paste.length = 0; paste.replacement = text; - replaceList.append(cut); - replaceList.append(paste); + m_replaceList.append(cut); + m_replaceList.append(paste); Replace cmd; - while (!replaceList.isEmpty()) { - cmd = replaceList.first(); - replaceList.removeFirst(); + while (!m_replaceList.isEmpty()) { + cmd = m_replaceList.first(); + m_replaceList.removeFirst(); doReplace(cmd); } } @@ -194,17 +204,17 @@ void ChangeSet::write_helper() cursor->beginEditBlock(); { Replace cmd; - while (!replaceList.isEmpty()) { - cmd = replaceList.first(); - replaceList.removeFirst(); + while (!m_replaceList.isEmpty()) { + cmd = m_replaceList.first(); + m_replaceList.removeFirst(); doReplace(cmd); } } { Move cmd; - while (!moveList.isEmpty()) { - cmd = moveList.first(); - moveList.removeFirst(); + while (!m_moveList.isEmpty()) { + cmd = m_moveList.first(); + m_moveList.removeFirst(); doMove(cmd); } } diff --git a/src/libs/utils/changeset.h b/src/libs/utils/changeset.h index ba86cf2253c60ddde91b1c343209e5ed569f7285..ff89bbdc0e6a7985db1e311b84eb905db2e48404 100644 --- a/src/libs/utils/changeset.h +++ b/src/libs/utils/changeset.h @@ -55,22 +55,32 @@ class QTCREATOR_UTILS_EXPORT ChangeSet QString *string; QTextCursor *cursor; +public: struct Replace { int pos; int length; QString replacement; }; - QList<Replace> replaceList; - struct Move { int pos; int length; 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 hasMoveInto(int pos, int length); @@ -79,14 +89,8 @@ class QTCREATOR_UTILS_EXPORT ChangeSet void write_helper(); -public: - ChangeSet(); - - 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); + QList<Replace> m_replaceList; + QList<Move> m_moveList; }; } // namespace Utils