diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativecomponent.cpp')
-rw-r--r-- | src/declarative/qml/qdeclarativecomponent.cpp | 82 |
1 files changed, 35 insertions, 47 deletions
diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index d6bb216..a280d7e 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -404,23 +404,9 @@ QDeclarativeContext *QDeclarativeComponent::creationContext() const { Q_D(const QDeclarativeComponent); if(d->creationContext) - return d->creationContext; - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(this); - if (ddata) - return ddata->context; - else - return 0; -} + return d->creationContext->asQDeclarativeContext(); -/*! - \internal - Sets the QDeclarativeContext the component was created in. This is only - desirable for components created in QML script. -*/ -void QDeclarativeComponent::setCreationContext(QDeclarativeContext* c) -{ - Q_D(QDeclarativeComponent); - d->creationContext = c; + return qmlContext(this); } /*! @@ -512,7 +498,6 @@ QDeclarativeComponent::QDeclarativeComponent(QDeclarativeComponentPrivate &dd, Q { } - /*! \internal A version of create which returns a scriptObject, for use in script @@ -526,7 +511,9 @@ QScriptValue QDeclarativeComponent::createObject() return QScriptValue(); } QObject* ret = create(ctxt); - return QDeclarativeEnginePrivate::qmlScriptObject(ret, d->engine); + QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine); + QDeclarativeDeclarativeData::get(ret, true)->setImplicitDestructible(); + return priv->objectClass->newQObject(ret, QMetaType::QObjectStar); } /*! @@ -541,19 +528,19 @@ QObject *QDeclarativeComponent::create(QDeclarativeContext *context) { Q_D(QDeclarativeComponent); - return d->create(context, QBitField()); + if (!context) + context = d->engine->rootContext(); + + QObject *rv = beginCreate(context); + completeCreate(); + return rv; } -QObject *QDeclarativeComponentPrivate::create(QDeclarativeContext *context, - const QBitField &bindings) +QObject *QDeclarativeComponentPrivate::create(QDeclarativeContextData *context, + const QBitField &bindings) { if (!context) - context = engine->rootContext(); - - if (context->engine() != engine) { - qWarning("QDeclarativeComponent::create(): Must create component in context from the same QDeclarativeEngine"); - return 0; - } + context = QDeclarativeContextData::get(engine->rootContext()); QObject *rv = beginCreate(context, bindings); completeCreate(); @@ -586,11 +573,17 @@ QObject *QDeclarativeComponentPrivate::create(QDeclarativeContext *context, QObject *QDeclarativeComponent::beginCreate(QDeclarativeContext *context) { Q_D(QDeclarativeComponent); - return d->beginCreate(context, QBitField()); + QObject *rv = d->beginCreate(context?QDeclarativeContextData::get(context):0, QBitField()); + if (rv) { + QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(rv); + Q_ASSERT(ddata); + ddata->indestructible = true; + } + return rv; } QObject * -QDeclarativeComponentPrivate::beginCreate(QDeclarativeContext *context, const QBitField &bindings) +QDeclarativeComponentPrivate::beginCreate(QDeclarativeContextData *context, const QBitField &bindings) { Q_Q(QDeclarativeComponent); if (!context) { @@ -598,7 +591,7 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContext *context, const QB return 0; } - if (context->engine() != engine) { + if (context->engine != engine) { qWarning("QDeclarativeComponent::beginCreate(): Must create component in context from the same QDeclarativeEngine"); return 0; } @@ -615,29 +608,24 @@ QDeclarativeComponentPrivate::beginCreate(QDeclarativeContext *context, const QB QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine); - QDeclarativeContextPrivate *contextPriv = - static_cast<QDeclarativeContextPrivate *>(QObjectPrivate::get(context)); - QDeclarativeContext *ctxt = new QDeclarativeContext(context, 0, true); - static_cast<QDeclarativeContextPrivate*>(ctxt->d_func())->url = cc->url; - static_cast<QDeclarativeContextPrivate*>(ctxt->d_func())->imports = cc->importCache; + QDeclarativeContextData *ctxt = new QDeclarativeContextData; + ctxt->isInternal = true; + ctxt->url = cc->url; + ctxt->imports = cc->importCache; cc->importCache->addref(); + ctxt->setParent(context); QObject *rv = begin(ctxt, ep, cc, start, count, &state, bindings); - if (rv) { - QDeclarative_setParent_noEvent(ctxt, rv); - } else { - delete ctxt; - } + if (rv && !context->isInternal && ep->isDebugging) + context->asQDeclarativeContextPrivate()->instances.append(rv); - if (rv && !contextPriv->isInternal && ep->isDebugging) - contextPriv->instances.append(rv); return rv; } -QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContext *ctxt, QDeclarativeEnginePrivate *enginePriv, - QDeclarativeCompiledData *component, int start, int count, - ConstructionState *state, const QBitField &bindings) +QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv, + QDeclarativeCompiledData *component, int start, int count, + ConstructionState *state, const QBitField &bindings) { bool isRoot = !enginePriv->inBeginCreate; enginePriv->inBeginCreate = true; @@ -667,8 +655,8 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContext *ctxt, QDeclar return rv; } -void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContext *, QDeclarativeEnginePrivate *enginePriv, - QObject *object, ConstructionState *state) +void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContextData *, QDeclarativeEnginePrivate *enginePriv, + QObject *object, ConstructionState *state) { bool isRoot = !enginePriv->inBeginCreate; enginePriv->inBeginCreate = true; |