diff options
author | Bea Lam <bea.lam@nokia.com> | 2011-11-08 16:11:26 +1000 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-11 06:42:58 +0100 |
commit | 1686a82f3859ce2a0f48774ded21bf9817f5abc9 (patch) | |
tree | 0593597514eab884a5304088b6759b0ba65e0526 /src | |
parent | e9b68b62e2a3b28c303210d22a6ffed1ec805771 (diff) |
GridView should re-layout if add/remove before visible index
Unlike ListView, GridView must redo its layout if an item is added or
removed from before the visible items, since it affects the column/row
layout.
Task-number: QTBUG-21588
Change-Id: Id333bc653033751c45d127973e94fae4580c55b0
Reviewed-by: Bea Lam <bea.lam@nokia.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/items/qquickgridview.cpp | 8 | ||||
-rw-r--r-- | src/declarative/items/qquickitemview.cpp | 19 | ||||
-rw-r--r-- | src/declarative/items/qquickitemview_p_p.h | 1 |
3 files changed, 20 insertions, 8 deletions
diff --git a/src/declarative/items/qquickgridview.cpp b/src/declarative/items/qquickgridview.cpp index 2793032a48..a4133143ea 100644 --- a/src/declarative/items/qquickgridview.cpp +++ b/src/declarative/items/qquickgridview.cpp @@ -182,6 +182,7 @@ public: virtual void setPosition(qreal pos); virtual void layoutVisibleItems(); bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *); + virtual bool needsRefillForAddedOrRemovedIndex(int index) const; virtual qreal headerSize() const; virtual qreal footerSize() const; @@ -1853,6 +1854,13 @@ bool QQuickGridViewPrivate::applyInsertionChange(const QDeclarativeChangeSet::In return insertResult->addedItems.count() > prevAddedCount; } +bool QQuickGridViewPrivate::needsRefillForAddedOrRemovedIndex(int modelIndex) const +{ + // If we add or remove items before visible items, a layout may be + // required to ensure item 0 is in the first column. + return modelIndex < visibleIndex; +} + /*! \qmlmethod QtQuick2::GridView::positionViewAtIndex(int index, PositionMode mode) diff --git a/src/declarative/items/qquickitemview.cpp b/src/declarative/items/qquickitemview.cpp index 923db4747a..79787d777c 100644 --- a/src/declarative/items/qquickitemview.cpp +++ b/src/declarative/items/qquickitemview.cpp @@ -1413,7 +1413,7 @@ bool QQuickItemViewPrivate::applyModelChanges() moveReason = QQuickItemViewPrivate::Other; int prevCount = itemCount; - bool removedVisible = false; + bool visibleAffected = false; bool viewportChanged = !currentChanges.pendingChanges.removes().isEmpty() || !currentChanges.pendingChanges.inserts().isEmpty(); @@ -1432,8 +1432,8 @@ bool QQuickItemViewPrivate::applyModelChanges() FxViewItem *item = *it; if (item->index == -1 || item->index < removals[i].index) { // already removed, or before removed items - if (item->index < removals[i].index && !removedVisible) - removedVisible = true; + if (!visibleAffected && item->index < removals[i].index) + visibleAffected = true; ++it; } else if (item->index >= removals[i].index + removals[i].count) { // after removed items @@ -1441,7 +1441,7 @@ bool QQuickItemViewPrivate::applyModelChanges() ++it; } else { // removed item - removedVisible = true; + visibleAffected = true; if (!removals[i].isMove()) item->attached->emitRemove(); @@ -1463,20 +1463,22 @@ bool QQuickItemViewPrivate::applyModelChanges() } } } - + if (!visibleAffected && needsRefillForAddedOrRemovedIndex(removals[i].index)) + visibleAffected = true; } if (!removals.isEmpty()) updateVisibleIndex(); const QVector<QDeclarativeChangeSet::Insert> &insertions = currentChanges.pendingChanges.inserts(); - bool addedVisible = false; InsertionsResult insertResult; bool allInsertionsBeforeVisible = true; for (int i=0; i<insertions.count(); i++) { bool wasEmpty = visibleItems.isEmpty(); if (applyInsertionChange(insertions[i], firstVisible, &insertResult)) - addedVisible = true; + visibleAffected = true; + if (!visibleAffected && needsRefillForAddedOrRemovedIndex(insertions[i].index)) + visibleAffected = true; if (insertions[i].index >= visibleIndex) allInsertionsBeforeVisible = false; if (wasEmpty && !visibleItems.isEmpty()) @@ -1542,7 +1544,8 @@ bool QQuickItemViewPrivate::applyModelChanges() if (prevCount != itemCount) emit q->countChanged(); - bool visibleAffected = removedVisible || addedVisible || !currentChanges.pendingChanges.changes().isEmpty(); + if (!visibleAffected) + visibleAffected = !currentChanges.pendingChanges.changes().isEmpty(); if (!visibleAffected && viewportChanged) updateViewport(); diff --git a/src/declarative/items/qquickitemview_p_p.h b/src/declarative/items/qquickitemview_p_p.h index 398de84c25..ca4c0ceba9 100644 --- a/src/declarative/items/qquickitemview_p_p.h +++ b/src/declarative/items/qquickitemview_p_p.h @@ -240,6 +240,7 @@ protected: virtual void layoutVisibleItems() = 0; virtual void changedVisibleIndex(int newIndex) = 0; virtual bool applyInsertionChange(const QDeclarativeChangeSet::Insert &, FxViewItem *, InsertionsResult *) = 0; + virtual bool needsRefillForAddedOrRemovedIndex(int) const { return false; } virtual void initializeViewItem(FxViewItem *) {} virtual void initializeCurrentItem() {} |