}
}
+void QQuickItemViewChangeSet::applyBufferedChanges(const QQuickItemViewChangeSet &other)
+{
+ if (!other.hasPendingChanges())
+ return;
+
+ pendingChanges.apply(other.pendingChanges);
+ itemCount = other.itemCount;
+ newCurrentIndex = other.newCurrentIndex;
+ currentChanged = other.currentChanged;
+ currentRemoved = other.currentRemoved;
+}
+
void QQuickItemViewChangeSet::prepare(int currentIndex, int count)
{
if (active)
polish();
}
} else {
- d->currentChanges.prepare(d->currentIndex, d->itemCount);
- d->currentChanges.applyChanges(changeSet);
+ if (d->disableLayout) {
+ d->bufferedChanges.prepare(d->currentIndex, d->itemCount);
+ d->bufferedChanges.applyChanges(changeSet);
+ } else {
+ if (d->bufferedChanges.hasPendingChanges()) {
+ d->currentChanges.applyBufferedChanges(d->bufferedChanges);
+ d->bufferedChanges.reset();
+ }
+ d->currentChanges.prepare(d->currentIndex, d->itemCount);
+ d->currentChanges.applyChanges(changeSet);
+ }
polish();
}
}
bool QQuickItemViewPrivate::applyModelChanges(ChangeResult *totalInsertionResult, ChangeResult *totalRemovalResult)
{
Q_Q(QQuickItemView);
- if (!q->isComponentComplete() || (!currentChanges.hasPendingChanges() && !runDelayedRemoveTransition) || disableLayout)
+ if (!q->isComponentComplete() || (!currentChanges.hasPendingChanges() && !bufferedChanges.hasPendingChanges() && !runDelayedRemoveTransition) || disableLayout)
return false;
disableLayout = true;
+ if (bufferedChanges.hasPendingChanges()) {
+ currentChanges.applyBufferedChanges(bufferedChanges);
+ bufferedChanges.reset();
+ }
+
updateUnrequestedIndexes();
moveReason = QQuickItemViewPrivate::Other;
void applyChanges(const QQuickChangeSet &changeSet);
+ void applyBufferedChanges(const QQuickItemViewChangeSet &other);
+
int itemCount;
int newCurrentIndex;
QQuickChangeSet pendingChanges;
int requestedIndex;
FxViewItem *requestedItem;
QQuickItemViewChangeSet currentChanges;
+ QQuickItemViewChangeSet bufferedChanges;
QQmlComponent *highlightComponent;
FxViewItem *highlight;
--- /dev/null
+import QtQuick 2.0
+
+Rectangle {
+ id: root
+
+ width: 240
+ height: 320
+
+ property int createdIndex: -1
+
+ Component {
+ id: myDelegate
+
+ Rectangle {
+ id: wrapper
+ width: 240; height: 20
+ objectName: "wrapper"
+
+ Text { text: index }
+
+ Component.onCompleted: {
+ root.createdIndex = index
+ ListView.view.model.removeItem(index)
+ }
+ }
+ }
+
+ ListView {
+ id: list
+ objectName: "list"
+ focus: true
+ width: 240
+ height: 320
+ delegate: myDelegate
+ model: testModel
+ }
+}
void multipleDisplaced();
void flickBeyondBounds();
+ void destroyItemOnCreation();
private:
template <class T> void items(const QUrl &source, bool forceLayout);
delete canvas;
}
+void tst_QQuickListView::destroyItemOnCreation()
+{
+ QmlListModel model;
+ QQuickView *canvas = createView();
+ canvas->rootContext()->setContextProperty("testModel", &model);
+
+ canvas->setSource(testFileUrl("destroyItemOnCreation.qml"));
+ canvas->show();
+ qApp->processEvents();
+
+ QQuickListView *listview = findItem<QQuickListView>(canvas->rootObject(), "list");
+ QVERIFY(listview != 0);
+
+ QQuickItem *contentItem = listview->contentItem();
+ QVERIFY(contentItem != 0);
+ QTRY_COMPARE(QQuickItemPrivate::get(listview)->polishScheduled, false);
+
+ QCOMPARE(canvas->rootObject()->property("createdIndex").toInt(), -1);
+ model.addItem("new item", "");
+ QTRY_COMPARE(canvas->rootObject()->property("createdIndex").toInt(), 0);
+
+ QTRY_COMPARE(findItems<QQuickItem>(contentItem, "wrapper").count(), 0);
+ QCOMPARE(model.count(), 0);
+
+ delete canvas;
+}
QTEST_MAIN(tst_QQuickListView)
void insertItem(int index, const QString &name, const QString &number);
void insertItems(int index, const QList<QPair<QString, QString> > &items);
- void removeItem(int index);
- void removeItems(int index, int count);
+ Q_INVOKABLE void removeItem(int index);
+ Q_INVOKABLE void removeItems(int index, int count);
void moveItem(int from, int to);
void moveItems(int from, int to, int count);