void QSGGridViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem)
{
+ if (item == toItem)
+ return;
FxGridItemSG *toGridItem = static_cast<FxGridItemSG*>(toItem);
static_cast<FxGridItemSG*>(item)->setPosition(toGridItem->colPos(), toGridItem->rowPos());
}
for (int i=0; i<addedItems.count(); ++i)
addedItems.at(i)->attached->emitAdd();
- // 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 the first visible item has moved, ensure another one takes its place
+ // so that we avoid shifting all content forwards
+ // (don't use items from removedBeforeFirstVisible - if an item is removed from
+ // before the first visible, the first visible should not move upwards)
if (firstVisible && firstItemIndex >= 0) {
+ bool found = false;
for (int i=0; i<movedBackwards.count(); i++) {
if (movedBackwards[i]->index == firstItemIndex) {
+ // an item has moved backwards up to the first visible's position
resetItemPosition(movedBackwards[i], firstVisible);
movedBackwards.removeAt(i);
+ found = true;
break;
}
}
+ if (!found) {
+ // first visible item has moved forward, another item takes its place
+ FxViewItem *item = visibleItem(firstItemIndex);
+ if (item)
+ resetItemPosition(item, firstVisible);
+ }
}
// Ensure we don't cause an ugly list scroll
void QSGListViewPrivate::resetItemPosition(FxViewItem *item, FxViewItem *toItem)
{
+ if (item == toItem)
+ return;
static_cast<FxListItemSG*>(item)->setPosition(toItem->position());
}
QTest::newRow("move multiple forwards, within visible items")
<< 0.0
<< 0 << 5 << 3
- << 60.0; // moved 3 items (i.e. 1 row) down
+ << 0.0;
+
+ QTest::newRow("move multiple forwards, before visible items")
+ << 120.0 // show 6-23
+ << 3 << 4 << 3 // 3, 4, 5 move to after 6
+ << 60.0; // row of 3,4,5 has moved down
QTest::newRow("move multiple forwards, from non-visible -> visible")
<< 120.0 // show 6-23
QTest::newRow("move multiple forwards, from visible -> non-visible (move first item)")
<< 0.0
<< 0 << 16 << 3
- << 60.0;
+ << 0.0;
QTest::newRow("move multiple backwards, within visible items")
QTest::newRow("move 1 forwards, from visible -> non-visible (move first item)")
<< 0.0
<< 0 << 16 << 1
- << 20.0;
+ << 0.0;
QTest::newRow("move 1 backwards, within visible items")
QTest::newRow("move multiple forwards, within visible items")
<< 0.0
<< 0 << 5 << 3
- << 20.0 * 3;
+ << 0.0;
+
+ QTest::newRow("move multiple forwards, before visible items")
+ << 140.0 // show 7-22
+ << 4 << 5 << 3 // 4,5,6 move to below 7
+ << 20.0 * 3; // 4,5,6 moved down
QTest::newRow("move multiple forwards, from non-visible -> visible")
<< 80.0 // show 4-19
QTest::newRow("move multiple forwards, from visible -> non-visible (move first item)")
<< 0.0
<< 0 << 16 << 3
- << 20.0 * 3;
+ << 0.0;
QTest::newRow("move multiple backwards, within visible items")