Remove unused QTextCursor code from rewriter.
authorMatthew Vogt <matthew.vogt@nokia.com>
Thu, 8 Mar 2012 04:11:46 +0000 (14:11 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 9 Mar 2012 06:30:00 +0000 (07:30 +0100)
The rewriter previously supported rewriting operations on either
a QString or a QTextCursor.  In order to remove the dependency on
QtGui, remove the unused QTextCursor support.

Task-number: QTBUG-24559
Change-Id: I7a4acceff8097a8bd8c022db23b6b89d356e305a
Reviewed-by: Roberto Raggi <roberto.raggi@nokia.com>

src/qml/qml/qqmlscript.cpp
src/qml/qml/rewriter/textwriter.cpp
src/qml/qml/rewriter/textwriter_p.h

index db59a72..8e22e48 100644 (file)
@@ -50,6 +50,7 @@
 #include <private/qqmlrewrite_p.h>
 
 #include <QStack>
+#include <QStringList>
 #include <QCoreApplication>
 #include <QtDebug>
 
index f14c4af..458fee6 100644 (file)
@@ -46,7 +46,7 @@ QT_QML_BEGIN_NAMESPACE
 using namespace QQmlJS;
 
 TextWriter::TextWriter()
-        :string(0), cursor(0)
+        :string(0)
 {
 }
 
@@ -72,8 +72,8 @@ bool TextWriter::hasOverlap(int pos, int length)
             if (overlaps(pos, length, cmd.pos, cmd.length))
                 return true;
         }
-        return false;
     }
+    return false;
 }
 
 bool TextWriter::hasMoveInto(int pos, int length)
@@ -137,25 +137,12 @@ void TextWriter::doReplace(const Replace &replace)
         }
     }
 
-    if (string) {
-        string->replace(replace.pos, replace.length, replace.replacement);
-    } else if (cursor) {
-        cursor->setPosition(replace.pos);
-        cursor->setPosition(replace.pos + replace.length, QTextCursor::KeepAnchor);
-        cursor->insertText(replace.replacement);
-    }
+    string->replace(replace.pos, replace.length, replace.replacement);
 }
 
 void TextWriter::doMove(const Move &move)
 {
-    QString text;
-    if (string) {
-        text = string->mid(move.pos, move.length);
-    } else if (cursor) {
-        cursor->setPosition(move.pos);
-        cursor->setPosition(move.pos + move.length, QTextCursor::KeepAnchor);
-        text = cursor->selectedText();
-    }
+    QString text(string->mid(move.pos, move.length));
 
     Replace cut;
     cut.pos = move.pos;
@@ -183,17 +170,10 @@ void TextWriter::write(QString *s)
     string = 0;
 }
 
-void TextWriter::write(QTextCursor *textCursor)
-{
-    cursor = textCursor;
-    write_helper();
-    cursor = 0;
-}
-
 void TextWriter::write_helper()
 {
-    if (cursor)
-        cursor->beginEditBlock();
+    Q_ASSERT(string);
+
     {
         Replace cmd;
         while (!replaceList.isEmpty()) {
@@ -210,8 +190,6 @@ void TextWriter::write_helper()
             doMove(cmd);
         }
     }
-    if (cursor)
-        cursor->endEditBlock();
 }
 
 QT_QML_END_NAMESPACE
index 94e2d08..6c36a2f 100644 (file)
@@ -46,7 +46,6 @@
 
 #include <QtCore/QString>
 #include <QtCore/QList>
-#include <QtGui/QTextCursor>
 
 QT_BEGIN_HEADER
 QT_QML_BEGIN_NAMESPACE
@@ -56,7 +55,6 @@ namespace QQmlJS {
 class TextWriter
 {
        QString *string;
-       QTextCursor *cursor;
 
        struct Replace {
                int pos;
@@ -89,8 +87,6 @@ public:
        void move(int pos, int length, int to);
 
        void write(QString *s);
-       void write(QTextCursor *textCursor);
-
 };
 
 } // end of namespace QQmlJS