diff options
author | Andrew den Exter <andrew.den-exter@nokia.com> | 2012-07-11 13:30:38 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-08-03 07:44:47 +0200 |
commit | 4eb04c4523ed901c173d69f16f199f7ec1b7e795 (patch) | |
tree | 16bcd565a3f14abd38db10f7038bb8bee4ce178a /src/quick/util/qquicklistcompositor.cpp | |
parent | aa25ad8d5f476d6db59012a122833ebe677eaf69 (diff) |
Refactor and document QQuickChangeSet.
Store an offset variable for moves so that an insert can be split
without the need to also split the corresponding remove, simplifying the
logic involved somewhat.
Change-Id: I1df19d431a04361a75e107bc4d149cbb80cd791d
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src/quick/util/qquicklistcompositor.cpp')
-rw-r--r-- | src/quick/util/qquicklistcompositor.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/quick/util/qquicklistcompositor.cpp b/src/quick/util/qquicklistcompositor.cpp index 25dbd98c1e..e820a73ad2 100644 --- a/src/quick/util/qquicklistcompositor.cpp +++ b/src/quick/util/qquicklistcompositor.cpp @@ -210,6 +210,7 @@ QQuickListCompositor::QQuickListCompositor() , m_groupCount(2) , m_defaultFlags(PrependFlag | DefaultFlag) , m_removeFlags(AppendFlag | PrependFlag | GroupMask) + , m_moveId(0) { } @@ -586,7 +587,7 @@ void QQuickListCompositor::move( // Remove count items belonging to the move group from the list. Range movedFlags; - for (int moveId = 0; count > 0;) { + for (int moveId = m_moveId; count > 0;) { if (fromIt != moveGroup) { // Skip ranges not containing items from the move group. fromIt.incrementIndexes(fromIt->count); @@ -604,7 +605,7 @@ void QQuickListCompositor::move( fromIt->flags & ~(PrependFlag | AppendFlag)); // Remove moved items from the count, the existing range, and a remove notification. if (removes) - removes->append(Remove(fromIt, difference, fromIt->flags, moveId++)); + removes->append(Remove(fromIt, difference, fromIt->flags, ++moveId)); count -= difference; fromIt->count -= difference; @@ -702,13 +703,15 @@ void QQuickListCompositor::move( for (Range *next, *range = movedFlags.next; range != &movedFlags; range = next) { insert.count = range->count; insert.flags = range->flags; - if (inserts) + if (inserts) { + insert.moveId = ++m_moveId; inserts->append(insert); + } for (int i = 0; i < m_groupCount; ++i) { if (insert.inGroup(i)) insert.index[i] += range->count; } - ++insert.moveId; + next = range->next; delete range; } @@ -823,7 +826,7 @@ void QQuickListCompositor::listItemsRemoved( void *list, QVector<QQuickChangeSet::Remove> *removals, QVector<QQuickChangeSet::Insert> *insertions, - QVector<MovedFlags> *movedFlags, int moveId) + QVector<MovedFlags> *movedFlags) { QT_QML_TRACE_LISTCOMPOSITOR(<< list << *removals) @@ -856,7 +859,7 @@ void QQuickListCompositor::listItemsRemoved( Q_ASSERT(insertion->count == removal->count); if (relativeIndex < 0) { - int splitMoveId = ++moveId; + int splitMoveId = ++m_moveId; removal = removals->insert(removal, QQuickChangeSet::Remove( removal->index, -relativeIndex, splitMoveId)); ++removal; @@ -870,8 +873,8 @@ void QQuickListCompositor::listItemsRemoved( if (it->prepend()) { removeFlags |= it->flags & CacheFlag; - translatedRemoval.moveId = ++moveId; - movedFlags->append(MovedFlags(moveId, it->flags & ~AppendFlag)); + translatedRemoval.moveId = ++m_moveId; + movedFlags->append(MovedFlags(m_moveId, it->flags & ~AppendFlag)); if (removeCount < removal->count) { removal = removals->insert(removal, QQuickChangeSet::Remove( @@ -965,7 +968,7 @@ void QQuickListCompositor::listItemsRemoved( QVector<QQuickChangeSet::Remove> removals; removals.append(QQuickChangeSet::Remove(index, count)); - listItemsRemoved(translatedRemovals, list, &removals, 0, 0, 0); + listItemsRemoved(translatedRemovals, list, &removals, 0, 0); } void QQuickListCompositor::listItemsMoved( @@ -985,7 +988,7 @@ void QQuickListCompositor::listItemsMoved( removals.append(QQuickChangeSet::Remove(from, count, 0)); insertions.append(QQuickChangeSet::Insert(to, count, 0)); - listItemsRemoved(translatedRemovals, list, &removals, &insertions, &movedFlags, 0); + listItemsRemoved(translatedRemovals, list, &removals, &insertions, &movedFlags); listItemsInserted(translatedInsertions, list, insertions, &movedFlags); } |