From 982d7f659750f0864e2d874ce41289125f40a36b Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Fri, 3 Sep 2010 17:10:45 +1000 Subject: Keep ListView position sensible when all visible items are removed. Previously it would always jump back to 0. Now it stays at the nearest remaining index. Task-number: QTBUG-12664 --- src/declarative/graphicsitems/qdeclarativelistview.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index ef28ab2..1c634d2 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -2916,14 +2916,18 @@ void QDeclarativeListView::itemsRemoved(int modelIndex, int count) } if (removedVisible && d->visibleItems.isEmpty()) { - d->visibleIndex = 0; - d->visiblePos = d->header ? d->header->size() : 0; d->timeline.clear(); - d->setPosition(0); if (d->itemCount == 0) { + d->visibleIndex = 0; + d->visiblePos = d->header ? d->header->size() : 0; + d->setPosition(0); d->updateHeader(); d->updateFooter(); update(); + } else { + if (modelIndex < d->visibleIndex) + d->visibleIndex = modelIndex+1; + d->visibleIndex = qMax(qMin(d->visibleIndex, d->itemCount-1), 0); } } -- cgit v0.12