aboutsummaryrefslogtreecommitdiffstats
path: root/src/declarative
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative')
-rw-r--r--src/declarative/items/qsggridview.cpp16
-rw-r--r--src/declarative/items/qsglistview.cpp13
2 files changed, 26 insertions, 3 deletions
diff --git a/src/declarative/items/qsggridview.cpp b/src/declarative/items/qsggridview.cpp
index 1aa7292060..8559379d20 100644
--- a/src/declarative/items/qsggridview.cpp
+++ b/src/declarative/items/qsggridview.cpp
@@ -1500,10 +1500,18 @@ void QSGGridView::itemsMoved(int from, int to, int count)
d->moveReason = QSGGridViewPrivate::Other;
FxGridItemSG *firstVisible = static_cast<FxGridItemSG*>(d->firstVisibleItem());
QHash<int,FxGridItemSG*> moved;
+ int moveByCount = 0;
bool movingBackwards = from > to;
int firstItemIndex = firstVisible ? firstVisible->index : -1;
+ // if visibleItems.first() is above the content start pos, and the items
+ // beneath it are moved, ensure this first item is later repositioned correctly
+ // (to above the next visible item) so that subsequent layout() is correct
+ bool repositionFirstItem = firstVisible
+ && d->visibleItems.first()->position() < firstVisible->position()
+ && from > d->visibleItems.first()->index;
+
QList<FxViewItem*>::Iterator it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
FxViewItem *item = *it;
@@ -1511,6 +1519,8 @@ void QSGGridView::itemsMoved(int from, int to, int count)
// take the items that are moving
item->index += (to-from);
moved.insert(item->index, static_cast<FxGridItemSG*>(item));
+ if (repositionFirstItem)
+ moveByCount++;
it = d->visibleItems.erase(it);
} else {
if (item->index > from && item->index != -1) {
@@ -1594,6 +1604,12 @@ void QSGGridView::itemsMoved(int from, int to, int count)
d->releaseItem(item);
}
+ // Ensure we don't cause an ugly list scroll.
+ if (d->visibleItems.count() && moveByCount > 0) {
+ FxGridItemSG *first = static_cast<FxGridItemSG*>(d->visibleItems.first());
+ first->setPosition(first->colPos(), first->rowPos() + ((moveByCount / d->columns) * d->rowSize()));
+ }
+
d->layout();
}
diff --git a/src/declarative/items/qsglistview.cpp b/src/declarative/items/qsglistview.cpp
index 0d6a4947f4..abfb4fe9a0 100644
--- a/src/declarative/items/qsglistview.cpp
+++ b/src/declarative/items/qsglistview.cpp
@@ -1815,13 +1815,19 @@ void QSGListView::itemsMoved(int from, int to, int count)
d->moveReason = QSGListViewPrivate::Other;
FxViewItem *firstVisible = d->firstVisibleItem();
- qreal firstItemPos = firstVisible->position();
QHash<int,FxViewItem*> moved;
int moveBy = 0;
bool movingBackwards = from > to;
int firstItemIndex = firstVisible ? firstVisible->index : -1;
+ // if visibleItems.first() is above the content start pos, and the items
+ // beneath it are moved, ensure this first item is later repositioned correctly
+ // (to above the next visible item) so that subsequent layout() is correct
+ bool repositionFirstItem = firstVisible
+ && d->visibleItems.first()->position() < firstVisible->position()
+ && from > d->visibleItems.first()->index;
+
QList<FxViewItem*>::Iterator it = d->visibleItems.begin();
while (it != d->visibleItems.end()) {
FxViewItem *item = *it;
@@ -1829,7 +1835,7 @@ void QSGListView::itemsMoved(int from, int to, int count)
// take the items that are moving
item->index += (to-from);
moved.insert(item->index, item);
- if (item->position() < firstItemPos)
+ if (repositionFirstItem)
moveBy += item->size();
it = d->visibleItems.erase(it);
} else {
@@ -1913,7 +1919,8 @@ void QSGListView::itemsMoved(int from, int to, int count)
}
// Ensure we don't cause an ugly list scroll.
- static_cast<FxListItemSG*>(d->visibleItems.first())->setPosition(d->visibleItems.first()->position() + moveBy);
+ if (d->visibleItems.count())
+ static_cast<FxListItemSG*>(d->visibleItems.first())->setPosition(d->visibleItems.first()->position() + moveBy);
d->updateSections();
d->layout();