From 816b5a667f0b5b47c3f80c2c775535310c89b727 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Wed, 8 Nov 2017 11:01:35 +0100 Subject: QQmlDelegateModel: add incubationStatus(), and use it to determine 'requestedIndex' We used to assign the currently incubating item to 'requestedIndex' based on requested incubation mode alone. This is not sufficient, as the item can also be loaded async when the mode is AsyncIfNested. To check if the item is really loading async (and that we're not getting nullptr because of some other failure), we need to ask the incubator. Task-number: QTBUG-61537 Change-Id: Id1f458db4a7584a6b58d5bad0e7832ce4fc341dc Reviewed-by: J-P Nurmi --- src/quick/items/qquickitemview.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/quick/items/qquickitemview.cpp') diff --git a/src/quick/items/qquickitemview.cpp b/src/quick/items/qquickitemview.cpp index 82dbf04090..10f6c63170 100644 --- a/src/quick/items/qquickitemview.cpp +++ b/src/quick/items/qquickitemview.cpp @@ -2340,14 +2340,20 @@ FxViewItem *QQuickItemViewPrivate::createItem(int modelIndex, QQmlIncubator::Inc } } - if (incubationMode == QQmlIncubator::Asynchronous) - requestedIndex = modelIndex; inRequest = true; QObject* object = model->object(modelIndex, incubationMode); QQuickItem *item = qmlobject_cast(object); + if (!item) { - if (object) { + if (!object) { + if (requestedIndex == -1 && model->incubationStatus(modelIndex) == QQmlIncubator::Loading) { + // The reason we didn't receive an item is because it's incubating async. We keep track + // of this by assigning the index we're waiting for to 'requestedIndex'. This will e.g. let + // the view avoid unnecessary layout calls until the item has been loaded. + requestedIndex = modelIndex; + } + } else { model->release(object); if (!delegateValidated) { delegateValidated = true; -- cgit v1.2.3