diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-12-22 06:15:28 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-12-22 06:36:41 (GMT) |
commit | cb31612bf6a48f995fbc05b5e8aa924e13034ae4 (patch) | |
tree | 78da6041402b81e955d1db8b983e098aea4470ba | |
parent | e50a0ad18c40322ca0c06a11e7dc7b9a82951f16 (diff) | |
download | Qt-cb31612bf6a48f995fbc05b5e8aa924e13034ae4.zip Qt-cb31612bf6a48f995fbc05b5e8aa924e13034ae4.tar.gz Qt-cb31612bf6a48f995fbc05b5e8aa924e13034ae4.tar.bz2 |
Removing all visible items in ListView resulted in blank view.
When delayRemove is true and all visible items are tagged to be
removed the visibleIndex became invalid and refill() began filling
from 0.
Task-number: QTBUG-16183
Reviewed-by: Michael Brasser
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 14 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp | 3 |
2 files changed, 12 insertions, 5 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 2a7f508..86c8756 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -643,7 +643,8 @@ void QDeclarativeListViewPrivate::refill(qreal from, qreal to, bool doBuffer) int i = visibleItems.count() - 1; while (i > 0 && visibleItems.at(i)->index == -1) --i; - modelIndex = visibleItems.at(i)->index + 1; + if (visibleItems.at(i)->index != -1) + modelIndex = visibleItems.at(i)->index + 1; } bool changed = false; @@ -2804,7 +2805,10 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) int i = d->visibleItems.count() - 1; while (i > 0 && d->visibleItems.at(i)->index == -1) --i; - if (d->visibleItems.at(i)->index + 1 == modelIndex + if (i == 0 && d->visibleItems.first()->index == -1) { + // there are no visible items except items marked for removal + index = d->visibleItems.count(); + } else if (d->visibleItems.at(i)->index + 1 == modelIndex && d->visibleItems.at(i)->endPosition() < d->buffer+d->position()+d->size()-1) { // Special case of appending an item to the model. index = d->visibleItems.count(); @@ -2836,7 +2840,7 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) // index can be the next item past the end of the visible items list (i.e. appended) int pos = index < d->visibleItems.count() ? d->visibleItems.at(index)->position() - : d->visibleItems.at(index-1)->endPosition()+d->spacing+1; + : d->visibleItems.last()->endPosition()+d->spacing+1; int initialPos = pos; int diff = 0; QList<FxListItem*> added; @@ -2988,14 +2992,16 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) } // update visibleIndex + bool haveVisibleIndex = false; for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) { if ((*it)->index != -1) { d->visibleIndex = (*it)->index; + haveVisibleIndex = true; break; } } - if (removedVisible && d->visibleItems.isEmpty()) { + if (removedVisible && !haveVisibleIndex) { d->timeline.clear(); if (d->itemCount == 0) { d->visibleIndex = 0; diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 3df10a9..dba0cc4 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -667,7 +667,8 @@ void tst_QDeclarativeListView::removed(bool animated) listview->setContentY(80); QTest::qWait(300); - model.removeItems(1, 17); + // remove all visible items + model.removeItems(1, 18); QTest::qWait(300); // Confirm items positioned correctly |