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 | |
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')
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativegridview.cpp | 17 | ||||
-rw-r--r-- | src/declarative/graphicsitems/qdeclarativelistview.cpp | 17 |
2 files changed, 30 insertions, 4 deletions
diff --git a/src/declarative/graphicsitems/qdeclarativegridview.cpp b/src/declarative/graphicsitems/qdeclarativegridview.cpp index afea4ea..2c27b6d 100644 --- a/src/declarative/graphicsitems/qdeclarativegridview.cpp +++ b/src/declarative/graphicsitems/qdeclarativegridview.cpp @@ -1083,8 +1083,9 @@ void QDeclarativeGridView::setCurrentIndex(int index) d->moveReason = QDeclarativeGridViewPrivate::SetIndex; cancelFlick(); d->updateCurrent(index); - } else { + } else if (index != d->currentIndex) { d->currentIndex = index; + emit currentIndexChanged(); } } @@ -1845,9 +1846,17 @@ void QDeclarativeGridView::trackedPositionChanged() void QDeclarativeGridView::itemsInserted(int modelIndex, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; 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; } @@ -1971,6 +1980,8 @@ void QDeclarativeGridView::itemsInserted(int modelIndex, int count) void QDeclarativeGridView::itemsRemoved(int modelIndex, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; bool currentRemoved = d->currentIndex >= modelIndex && d->currentIndex < modelIndex + count; bool removedVisible = false; @@ -2061,6 +2072,8 @@ void QDeclarativeGridView::destroyRemoved() void QDeclarativeGridView::itemsMoved(int from, int to, int count) { Q_D(QDeclarativeGridView); + if (!isComponentComplete()) + return; QHash<int,FxGridItem*> moved; bool removedBeforeVisible = false; 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()) { |