diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-10-20 03:16:50 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-10-20 03:16:50 (GMT) |
commit | 965e47f1758079aaf53bfd7a4e0577a249114cb9 (patch) | |
tree | 106d11d3ac3865c9b42ff47180e43369c7263dd7 | |
parent | e3af86a892cd7ce70297f0b1e76390cfd18536e2 (diff) | |
download | Qt-965e47f1758079aaf53bfd7a4e0577a249114cb9.zip Qt-965e47f1758079aaf53bfd7a4e0577a249114cb9.tar.gz Qt-965e47f1758079aaf53bfd7a4e0577a249114cb9.tar.bz2 |
ListView item insertion didn't handle delayed item removal correctly.
The delayed removal items weren't handled correctly by
mapRangeFromModel() function. Use mapFromModel() instead which gives us
what we actually want and remove unused mapRangeFromModel().
Task-number: QTBUG-14471
Reviewed-by: Michael Brasser
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 34 | ||||
-rw-r--r-- | tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp | 9 |
2 files changed, 13 insertions, 30 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 7dd5c75..83965f5 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -394,44 +394,19 @@ public: } // map a model index to visibleItems index. - // These may differ if removed items are still present in the visible list, - // e.g. doing a removal animation int mapFromModel(int modelIndex) const { if (modelIndex < visibleIndex || modelIndex >= visibleIndex + visibleItems.count()) return -1; for (int i = 0; i < visibleItems.count(); ++i) { FxListItem *listItem = visibleItems.at(i); if (listItem->index == modelIndex) - return i + visibleIndex; + return i; if (listItem->index > modelIndex) return -1; } return -1; // Not in visibleList } - bool mapRangeFromModel(int &index, int &count) const { - if (index + count < visibleIndex) - return false; - - int lastIndex = -1; - for (int i = visibleItems.count()-1; i >= 0; --i) { - FxListItem *listItem = visibleItems.at(i); - if (listItem->index != -1) { - lastIndex = listItem->index; - break; - } - } - - if (index > lastIndex) - return false; - - int last = qMin(index + count - 1, lastIndex); - index = qMax(index, visibleIndex); - count = last - index + 1; - - return true; - } - void updateViewport() { Q_Q(QDeclarativeListView); if (orient == QDeclarativeListView::Vertical) { @@ -2811,15 +2786,15 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) return; } - int overlapCount = count; - if (!d->mapRangeFromModel(modelIndex, overlapCount)) { + int index = d->mapFromModel(modelIndex); + if (index < 0) { int i = d->visibleItems.count() - 1; while (i > 0 && d->visibleItems.at(i)->index == -1) --i; 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. - modelIndex = d->visibleIndex + d->visibleItems.count(); + index = d->visibleItems.count(); } else { if (modelIndex < d->visibleIndex) { // Insert before visible items @@ -2846,7 +2821,6 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) // At least some of the added items will be visible - int index = modelIndex - d->visibleIndex; // 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; diff --git a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp index 080631c..79fef7a 100644 --- a/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp +++ b/tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp @@ -673,6 +673,15 @@ void tst_QDeclarativeListView::removed(bool animated) QTRY_COMPARE(item->y(),80+i*20.0); } + model.removeItems(1, 17); +// QTest::qWait(300); + + model.removeItems(2, 1); + model.addItem("New", "1"); + + QTRY_VERIFY(name = findItem<QDeclarativeText>(contentItem, "textName", model.count()-1)); + QCOMPARE(name->text(), QString("New")); + delete canvas; } |