Skip to content
Snippets Groups Projects
Commit 8a73554d authored by Roberto Raggi's avatar Roberto Raggi
Browse files

Initialize the members.

parent 4abd0aef
No related branches found
No related tags found
No related merge requests found
...@@ -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
...@@ -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;
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment