From 01a60f8771ba273d164042710364b7fd88168dcc Mon Sep 17 00:00:00 2001 From: Andrew den Exter Date: Fri, 30 Sep 2011 17:52:27 +1000 Subject: [PATCH] Fix incorrect index when accumulating multiple removes. 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 Reviewed-by: Andrew den Exter --- src/declarative/util/qdeclarativechangeset.cpp | 8 +++----- tests/auto/declarative/declarative.pro | 1 + .../tst_qdeclarativechangeset.cpp | 22 ++++++++++++++++++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/declarative/util/qdeclarativechangeset.cpp b/src/declarative/util/qdeclarativechangeset.cpp index c264ca0..3375706 100644 --- a/src/declarative/util/qdeclarativechangeset.cpp +++ b/src/declarative/util/qdeclarativechangeset.cpp @@ -276,7 +276,7 @@ void QDeclarativeChangeSet::applyRemovals(QVector &removals, QVectormoveId == -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 &removals, QVectorcount -= difference; removeCount += difference; - remove->index = rit->index; remove->count = count; remove = m_removes.erase(++remove, rend); @@ -302,10 +301,10 @@ void QDeclarativeChangeSet::applyRemovals(QVector &removals, QVectorindex, 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 &removals, QVectorindex, 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) { diff --git a/tests/auto/declarative/declarative.pro b/tests/auto/declarative/declarative.pro index d8567db..60eb2a9 100644 --- a/tests/auto/declarative/declarative.pro +++ b/tests/auto/declarative/declarative.pro @@ -31,6 +31,7 @@ PRIVATETESTS += \ qdeclarativeapplication \ qdeclarativebehaviors \ qdeclarativebinding \ + qdeclarativechangeset \ qdeclarativeconnection \ qdeclarativeenginedebug \ qdeclarativedebugclient \ diff --git a/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp index 6b3fcf9..8da3d9b 100644 --- a/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp +++ b/tests/auto/declarative/qdeclarativechangeset/tst_qdeclarativechangeset.cpp @@ -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() -- 2.7.4