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()) {
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 {
}
}
+ // 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;
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;
}
}
+ // 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;
void removed();
void clear();
void moved();
+ void swapWithFirstItem();
void changeFlow();
void currentIndex();
void noCurrentIndex();
QTRY_COMPARE(number->text(), model.number(i));
}
+ delete canvas;
+}
+
+void tst_QSGGridView::swapWithFirstItem()
+{
+ // QTBUG_9697
+ QSGView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+ ctxt->setContextProperty("testRightToLeft", QVariant(false));
+ ctxt->setContextProperty("testTopToBottom", QVariant(false));
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/gridview1.qml"));
+ qApp->processEvents();
+
+ QSGGridView *gridview = findItem<QSGGridView>(canvas->rootObject(), "grid");
+ QTRY_VERIFY(gridview != 0);
+
// ensure content position is stable
gridview->setContentY(0);
model.moveItem(10, 0);
void qListModelInterface_clear();
void qAbstractItemModel_clear();
+ void swapWithFirstItem();
void itemList();
void currentIndex();
void noCurrentIndex();
delete testObject;
}
+void tst_QSGListView::swapWithFirstItem()
+{
+ QSGView *canvas = createView();
+ canvas->show();
+
+ TestModel model;
+ for (int i = 0; i < 30; i++)
+ model.addItem("Item" + QString::number(i), "");
+
+ QDeclarativeContext *ctxt = canvas->rootContext();
+ ctxt->setContextProperty("testModel", &model);
+
+ TestObject *testObject = new TestObject;
+ ctxt->setContextProperty("testObject", testObject);
+
+ canvas->setSource(QUrl::fromLocalFile(SRCDIR "/data/listviewtest.qml"));
+ qApp->processEvents();
+
+ QSGListView *listview = findItem<QSGListView>(canvas->rootObject(), "list");
+ QTRY_VERIFY(listview != 0);
+
+ // ensure content position is stable
+ listview->setContentY(0);
+ model.moveItem(10, 0);
+ QTRY_VERIFY(listview->contentY() == 0);
+
+ delete testObject;
+ delete canvas;
+}
+
void tst_QSGListView::enforceRange()
{
QSGView *canvas = createView();