diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-03-25 00:16:50 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-03-25 00:16:50 (GMT) |
commit | 8ea277d3dad350eae9778f1dc1169d9ec3f4c392 (patch) | |
tree | cbe30d8b5edc8d411a0346f005b531b32dea6ce4 /src/declarative/graphicsitems/qdeclarativelistview.cpp | |
parent | 89eb5c7ea21502c23dd509035c0eaf0fdea0d01e (diff) | |
download | Qt-8ea277d3dad350eae9778f1dc1169d9ec3f4c392.zip Qt-8ea277d3dad350eae9778f1dc1169d9ec3f4c392.tar.gz Qt-8ea277d3dad350eae9778f1dc1169d9ec3f4c392.tar.bz2 |
Ensure currentIndex is updated when items inserted before currentIndex
Was occurring when items inserted but no items had been created yet.
Task-number: QTBUG-9313
Diffstat (limited to 'src/declarative/graphicsitems/qdeclarativelistview.cpp')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativelistview.cpp b/src/declarative/graphicsitems/qdeclarativelistview.cpp index 4cf8117..ab82f3a 100644 --- a/src/declarative/graphicsitems/qdeclarativelistview.cpp +++ b/src/declarative/graphicsitems/qdeclarativelistview.cpp @@ -1491,8 +1491,9 @@ void QDeclarativeListView::setCurrentIndex(int index) d->moveReason = QDeclarativeListViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); - } else { + } else if (index != d->currentIndex) { d->currentIndex = index; + emit currentIndexChanged(); } } @@ -2366,11 +2367,19 @@ void QDeclarativeListView::trackedPositionChanged() void QDeclarativeListView::itemsInserted(int modelIndex, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->updateUnrequestedIndexes(); d->moveReason = QDeclarativeListViewPrivate::Other; if (!d->visibleItems.count() || d->model->count() <= 1) { d->scheduleLayout(); - d->updateCurrent(qMax(0, qMin(d->currentIndex, d->model->count()-1))); + if (d->currentIndex >= modelIndex) { + // adjust current item index + d->currentIndex += count; + if (d->currentItem) + d->currentItem->index = d->currentIndex; + emit currentIndexChanged(); + } emit countChanged(); return; } @@ -2500,6 +2509,8 @@ void QDeclarativeListView::itemsInserted(int modelIndex, int count) void QDeclarativeListView::itemsRemoved(int modelIndex, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->moveReason = QDeclarativeListViewPrivate::Other; d->updateUnrequestedIndexes(); @@ -2598,6 +2609,8 @@ void QDeclarativeListView::destroyRemoved() void QDeclarativeListView::itemsMoved(int from, int to, int count) { Q_D(QDeclarativeListView); + if (!isComponentComplete()) + return; d->updateUnrequestedIndexes(); if (d->visibleItems.isEmpty()) { |