diff options
-rw-r--r-- | src/qml/qml/qqmlcontext.cpp | 2 | ||||
-rw-r--r-- | src/qml/qml/qqmlcontext_p.h | 11 | ||||
-rw-r--r-- | src/qml/qml/qqmlincubator.cpp | 5 | ||||
-rw-r--r-- | src/qmlmodels/qqmldelegatemodel.cpp | 8 |
4 files changed, 20 insertions, 6 deletions
diff --git a/src/qml/qml/qqmlcontext.cpp b/src/qml/qml/qqmlcontext.cpp index 14892bd6ad..668f00b136 100644 --- a/src/qml/qml/qqmlcontext.cpp +++ b/src/qml/qml/qqmlcontext.cpp @@ -550,7 +550,7 @@ QQmlContextData::QQmlContextData() QQmlContextData::QQmlContextData(QQmlContext *ctxt) : engine(nullptr), isInternal(false), isJSContext(false), isPragmaLibraryContext(false), unresolvedNames(false), hasEmittedDestruction(false), isRootObjectInCreation(false), - stronglyReferencedByParent(false), publicContext(ctxt), incubator(nullptr), componentObjectIndex(-1), + stronglyReferencedByParent(false), hasExtraObject(false), publicContext(ctxt), incubator(nullptr), componentObjectIndex(-1), contextObject(nullptr), nextChild(nullptr), prevChild(nullptr), expressions(nullptr), contextObjects(nullptr), idValues(nullptr), idValueCount(0), componentAttached(nullptr) diff --git a/src/qml/qml/qqmlcontext_p.h b/src/qml/qml/qqmlcontext_p.h index 5f7316b00c..f93393a11b 100644 --- a/src/qml/qml/qqmlcontext_p.h +++ b/src/qml/qml/qqmlcontext_p.h @@ -147,11 +147,16 @@ public: quint32 hasEmittedDestruction:1; quint32 isRootObjectInCreation:1; quint32 stronglyReferencedByParent:1; - quint32 dummy:25; + quint32 hasExtraObject:1; // used in QQmlDelegateModelItem::dataForObject to find the corresponding QQmlDelegateModelItem of an object + quint32 dummy:24; QQmlContext *publicContext; - // The incubator that is constructing this context if any - QQmlIncubatorPrivate *incubator; + union { + // The incubator that is constructing this context if any + QQmlIncubatorPrivate *incubator; + // a pointer to extra data, currently only used in QQmlDelegateModel + QObject *extraObject; + }; // Compilation unit for contexts that belong to a compiled type. QQmlRefPointer<QV4::ExecutableCompilationUnit> typeCompilationUnit; diff --git a/src/qml/qml/qqmlincubator.cpp b/src/qml/qml/qqmlincubator.cpp index 5c3ecbfb60..f0ef5360b0 100644 --- a/src/qml/qml/qqmlincubator.cpp +++ b/src/qml/qml/qqmlincubator.cpp @@ -61,7 +61,7 @@ void QQmlEnginePrivate::incubate(QQmlIncubator &i, QQmlContextData *forContext) QExplicitlySharedDataPointer<QQmlIncubatorPrivate> parentIncubator; QQmlContextData *cctxt = forContext; while (cctxt) { - if (cctxt->incubator) { + if (!cctxt->hasExtraObject && cctxt->incubator) { parentIncubator = cctxt->incubator; break; } @@ -149,7 +149,8 @@ void QQmlIncubatorPrivate::clear() } enginePriv = nullptr; if (!rootContext.isNull()) { - rootContext->incubator = nullptr; + if (!rootContext->hasExtraObject) + rootContext->incubator = nullptr; rootContext = nullptr; } diff --git a/src/qmlmodels/qqmldelegatemodel.cpp b/src/qmlmodels/qqmldelegatemodel.cpp index e2a750a43a..55bf2ad783 100644 --- a/src/qmlmodels/qqmldelegatemodel.cpp +++ b/src/qmlmodels/qqmldelegatemodel.cpp @@ -932,6 +932,12 @@ void PropertyUpdater::breakBinding() void QQDMIncubationTask::initializeRequiredProperties(QQmlDelegateModelItem *modelItemToIncubate, QObject *object) { auto incubatorPriv = QQmlIncubatorPrivate::get(this); + QQmlData *d = QQmlData::get(object); + auto contextData = d ? d->context : nullptr; + if (contextData) { + contextData->hasExtraObject = true; + contextData->extraObject = modelItemToIncubate; + } if (incubatorPriv->hadRequiredProperties()) { if (incubatorPriv->requiredProperties().empty()) return; @@ -2271,6 +2277,8 @@ QQmlDelegateModelItem *QQmlDelegateModelItem::dataForObject(QObject *object) { QQmlData *d = QQmlData::get(object); QQmlContextData *context = d ? d->context : nullptr; + if (context && context->hasExtraObject) + return qobject_cast<QQmlDelegateModelItem *>(context->extraObject); for (context = context ? context->parent : nullptr; context; context = context->parent) { if (QQmlDelegateModelItem *cacheItem = qobject_cast<QQmlDelegateModelItem *>( context->contextObject)) { |