From 605d6194c9d481a50fbc927a0094446690f651a6 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Sat, 29 Apr 2017 12:33:16 +0200 Subject: QQmlComponent: Move incubateObject from QQmlDelegateModel to QQmlComponentPrivate This feels like a slightly tidier encapsulation. Change-Id: Iff6c05e1fe7fbc6bb1ec58a7ea42d32ee03187df Reviewed-by: Simon Hausmann --- src/qml/qml/qqmlcomponent.cpp | 29 +++++++++++++++++++++++++++++ src/qml/qml/qqmlcomponent_p.h | 7 +++++++ src/qml/types/qqmldelegatemodel.cpp | 28 +++------------------------- src/qml/types/qqmldelegatemodel_p_p.h | 5 ----- 4 files changed, 39 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/qml/qml/qqmlcomponent.cpp b/src/qml/qml/qqmlcomponent.cpp index 9b965a52fb..e7a45482e6 100644 --- a/src/qml/qml/qqmlcomponent.cpp +++ b/src/qml/qml/qqmlcomponent.cpp @@ -1040,6 +1040,35 @@ void QQmlComponent::create(QQmlIncubator &incubator, QQmlContext *context, enginePriv->incubate(incubator, forContextData); } +/* + This is essentially a copy of QQmlComponent::create(); except it takes the QQmlContextData + arguments instead of QQmlContext which means we don't have to construct the rather weighty + wrapper class for every delegate item. + + This is used by QQmlDelegateModel. +*/ +void QQmlComponentPrivate::incubateObject( + QQmlIncubator *incubationTask, + QQmlComponent *component, + QQmlEngine *engine, + QQmlContextData *context, + QQmlContextData *forContext) +{ + QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask); + QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine); + QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component); + + incubatorPriv->compilationUnit = componentPriv->compilationUnit; + incubatorPriv->compilationUnit->addref(); + incubatorPriv->enginePriv = enginePriv; + incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext)); + incubatorPriv->subComponentToCreate = componentPriv->start; + + enginePriv->incubate(*incubationTask, forContext); +} + + + class QQmlComponentIncubator; namespace QV4 { diff --git a/src/qml/qml/qqmlcomponent_p.h b/src/qml/qml/qqmlcomponent_p.h index d01a987acc..6414025574 100644 --- a/src/qml/qml/qqmlcomponent_p.h +++ b/src/qml/qml/qqmlcomponent_p.h @@ -88,6 +88,13 @@ public: void initializeObjectWithInitialProperties(QV4::QmlContext *qmlContext, const QV4::Value &valuemap, QObject *toCreate); static void setInitialProperties(QV4::ExecutionEngine *engine, QV4::QmlContext *qmlContext, const QV4::Value &o, const QV4::Value &v); + void incubateObject( + QQmlIncubator *incubationTask, + QQmlComponent *component, + QQmlEngine *engine, + QQmlContextData *context, + QQmlContextData *forContext); + QQmlTypeData *typeData; void typeDataReady(QQmlTypeData *) override; void typeDataProgress(QQmlTypeData *, qreal) override; diff --git a/src/qml/types/qqmldelegatemodel.cpp b/src/qml/types/qqmldelegatemodel.cpp index 8f4b9cd519..9620df6af9 100644 --- a/src/qml/types/qqmldelegatemodel.cpp +++ b/src/qml/types/qqmldelegatemodel.cpp @@ -988,7 +988,9 @@ QObject *QQmlDelegateModelPrivate::object(Compositor::Group group, int index, bo } } - cacheItem->incubateObject( + QQmlComponentPrivate *cp = QQmlComponentPrivate::get(m_delegate); + cp->incubateObject( + cacheItem->incubationTask, m_delegate, m_context->engine(), ctxt, @@ -1935,30 +1937,6 @@ void QQmlDelegateModelItem::Dispose() delete this; } -/* - This is essentially a copy of QQmlComponent::create(); except it takes the QQmlContextData - arguments instead of QQmlContext which means we don't have to construct the rather weighty - wrapper class for every delegate item. -*/ -void QQmlDelegateModelItem::incubateObject( - QQmlComponent *component, - QQmlEngine *engine, - QQmlContextData *context, - QQmlContextData *forContext) -{ - QQmlIncubatorPrivate *incubatorPriv = QQmlIncubatorPrivate::get(incubationTask); - QQmlEnginePrivate *enginePriv = QQmlEnginePrivate::get(engine); - QQmlComponentPrivate *componentPriv = QQmlComponentPrivate::get(component); - - incubatorPriv->compilationUnit = componentPriv->compilationUnit; - incubatorPriv->compilationUnit->addref(); - incubatorPriv->enginePriv = enginePriv; - incubatorPriv->creator.reset(new QQmlObjectCreator(context, componentPriv->compilationUnit, componentPriv->creationContext)); - incubatorPriv->subComponentToCreate = componentPriv->start; - - enginePriv->incubate(*incubationTask, forContext); -} - void QQmlDelegateModelItem::destroyObject() { Q_ASSERT(object); diff --git a/src/qml/types/qqmldelegatemodel_p_p.h b/src/qml/types/qqmldelegatemodel_p_p.h index cb4a1f79ba..4ebfd9b938 100644 --- a/src/qml/types/qqmldelegatemodel_p_p.h +++ b/src/qml/types/qqmldelegatemodel_p_p.h @@ -112,11 +112,6 @@ public: QObject *modelObject() { return this; } - void incubateObject( - QQmlComponent *component, - QQmlEngine *engine, - QQmlContextData *context, - QQmlContextData *forContext); void destroyObject(); static QQmlDelegateModelItem *dataForObject(QObject *object); -- cgit v1.2.3