aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2011-07-27 17:57:48 +1000
committerQt by Nokia <qt-info@nokia.com>2011-07-28 02:21:28 +0200
commit70cb4d6d9a2193444d785519a9811dc6693a6ab6 (patch)
treefccb6286bfe7a138a790d4590679d961d25fc2e0 /src
parent5266db7357f8a0ce4ce175b5becdbdd2c094a808 (diff)
Don't move view content position item 0 is being replaced
Usually if item 0 moves down, the next item becomes the first visible item and all content moves down. Don't do this if another item is moving up to take its place. Change-Id: If625cfc0eaa70fd1094c7bc0fdd29f5f56766a42 Reviewed-on: http://codereview.qt.nokia.com/2260 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Martin Jones <martin.jones@nokia.com>
Diffstat (limited to 'src')
-rw-r--r--src/declarative/items/qsggridview.cpp26
-rw-r--r--src/declarative/items/qsglistview.cpp14
2 files changed, 37 insertions, 3 deletions
diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp
index 307aeae32f..1aa7292060 100644
--- a/src/declarative/items/qsggridview.cpp
+++ b/src/declarative/items/qsggridview.cpp
@@ -1490,9 +1490,19 @@ void QSGGridView::itemsMoved(int from, int to, int count)
Q_D(QSGGridView);
if (!isComponentComplete())
return;
+ d->updateUnrequestedIndexes();
+
+ if (d->visibleItems.isEmpty()) {
+ d->refill();
+ return;
+ }
+
+ d->moveReason = QSGGridViewPrivate::Other;
+ FxGridItemSG *firstVisible = static_cast<FxGridItemSG*>(d->firstVisibleItem());
QHash<int,FxGridItemSG*> moved;
- FxGridItemSG *firstItem = static_cast<FxGridItemSG*>(d->firstVisibleItem());
+ bool movingBackwards = from > to;
+ int firstItemIndex = firstVisible ? firstVisible->index : -1;
QList<FxViewItem*>::Iterator it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
@@ -1524,8 +1534,6 @@ void QSGGridView::itemsMoved(int from, int to, int count)
if (!movedItem)
movedItem = static_cast<FxGridItemSG*>(d->createItem(item->index));
it = d->visibleItems.insert(it, movedItem);
- if (it == d->visibleItems.begin() && firstItem)
- movedItem->setPosition(firstItem->colPos(), firstItem->rowPos());
++it;
--remaining;
} else {
@@ -1555,6 +1563,18 @@ void QSGGridView::itemsMoved(int from, int to, int count)
}
}
+ // if first visible item is moving but another item is moving up to replace it,
+ // do this positioning now to avoid shifting all content forwards
+ if (movingBackwards && firstItemIndex >= 0) {
+ for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) {
+ if ((*it)->index == firstItemIndex) {
+ static_cast<FxGridItemSG*>(*it)->setPosition(firstVisible->colPos(),
+ firstVisible->rowPos());
+ break;
+ }
+ }
+ }
+
// Fix current index
if (d->currentIndex >= 0 && d->currentItem) {
int oldCurrent = d->currentIndex;
diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp
index fa4260214b..0d6a4947f4 100644
--- a/src/declarative/items/qsglistview.cpp
+++ b/src/declarative/items/qsglistview.cpp
@@ -1819,6 +1819,9 @@ void QSGListView::itemsMoved(int from, int to, int count)
QHash<int,FxViewItem*> moved;
int moveBy = 0;
+ bool movingBackwards = from > to;
+ int firstItemIndex = firstVisible ? firstVisible->index : -1;
+
QList<FxViewItem*>::Iterator it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
FxViewItem *item = *it;
@@ -1879,6 +1882,17 @@ void QSGListView::itemsMoved(int from, int to, int count)
}
}
+ // if first visible item is moving but another item is moving up to replace it,
+ // do this positioning now to avoid shifting all content forwards
+ if (movingBackwards && firstItemIndex >= 0) {
+ for (it = d->visibleItems.begin(); it != d->visibleItems.end(); ++it) {
+ if ((*it)->index == firstItemIndex) {
+ static_cast<FxListItemSG*>(*it)->setPosition(firstVisible->position());
+ break;
+ }
+ }
+ }
+
// Fix current index
if (d->currentIndex >= 0 && d->currentItem) {
int oldCurrent = d->currentIndex;