Fix incorrect index when accumulating multiple removes.
authorAndrew den Exter <andrew.den-exter@nokia.com>
Fri, 30 Sep 2011 07:52:27 +0000 (17:52 +1000)
committerQt by Nokia <qt-info@nokia.com>
Tue, 4 Oct 2011 03:16:43 +0000 (05:16 +0200)
Don't remove the intersecting count from the current remove twice,
and accumulate consecutive not just overlapping removes.

Change-Id: I426d764d980ee17ad114aa03ca4089da89c6aed2
Reviewed-on: http://codereview.qt-project.org/5902
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Andrew den Exter <andrew.den-exter@nokia.com>
src/declarative/util/qdeclarativechangeset.cpp
tests/auto/declarative/declarative.pro
tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp

index c264ca0..3375706 100644 (file)
@@ -276,7 +276,7 @@ void QDeclarativeChangeSet::applyRemovals(QVector<Remove> &removals, QVector<Ins
             for (; rend != m_removes.end()
                     && rit->moveId == -1
                     && rend->moveId == -1
-                    && rit->index + rit->count > rend->index; ++rend) {
+                    && rit->index + rit->count >= rend->index; ++rend) {
                 count += rend->count;
             }
             if (remove != rend) {
@@ -288,7 +288,6 @@ void QDeclarativeChangeSet::applyRemovals(QVector<Remove> &removals, QVector<Ins
                 index += difference;
                 rit->count -= difference;
                 removeCount += difference;
-
                 remove->index = rit->index;
                 remove->count = count;
                 remove = m_removes.erase(++remove, rend);
@@ -302,10 +301,10 @@ void QDeclarativeChangeSet::applyRemovals(QVector<Remove> &removals, QVector<Ins
                     remove = m_removes.insert(remove, Remove(rit->index, offset, moveId));
                     ++remove;
                     rit->count -= offset;
+                    removeCount += offset;
                 }
                 remove->index = rit->index;
                 index += offset;
-                removeCount += offset;
 
                 ++remove;
             } else {
@@ -313,15 +312,14 @@ void QDeclarativeChangeSet::applyRemovals(QVector<Remove> &removals, QVector<Ins
                     remove = m_removes.insert(remove, Remove(rit->index, offset));
                     ++remove;
                     rit->count -= offset;
+                    removeCount += offset;
                 }
                 remove->index = rit->index;
                 index += offset;
-                removeCount += offset;
 
                 ++remove;
             }
             index += count;
-            rit->count -= count;
         }
 
         if (rit->count > 0) {
index d8567db..60eb2a9 100644 (file)
@@ -31,6 +31,7 @@ PRIVATETESTS += \
     qdeclarativeapplication \
     qdeclarativebehaviors \
     qdeclarativebinding \
+    qdeclarativechangeset \
     qdeclarativeconnection \
     qdeclarativeenginedebug \
     qdeclarativedebugclient \
index 6b3fcf9..8da3d9b 100644 (file)
@@ -727,6 +727,28 @@ void tst_qdeclarativemodelchange::sequence_data()
     QTest::newRow("m(12-23,6),r(20,4)")
             << (SignalList() << Move(12,23,6) << Remove(20,4))
             << (SignalList() << Remove(12,1) << Remove(12,5,0) << Remove(20,3) << Insert(20,5,0));
+
+
+    // Complex
+    QTest::newRow("r(15,1),r(22,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1))
+            << (SignalList() << Remove(15,1) << Remove(22,1));
+    QTest::newRow("r(15,1),r(22,1),r(25,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1))
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1));
+    QTest::newRow("r(15,1),r(22,1),r(25,1),r(15,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1) << Remove(15,1))
+            << (SignalList() << Remove(15,2) << Remove(21,1) << Remove(24,1));
+    QTest::newRow("r(15,1),r(22,1),r(25,1),r(15,1),r(13,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1) << Remove(15,1) << Remove(13,1))
+            << (SignalList() << Remove(13,1) << Remove(14,2) << Remove(20,1) << Remove(23,1));
+    QTest::newRow("r(15,1),r(22,1),r(25,1),r(15,1),r(13,1),r(13,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1) << Remove(15,1) << Remove(13,1) << Remove(13,1))
+            << (SignalList() << Remove(13,4) << Remove(19,1) << Remove(22,1));
+    QTest::newRow("r(15,1),r(22,1),r(25,1),r(15,1),r(13,1),r(13,1),m(12,13,1)")
+            << (SignalList() << Remove(15,1) << Remove(22,1) << Remove(25,1) << Remove(15,1) << Remove(13,1) << Remove(13,1) << Move(12,13,1))
+            << (SignalList() << Remove(12,1,0) << Remove(12,4) << Remove(18,1) << Remove(21,1) << Insert(13,1,0));
+
 }
 
 void tst_qdeclarativemodelchange::sequence()