diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-10 03:44:48 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-08-10 03:44:48 (GMT) |
commit | 12ffa33ddc725cd94662a383af6e1793049c807c (patch) | |
tree | 8190ce28b9cc6bd23736f718ded3b59d32be80d0 /src | |
parent | 3ee9db1d892927522832b6bc8e1d806e27015bc4 (diff) | |
download | Qt-12ffa33ddc725cd94662a383af6e1793049c807c.zip Qt-12ffa33ddc725cd94662a383af6e1793049c807c.tar.gz Qt-12ffa33ddc725cd94662a383af6e1793049c807c.tar.bz2 |
Simplify QmlDeclarativeData to a single class
Diffstat (limited to 'src')
-rw-r--r-- | src/declarative/qml/qmlcontext.cpp | 11 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontext_p.h | 3 | ||||
-rw-r--r-- | src/declarative/qml/qmldeclarativedata_p.h | 113 | ||||
-rw-r--r-- | src/declarative/qml/qmlengine.cpp | 37 | ||||
-rw-r--r-- | src/declarative/qml/qmlvme.cpp | 6 |
6 files changed, 46 insertions, 125 deletions
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index 8a2732d..18ba906 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -106,8 +106,6 @@ void QmlContextPrivate::init() else scopeChain = parent->d_func()->scopeChain; scopeChain.prepend(scopeObj); - - contextData.context = q; } void QmlContextPrivate::addDefaultObject(QObject *object, Priority priority) @@ -291,13 +289,10 @@ QmlContext::~QmlContext() for (int ii = 0; ii < d->contextObjects.count(); ++ii) { QObjectPrivate *p = QObjectPrivate::get(d->contextObjects.at(ii)); - QmlSimpleDeclarativeData *data = - static_cast<QmlSimpleDeclarativeData *>(p->declarativeData); - if(data && (data->flags & QmlSimpleDeclarativeData::Extended)) { + QmlDeclarativeData *data = + static_cast<QmlDeclarativeData *>(p->declarativeData); + if(data) data->context = 0; - } else { - p->declarativeData = 0; - } } d->contextObjects.clear(); diff --git a/src/declarative/qml/qmlcontext.h b/src/declarative/qml/qmlcontext.h index 1f29ca2..70a81fc 100644 --- a/src/declarative/qml/qmlcontext.h +++ b/src/declarative/qml/qmlcontext.h @@ -89,7 +89,6 @@ private: friend class QmlComponent; friend class QmlScriptPrivate; friend class QmlBoundSignalProxy; - friend class QmlSimpleDeclarativeData; QmlContext(QmlContext *parent, QObject *objParent, bool); QmlContext(QmlEngine *, bool); }; diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h index 60655ae..0424a85 100644 --- a/src/declarative/qml/qmlcontext_p.h +++ b/src/declarative/qml/qmlcontext_p.h @@ -106,7 +106,6 @@ public: QmlExpressionPrivate *expressions; - QmlSimpleDeclarativeData contextData; QObjectList contextObjects; struct ContextGuard : public QGuard<QObject> @@ -115,7 +114,7 @@ public: ContextGuard &operator=(QObject *obj) { (QGuard<QObject>&)*this = obj; return *this; } - void objectDestroyed(QObject *o) { priv->destroyed(this); } + void objectDestroyed(QObject *) { priv->destroyed(this); } }; ContextGuard *idValues; int idValueCount; diff --git a/src/declarative/qml/qmldeclarativedata_p.h b/src/declarative/qml/qmldeclarativedata_p.h index b473e77..8d30bcc 100644 --- a/src/declarative/qml/qmldeclarativedata_p.h +++ b/src/declarative/qml/qmldeclarativedata_p.h @@ -57,113 +57,36 @@ QT_BEGIN_NAMESPACE -class QmlSimpleDeclarativeData : public QDeclarativeData -{ -public: - QmlSimpleDeclarativeData() : flags(0), context(0) {} - - virtual void destroyed(QObject *); - enum Flag { Instance = 0x00000001, Extended = 0x00000002 }; - quint32 flags; - QmlContext *context; - - static inline QmlSimpleDeclarativeData *get(QObject *object, - bool create = false); -}; - class QmlCompiledData; -class QmlInstanceDeclarativeData : public QmlSimpleDeclarativeData +class QmlBinding; +class QmlDeclarativeData : public QDeclarativeData { public: - QmlInstanceDeclarativeData() : deferredComponent(0) { flags |= Instance; } + QmlDeclarativeData(QmlContext *context = 0); virtual void destroyed(QObject *); - QmlCompiledData *deferredComponent; - unsigned int deferredIdx; - - static inline QmlInstanceDeclarativeData *get(QObject *object, - bool create = false); -}; - -class QmlExtendedDeclarativeData : public QmlInstanceDeclarativeData -{ -public: - QmlExtendedDeclarativeData() { flags |= Extended; } - - QHash<int, QObject *> attachedProperties; - - static inline QmlExtendedDeclarativeData *get(QObject *object, - bool create = false); -}; - -QmlSimpleDeclarativeData * -QmlSimpleDeclarativeData::get(QObject *object, bool create) -{ - QObjectPrivate *priv = QObjectPrivate::get(object); - - if (create && !priv->declarativeData) - priv->declarativeData = new QmlInstanceDeclarativeData; - - return static_cast<QmlSimpleDeclarativeData *>(priv->declarativeData); -} - -QmlInstanceDeclarativeData * -QmlInstanceDeclarativeData::get(QObject *object, bool create) -{ - QObjectPrivate *priv = QObjectPrivate::get(object); - - QmlSimpleDeclarativeData *simple = - static_cast<QmlSimpleDeclarativeData *>(priv->declarativeData); - - if (simple && (simple->flags & Instance)) { - return static_cast<QmlInstanceDeclarativeData *>(simple); - } else if (create && simple) { - QmlInstanceDeclarativeData *rv = new QmlInstanceDeclarativeData; - rv->context = simple->context; - simple->destroyed(object); - priv->declarativeData = rv; - return rv; - } else if (create) { - QmlInstanceDeclarativeData *rv = new QmlInstanceDeclarativeData; - priv->declarativeData = rv; - return rv; - } - return 0; -} - -QmlExtendedDeclarativeData * -QmlExtendedDeclarativeData::get(QObject *object, bool create) -{ - QObjectPrivate *priv = QObjectPrivate::get(object); + QmlContext *context; + QmlBinding *bindings; - QmlSimpleDeclarativeData *simple = - static_cast<QmlSimpleDeclarativeData *>(priv->declarativeData); + QmlCompiledData *deferredComponent; // Can't this be found from the context? + unsigned int deferredIdx; - if (simple && (simple->flags & Extended)) { - return static_cast<QmlExtendedDeclarativeData *>(simple); - } else if (create && simple) { - QmlExtendedDeclarativeData *rv = new QmlExtendedDeclarativeData; - rv->context = simple->context; + QHash<int, QObject *> *attachedProperties; - if (simple->flags & Instance) { - QmlInstanceDeclarativeData *instance = - static_cast<QmlInstanceDeclarativeData *>(priv->declarativeData); - rv->deferredComponent = instance->deferredComponent; - rv->deferredIdx = instance->deferredIdx; - delete simple; + static QmlDeclarativeData *get(const QObject *object, bool create = false) { + QObjectPrivate *priv = + QObjectPrivate::get(const_cast<QObject *>(object)); + if (priv && priv->declarativeData) { + return static_cast<QmlDeclarativeData *>(priv->declarativeData); + } else if (create && priv) { + priv->declarativeData = new QmlDeclarativeData; + return static_cast<QmlDeclarativeData *>(priv->declarativeData); } else { - simple->destroyed(object); + return 0; } - priv->declarativeData = rv; - return rv; - } else if (create) { - QmlExtendedDeclarativeData *rv = new QmlExtendedDeclarativeData; - priv->declarativeData = rv; - return rv; } - return 0; -} +}; QT_END_NAMESPACE diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 68ad655..09539bc 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -427,8 +427,8 @@ QmlContext *QmlEngine::contextForObject(const QObject *object) QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object)); - QmlSimpleDeclarativeData *data = - static_cast<QmlSimpleDeclarativeData *>(priv->declarativeData); + QmlDeclarativeData *data = + static_cast<QmlDeclarativeData *>(priv->declarativeData); return data?data->context:0; } @@ -444,8 +444,8 @@ void QmlEngine::setContextForObject(QObject *object, QmlContext *context) { QObjectPrivate *priv = QObjectPrivate::get(object); - QmlSimpleDeclarativeData *data = - static_cast<QmlSimpleDeclarativeData *>(priv->declarativeData); + QmlDeclarativeData *data = + static_cast<QmlDeclarativeData *>(priv->declarativeData); if (data && data->context) { qWarning("QmlEngine::setContextForObject(): Object already has a QmlContext"); @@ -453,7 +453,7 @@ void QmlEngine::setContextForObject(QObject *object, QmlContext *context) } if (!data) { - priv->declarativeData = &context->d_func()->contextData; + priv->declarativeData = new QmlDeclarativeData(context); } else { data->context = context; } @@ -463,7 +463,7 @@ void QmlEngine::setContextForObject(QObject *object, QmlContext *context) void qmlExecuteDeferred(QObject *object) { - QmlInstanceDeclarativeData *data = QmlInstanceDeclarativeData::get(object); + QmlDeclarativeData *data = QmlDeclarativeData::get(object); if (data && data->deferredComponent) { QmlVME vme; @@ -487,10 +487,9 @@ QmlEngine *qmlEngine(const QObject *obj) QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool create) { - QmlExtendedDeclarativeData *edata = - QmlExtendedDeclarativeData::get(const_cast<QObject *>(object), true); + QmlDeclarativeData *data = QmlDeclarativeData::get(object); - QObject *rv = edata->attachedProperties.value(id); + QObject *rv = data->attachedProperties?data->attachedProperties->value(id):0; if (rv || !create) return rv; @@ -500,23 +499,29 @@ QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool cre rv = pf(const_cast<QObject *>(object)); - if (rv) - edata->attachedProperties.insert(id, rv); + if (rv) { + if (!data->attachedProperties) + data->attachedProperties = new QHash<int, QObject *>(); + data->attachedProperties->insert(id, rv); + } return rv; } -void QmlSimpleDeclarativeData::destroyed(QObject *object) +QmlDeclarativeData::QmlDeclarativeData(QmlContext *ctxt) +: context(ctxt), bindings(0), deferredComponent(0), attachedProperties(0) { - if (context) - context->d_func()->contextObjects.removeAll(object); } -void QmlInstanceDeclarativeData::destroyed(QObject *object) +void QmlDeclarativeData::destroyed(QObject *object) { - QmlSimpleDeclarativeData::destroyed(object); if (deferredComponent) deferredComponent->release(); + if (attachedProperties) + delete attachedProperties; + if (context) + static_cast<QmlContextPrivate *>(QObjectPrivate::get(context))->contextObjects.removeAll(object); + delete this; } diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp index bf3b31a..ffe8591 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -111,7 +111,7 @@ QObject *QmlVME::run(QmlContext *ctxt, QmlCompiledData *comp, int start, int cou void QmlVME::runDeferred(QObject *object) { - QmlInstanceDeclarativeData *data = QmlInstanceDeclarativeData::get(object); + QmlDeclarativeData *data = QmlDeclarativeData::get(object); if (!data || !data->context || !data->deferredComponent) return; @@ -725,8 +725,8 @@ QObject *QmlVME::run(QStack<QObject *> &stack, QmlContext *ctxt, QmlCompiledData { if (instr.defer.deferCount) { QObject *target = stack.top(); - QmlInstanceDeclarativeData *data = - QmlInstanceDeclarativeData::get(target, true); + QmlDeclarativeData *data = + QmlDeclarativeData::get(target, true); comp->addref(); data->deferredComponent = comp; data->deferredIdx = ii; |