summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/declarative/graphicsitems/qdeclarativelistview.cpp34
-rw-r--r--tests/auto/declarative/qdeclarativelistview/tst_qdeclarativelistview.cpp9
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;
}