Q_D(QQuickVisualItemModel);
QQuickVisualItemModelPrivate::Item &item = d->children[index];
item.addRef();
- emit initItem(index, item.item);
- emit createdItem(index, item.item);
+ if (item.ref == 1) {
+ emit initItem(index, item.item);
+ emit createdItem(index, item.item);
+ }
return item.item;
}
if (d->children[idx].deref()) {
// XXX todo - the original did item->scene()->removeItem(). Why?
item->setParentItem(0);
+ } else {
+ return QQuickVisualModel::Referenced;
}
}
return 0;
--- /dev/null
+// This example demonstrates placing items in a view using
+// a VisualItemModel
+
+import QtQuick 2.0
+
+Rectangle {
+ color: "lightgray"
+ width: 240
+ height: 320
+
+ VisualItemModel {
+ id: itemModel
+ objectName: "itemModel"
+ Rectangle {
+ objectName: "item1"
+ height: view.height / 3
+ width: view.width; color: "#FFFEF0"
+ Text { objectName: "text1"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ Rectangle {
+ objectName: "item2"
+ height: view.height / 3
+ width: view.width; color: "#F0FFF7"
+ Text { objectName: "text2"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ Rectangle {
+ objectName: "item3"
+ height: view.height / 3
+ width: view.width; color: "#F4F0FF"
+ Text { objectName: "text3"; text: "index: " + parent.VisualItemModel.index; font.bold: true; anchors.centerIn: parent }
+ }
+ }
+
+ ListView {
+ id: view
+ objectName: "view"
+ anchors.fill: parent
+ anchors.bottomMargin: 30
+ model: itemModel
+ preferredHighlightBegin: 0
+ preferredHighlightEnd: 0
+ highlightRangeMode: "StrictlyEnforceRange"
+ orientation: ListView.Vertical
+ flickDeceleration: 2000
+ }
+}
void insertBeforeVisible_data();
void swapWithFirstItem();
void itemList();
+ void itemListFlicker();
void currentIndex_delayedItemCreation();
void currentIndex_delayedItemCreation_data();
void currentIndex();
delete canvas;
}
+void tst_QQuickListView::itemListFlicker()
+{
+ QQuickView *canvas = createView();
+ canvas->setSource(testFileUrl("itemlist-flicker.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickListView *listview = findItem<QQuickListView>(canvas->rootObject(), "view");
+ QTRY_VERIFY(listview != 0);
+
+ QQuickItem *contentItem = listview->contentItem();
+ QTRY_VERIFY(contentItem != 0);
+
+ QQuickVisualItemModel *model = canvas->rootObject()->findChild<QQuickVisualItemModel*>("itemModel");
+ QTRY_VERIFY(model != 0);
+
+ QTRY_VERIFY(model->count() == 3);
+ QTRY_COMPARE(listview->currentIndex(), 0);
+
+ QQuickItem *item;
+
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item1"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item2"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item3"));
+ QVERIFY(item->isVisible());
+
+ listview->setCurrentIndex(1);
+
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item1"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item2"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item3"));
+ QVERIFY(item->isVisible());
+
+ listview->setCurrentIndex(2);
+
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item1"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item2"));
+ QVERIFY(item->isVisible());
+ QVERIFY(item = findItem<QQuickItem>(contentItem, "item3"));
+ QVERIFY(item->isVisible());
+
+ delete canvas;
+}
+
void tst_QQuickListView::cacheBuffer()
{
QQuickView *canvas = createView();