diff options
Diffstat (limited to 'src/declarative/qml/qdeclarativecontext_p.h')
-rw-r--r-- | src/declarative/qml/qdeclarativecontext_p.h | 187 |
1 files changed, 131 insertions, 56 deletions
diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index 8297280..d74aa33 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -56,9 +56,11 @@ #include "qdeclarativecontext.h" #include "qdeclarativedeclarativedata_p.h" -#include "qdeclarativeengine_p.h" #include "qdeclarativeintegercache_p.h" #include "qdeclarativetypenamecache_p.h" +#include "qdeclarativenotifier_p.h" +#include "qdeclarativelist.h" +#include "qdeclarativeparser_p.h" #include <QtCore/qhash.h> #include <QtScript/qscriptvalue.h> @@ -77,6 +79,7 @@ class QDeclarativeExpressionPrivate; class QDeclarativeAbstractExpression; class QDeclarativeBinding_Id; class QDeclarativeCompiledBindings; +class QDeclarativeContextData; class Q_DECLARATIVE_EXPORT QDeclarativeContextPrivate : public QObjectPrivate { @@ -84,110 +87,182 @@ class Q_DECLARATIVE_EXPORT QDeclarativeContextPrivate : public QObjectPrivate public: QDeclarativeContextPrivate(); - QDeclarativeContext *parent; + QDeclarativeContextData *data; + + QList<QVariant> propertyValues; + int notifyIndex; + + static QDeclarativeContextPrivate *get(QDeclarativeContext *context) { + return static_cast<QDeclarativeContextPrivate *>(QObjectPrivate::get(context)); + } + static QDeclarativeContext *get(QDeclarativeContextPrivate *context) { + return static_cast<QDeclarativeContext *>(context->q_func()); + } + + // Only used for debugging + QList<QPointer<QObject> > instances; + + static int context_count(QDeclarativeListProperty<QObject> *); + static QObject *context_at(QDeclarativeListProperty<QObject> *, int); +}; + +class QDeclarativeGuardedContextData; +class QDeclarativeContextData +{ +public: + QDeclarativeContextData(); + QDeclarativeContextData(QDeclarativeContext *); + void destroy(); + + // My parent context and engine + QDeclarativeContextData *parent; QDeclarativeEngine *engine; + void setParent(QDeclarativeContextData *); + void invalidateEngines(); + void refreshExpressions(); + + void addObject(QObject *); + + QUrl resolvedUrl(const QUrl &); + + // My containing QDeclarativeContext. If isInternal is true this owns publicContext. + // If internal is false publicContext owns this. + QDeclarativeContext *asQDeclarativeContext(); + QDeclarativeContextPrivate *asQDeclarativeContextPrivate(); bool isInternal; + QDeclarativeContext *publicContext; + // Property name cache QDeclarativeIntegerCache *propertyNames; - QList<QVariant> propertyValues; - int notifyIndex; - QObjectList defaultObjects; - int highPriorityCount; + // Context object + QObject *contextObject; + // Any script blocks that exist on this context QList<QScriptValue> scripts; - void addScript(const QDeclarativeParser::Object::ScriptBlock &, QObject *); + void addScript(const QDeclarativeParser::Object::ScriptBlock &script, QObject *scopeObject); + // Context base url QUrl url; + // List of imports that apply to this context QDeclarativeTypeNameCache *imports; - void init(); + // My children + QDeclarativeContextData *childContexts; - void invalidateEngines(); - void refreshExpressions(); - QSet<QDeclarativeContext *> childContexts; + // My peers in parent's childContexts list + QDeclarativeContextData *nextChild; + QDeclarativeContextData **prevChild; + // Expressions that use this context QDeclarativeAbstractExpression *expressions; + // Doubly-linked list of objects that are owned by this context QDeclarativeDeclarativeData *contextObjects; - struct IdNotifier - { - inline IdNotifier(); - inline ~IdNotifier(); - - inline void clear(); - - IdNotifier *next; - IdNotifier**prev; - QObject *target; - int methodIndex; - }; + // Doubly-linked list of context guards (XXX merge with contextObjects) + QDeclarativeGuardedContextData *contextGuards; + // id guards struct ContextGuard : public QDeclarativeGuard<QObject> { - inline ContextGuard(); - inline ContextGuard &operator=(QObject *obj); - inline virtual void objectDestroyed(QObject *); - - QDeclarativeContextPrivate *priv; - IdNotifier *bindings; + ContextGuard() : context(0) {} + inline ContextGuard &operator=(QObject *obj) + { QDeclarativeGuard<QObject>::operator=(obj); return *this; } + virtual void objectDestroyed(QObject *) { + if (!QObjectPrivate::get(context->contextObject)->wasDeleted) bindings.notify(); + } + QDeclarativeContextData *context; + QDeclarativeNotifier bindings; }; ContextGuard *idValues; int idValueCount; void setIdProperty(int, QObject *); void setIdPropertyData(QDeclarativeIntegerCache *); - void destroyed(ContextGuard *); - static QDeclarativeContextPrivate *get(QDeclarativeContext *context) { - return static_cast<QDeclarativeContextPrivate *>(QObjectPrivate::get(context)); - } - static QDeclarativeContext *get(QDeclarativeContextPrivate *context) { - return static_cast<QDeclarativeContext *>(context->q_func()); + // Optimized binding pointer + QDeclarativeCompiledBindings *optimizedBindings; + + // Linked contexts. this owns linkedContext. + QDeclarativeContextData *linkedContext; + + static QDeclarativeContextData *get(QDeclarativeContext *context) { + return QDeclarativeContextPrivate::get(context)->data; } - QDeclarativeCompiledBindings *optimizedBindings; +private: + ~QDeclarativeContextData() {} +}; - // Only used for debugging - QList<QPointer<QObject> > instances; +class QDeclarativeGuardedContextData +{ +public: + inline QDeclarativeGuardedContextData(); + inline QDeclarativeGuardedContextData(QDeclarativeContextData *); + inline ~QDeclarativeGuardedContextData(); - static int context_count(QDeclarativeListProperty<QObject> *); - static QObject *context_at(QDeclarativeListProperty<QObject> *, int); + inline void setContextData(QDeclarativeContextData *); + + inline QDeclarativeContextData *contextData(); + + inline operator QDeclarativeContextData*() const { return m_contextData; } + inline QDeclarativeContextData* operator->() const { return m_contextData; } + +private: + friend class QDeclarativeContextData; + + inline void clear(); + + QDeclarativeContextData *m_contextData; + QDeclarativeGuardedContextData *m_next; + QDeclarativeGuardedContextData **m_prev; }; -QDeclarativeContextPrivate::IdNotifier::IdNotifier() -: next(0), prev(0), target(0), methodIndex(-1) +QDeclarativeGuardedContextData::QDeclarativeGuardedContextData() +: m_contextData(0), m_next(0), m_prev(0) { } -QDeclarativeContextPrivate::IdNotifier::~IdNotifier() +QDeclarativeGuardedContextData::QDeclarativeGuardedContextData(QDeclarativeContextData *data) +: m_contextData(0), m_next(0), m_prev(0) { - clear(); + setContextData(data); } -void QDeclarativeContextPrivate::IdNotifier::clear() +QDeclarativeGuardedContextData::~QDeclarativeGuardedContextData() { - if (next) next->prev = prev; - if (prev) *prev = next; - next = 0; prev = 0; target = 0; - methodIndex = -1; + clear(); } -QDeclarativeContextPrivate::ContextGuard::ContextGuard() -: priv(0), bindings(0) +void QDeclarativeGuardedContextData::setContextData(QDeclarativeContextData *contextData) { + clear(); + + if (contextData) { + m_contextData = contextData; + m_next = contextData->contextGuards; + if (m_next) m_next->m_prev = &m_next; + m_prev = &contextData->contextGuards; + contextData->contextGuards = this; + } } -QDeclarativeContextPrivate::ContextGuard &QDeclarativeContextPrivate::ContextGuard::operator=(QObject *obj) +QDeclarativeContextData *QDeclarativeGuardedContextData::contextData() { - (QDeclarativeGuard<QObject>&)*this = obj; return *this; + return m_contextData; } -void QDeclarativeContextPrivate::ContextGuard::objectDestroyed(QObject *) -{ - priv->destroyed(this); +void QDeclarativeGuardedContextData::clear() +{ + if (m_prev) { + *m_prev = m_next; + if (m_next) m_next->m_prev = m_prev; + m_contextData = 0; + m_next = 0; + m_prev = 0; + } } QT_END_NAMESPACE |