diff options
Diffstat (limited to 'src/declarative/qml')
26 files changed, 336 insertions, 225 deletions
diff --git a/src/declarative/qml/qdeclarativebinding.cpp b/src/declarative/qml/qdeclarativebinding.cpp index 664118d..25492ac 100644 --- a/src/declarative/qml/qdeclarativebinding.cpp +++ b/src/declarative/qml/qdeclarativebinding.cpp @@ -46,7 +46,7 @@ #include "qdeclarativecontext.h" #include "qdeclarativeinfo.h" #include "private/qdeclarativecontext_p.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "private/qdeclarativestringconverters_p.h" #include <QVariant> @@ -296,7 +296,7 @@ void QDeclarativeAbstractBinding::addToObject(QObject *object) Q_ASSERT(!m_prevBinding); m_object = object; - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true); + QDeclarativeData *data = QDeclarativeData::get(object, true); if (index & 0xFF000000) { // Value type @@ -348,7 +348,7 @@ void QDeclarativeAbstractBinding::removeFromObject() // Value type - we don't remove the proxy from the object. It will sit their happily // doing nothing for ever more. } else { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(m_object, false); + QDeclarativeData *data = QDeclarativeData::get(m_object, false); if (data) data->clearBindingBit(index); } diff --git a/src/declarative/qml/qdeclarativebinding_p.h b/src/declarative/qml/qdeclarativebinding_p.h index 2789738..2d3acf5 100644 --- a/src/declarative/qml/qdeclarativebinding_p.h +++ b/src/declarative/qml/qdeclarativebinding_p.h @@ -92,7 +92,7 @@ protected: private: - friend class QDeclarativeDeclarativeData; + friend class QDeclarativeData; friend class QDeclarativeValueTypeProxyBinding; friend class QDeclarativePropertyPrivate; friend class QDeclarativeVME; diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index fad7779..065009a 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -67,7 +67,6 @@ #include "private/qdeclarativecompiledbindings_p.h" #include "private/qdeclarativeglobalscriptclass_p.h" -#include <QCoreApplication> #include <QColor> #include <QDebug> #include <QPointF> @@ -1364,35 +1363,6 @@ int QDeclarativeCompiler::componentTypeRef() return output->types.count() - 1; } -QMetaMethod QDeclarativeCompiler::findSignalByName(const QMetaObject *mo, const QByteArray &name) -{ - Q_ASSERT(mo); - int methods = mo->methodCount(); - for (int ii = methods - 1; ii >= 0; --ii) { - QMetaMethod method = mo->method(ii); - QByteArray methodName = method.signature(); - int idx = methodName.indexOf('('); - methodName = methodName.left(idx); - - if (methodName == name) - return method; - } - - // If no signal is found, but the signal is of the form "onBlahChanged", - // return the notify signal for the property "Blah" - if (name.endsWith("Changed")) { - QByteArray propName = name.mid(0, name.length() - 7); - int propIdx = mo->indexOfProperty(propName.constData()); - if (propIdx >= 0) { - QMetaProperty prop = mo->property(propIdx); - if (prop.hasNotifySignal()) - return prop.notifySignal(); - } - } - - return QMetaMethod(); -} - bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDeclarativeParser::Object *obj, const BindingContext &ctxt) { @@ -1404,7 +1374,7 @@ bool QDeclarativeCompiler::buildSignal(QDeclarativeParser::Property *prop, QDecl if(name[0] >= 'A' && name[0] <= 'Z') name[0] = name[0] - 'A' + 'a'; - int sigIdx = findSignalByName(obj->metaObject(), name).methodIndex(); + int sigIdx = QDeclarativePropertyPrivate::findSignalByName(obj->metaObject(), name).methodIndex(); if (sigIdx == -1) { @@ -2976,9 +2946,4 @@ QStringList QDeclarativeCompiler::deferredProperties(QDeclarativeParser::Object return rv; } -QString QDeclarativeCompiler::tr(const char *str) -{ - return QCoreApplication::translate("QDeclarativeCompiler", str); -} - QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativecompiler_p.h b/src/declarative/qml/qdeclarativecompiler_p.h index 0e47774..867db2c 100644 --- a/src/declarative/qml/qdeclarativecompiler_p.h +++ b/src/declarative/qml/qdeclarativecompiler_p.h @@ -66,6 +66,7 @@ #include <QtCore/qbytearray.h> #include <QtCore/qset.h> +#include <QtCore/QCoreApplication> QT_BEGIN_NAMESPACE @@ -148,6 +149,7 @@ private: class QMetaObjectBuilder; class Q_DECLARATIVE_EXPORT QDeclarativeCompiler { + Q_DECLARE_TR_FUNCTIONS(QDeclarativeCompiler) public: QDeclarativeCompiler(); @@ -159,8 +161,6 @@ public: static bool isAttachedPropertyName(const QByteArray &); static bool isSignalPropertyName(const QByteArray &); - static QMetaMethod findSignalByName(const QMetaObject *, const QByteArray &name); - int evaluateEnum(const QByteArray& script) const; // for QDeclarativeCustomParser::evaluateEnum private: @@ -281,8 +281,6 @@ private: void addId(const QString &, QDeclarativeParser::Object *); - QString tr(const char *); - void dumpStats(); struct BindingReference { diff --git a/src/declarative/qml/qdeclarativecomponent.cpp b/src/declarative/qml/qdeclarativecomponent.cpp index 5f26ad5..3e4651c 100644 --- a/src/declarative/qml/qdeclarativecomponent.cpp +++ b/src/declarative/qml/qdeclarativecomponent.cpp @@ -120,6 +120,26 @@ Item { } } \endqml + + \e onDestruction + + Emitted as the component begins destruction. This can be used to undo + work done in the onCompleted signal, or other imperative code in your + application. + + The \c {Component::onDestruction} attached property can be applied to + any element. However, it applies to the destruction of the component as + a whole, and not the destruction of the specific object. The order of + running the \c onDestruction scripts is undefined. + + \qml + Rectangle { + Component.onDestruction: console.log("Destruction Beginning!") + Rectangle { + Component.onDestruction: console.log("Nested Destruction Beginning!") + } + } + \endqml */ /*! @@ -518,7 +538,7 @@ QScriptValue QDeclarativeComponent::createObject() if (!ret) return QScriptValue(); QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(d->engine); - QDeclarativeDeclarativeData::get(ret, true)->setImplicitDestructible(); + QDeclarativeData::get(ret, true)->setImplicitDestructible(); return priv->objectClass->newQObject(ret, QMetaType::QObjectStar); } @@ -581,7 +601,7 @@ QObject *QDeclarativeComponent::beginCreate(QDeclarativeContext *context) Q_D(QDeclarativeComponent); QObject *rv = d->beginCreate(context?QDeclarativeContextData::get(context):0, QBitField()); if (rv) { - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(rv); + QDeclarativeData *ddata = QDeclarativeData::get(rv); Q_ASSERT(ddata); ddata->indestructible = true; } @@ -657,11 +677,11 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe state->bindValues = enginePriv->bindValues; state->parserStatus = enginePriv->parserStatus; - state->componentAttacheds = enginePriv->componentAttacheds; - if (state->componentAttacheds) - state->componentAttacheds->prev = &state->componentAttacheds; + state->componentAttached = enginePriv->componentAttached; + if (state->componentAttached) + state->componentAttached->prev = &state->componentAttached; - enginePriv->componentAttacheds = 0; + enginePriv->componentAttached = 0; enginePriv->bindValues.clear(); enginePriv->parserStatus.clear(); state->completePending = true; @@ -671,7 +691,7 @@ QObject * QDeclarativeComponentPrivate::begin(QDeclarativeContextData *ctxt, QDe return rv; } -void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContextData *, QDeclarativeEnginePrivate *enginePriv, +void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeEnginePrivate *enginePriv, QObject *object, ConstructionState *state) { bool isRoot = !enginePriv->inBeginCreate; @@ -688,11 +708,11 @@ void QDeclarativeComponentPrivate::beginDeferred(QDeclarativeContextData *, QDec state->bindValues = enginePriv->bindValues; state->parserStatus = enginePriv->parserStatus; - state->componentAttacheds = enginePriv->componentAttacheds; - if (state->componentAttacheds) - state->componentAttacheds->prev = &state->componentAttacheds; + state->componentAttached = enginePriv->componentAttached; + if (state->componentAttached) + state->componentAttached->prev = &state->componentAttached; - enginePriv->componentAttacheds = 0; + enginePriv->componentAttached = 0; enginePriv->bindValues.clear(); enginePriv->parserStatus.clear(); state->completePending = true; @@ -729,11 +749,13 @@ void QDeclarativeComponentPrivate::complete(QDeclarativeEnginePrivate *enginePri QDeclarativeEnginePrivate::clear(ps); } - while (state->componentAttacheds) { - QDeclarativeComponentAttached *a = state->componentAttacheds; - if (a->next) a->next->prev = &state->componentAttacheds; - state->componentAttacheds = a->next; - a->prev = 0; a->next = 0; + while (state->componentAttached) { + QDeclarativeComponentAttached *a = state->componentAttached; + a->rem(); + QDeclarativeData *d = QDeclarativeData::get(a->parent()); + Q_ASSERT(d); + Q_ASSERT(d->context); + a->add(&d->context->componentAttached); emit a->completed(); } @@ -793,15 +815,18 @@ QDeclarativeComponentAttached *QDeclarativeComponent::qmlAttachedProperties(QObj QDeclarativeComponentAttached *a = new QDeclarativeComponentAttached(obj); QDeclarativeEngine *engine = qmlEngine(obj); - if (!engine || !QDeclarativeEnginePrivate::get(engine)->inBeginCreate) + if (!engine) return a; - QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine); - - a->next = p->componentAttacheds; - a->prev = &p->componentAttacheds; - if (a->next) a->next->prev = &a->next; - p->componentAttacheds = a; + if (QDeclarativeEnginePrivate::get(engine)->inBeginCreate) { + QDeclarativeEnginePrivate *p = QDeclarativeEnginePrivate::get(engine); + a->add(&p->componentAttached); + } else { + QDeclarativeData *d = QDeclarativeData::get(obj); + Q_ASSERT(d); + Q_ASSERT(d->context); + a->add(&d->context->componentAttached); + } return a; } diff --git a/src/declarative/qml/qdeclarativecomponent_p.h b/src/declarative/qml/qdeclarativecomponent_p.h index dfe327b..24e5386 100644 --- a/src/declarative/qml/qdeclarativecomponent_p.h +++ b/src/declarative/qml/qdeclarativecomponent_p.h @@ -99,10 +99,10 @@ public: QDeclarativeCompiledData *cc; struct ConstructionState { - ConstructionState() : componentAttacheds(0), completePending(false) {} + ConstructionState() : componentAttached(0), completePending(false) {} QList<QDeclarativeEnginePrivate::SimpleList<QDeclarativeAbstractBinding> > bindValues; QList<QDeclarativeEnginePrivate::SimpleList<QDeclarativeParserStatus> > parserStatus; - QDeclarativeComponentAttached *componentAttacheds; + QDeclarativeComponentAttached *componentAttached; QList<QDeclarativeError> errors; bool completePending; }; @@ -111,8 +111,8 @@ public: static QObject *begin(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv, QDeclarativeCompiledData *component, int start, int count, ConstructionState *state, const QBitField &bindings = QBitField()); - static void beginDeferred(QDeclarativeContextData *ctxt, QDeclarativeEnginePrivate *enginePriv, - QObject *object, ConstructionState *state); + static void beginDeferred(QDeclarativeEnginePrivate *enginePriv, QObject *object, + ConstructionState *state); static void complete(QDeclarativeEnginePrivate *enginePriv, ConstructionState *state); QDeclarativeEngine *engine; @@ -132,13 +132,24 @@ public: QDeclarativeComponentAttached(QObject *parent = 0); ~QDeclarativeComponentAttached(); + void add(QDeclarativeComponentAttached **a) { + prev = a; next = *a; *a = this; + if (next) next->prev = &next; + } + void rem() { + if (next) next->prev = prev; + *prev = next; + next = 0; prev = 0; + } QDeclarativeComponentAttached **prev; QDeclarativeComponentAttached *next; Q_SIGNALS: void completed(); + void destruction(); private: + friend class QDeclarativeContextData;; friend class QDeclarativeComponentPrivate; }; diff --git a/src/declarative/qml/qdeclarativecontext.cpp b/src/declarative/qml/qdeclarativecontext.cpp index ba4da95..6657fea 100644 --- a/src/declarative/qml/qdeclarativecontext.cpp +++ b/src/declarative/qml/qdeclarativecontext.cpp @@ -42,6 +42,7 @@ #include "qdeclarativecontext.h" #include "private/qdeclarativecontext_p.h" +#include "private/qdeclarativecomponent_p.h" #include "private/qdeclarativeexpression_p.h" #include "private/qdeclarativeengine_p.h" #include "qdeclarativeengine.h" @@ -476,21 +477,34 @@ QObject *QDeclarativeContextPrivate::context_at(QDeclarativeListProperty<QObject QDeclarativeContextData::QDeclarativeContextData() : parent(0), engine(0), isInternal(false), publicContext(0), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), - contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0) + contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0), + componentAttached(0) { } QDeclarativeContextData::QDeclarativeContextData(QDeclarativeContext *ctxt) : parent(0), engine(0), isInternal(false), publicContext(ctxt), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0), expressions(0), contextObjects(0), - contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0) + contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0), linkedContext(0), + componentAttached(0) { } -void QDeclarativeContextData::destroy() +void QDeclarativeContextData::invalidate() { - if (linkedContext) - linkedContext->destroy(); + while (childContexts) + childContexts->invalidate(); + + while (componentAttached) { + QDeclarativeComponentAttached *a = componentAttached; + componentAttached = a->next; + if (componentAttached) componentAttached->prev = &componentAttached; + + a->next = 0; + a->prev = 0; + + emit a->destruction(); + } if (prevChild) { *prevChild = nextChild; @@ -498,19 +512,17 @@ void QDeclarativeContextData::destroy() nextChild = 0; prevChild = 0; } - - QDeclarativeContextData *child = childContexts; - while (child) { - QDeclarativeContextData *next = child->nextChild; - child->invalidateEngines(); - child->parent = 0; - child->nextChild = 0; - child->prevChild = 0; + engine = 0; + parent = 0; +} - child = next; - } - childContexts = 0; +void QDeclarativeContextData::destroy() +{ + if (linkedContext) + linkedContext->destroy(); + + if (engine) invalidate(); QDeclarativeAbstractExpression *expression = expressions; while (expression) { @@ -525,7 +537,7 @@ void QDeclarativeContextData::destroy() expressions = 0; while (contextObjects) { - QDeclarativeDeclarativeData *co = contextObjects; + QDeclarativeData *co = contextObjects; contextObjects = contextObjects->nextContextObject; co->context = 0; @@ -573,19 +585,6 @@ void QDeclarativeContextData::setParent(QDeclarativeContextData *p) } } -void QDeclarativeContextData::invalidateEngines() -{ - if (!engine) - return; - engine = 0; - - QDeclarativeContextData *child = childContexts; - while (child) { - child->invalidateEngines(); - child = child->nextChild; - } -} - /* Refreshes all expressions that could possibly depend on this context. Refreshing flushes all context-tree dependent caches in the expressions, and should occur every time the context tree @@ -608,7 +607,7 @@ void QDeclarativeContextData::refreshExpressions() void QDeclarativeContextData::addObject(QObject *o) { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(o, true); + QDeclarativeData *data = QDeclarativeData::get(o, true); Q_ASSERT(data->context == 0); diff --git a/src/declarative/qml/qdeclarativecontext_p.h b/src/declarative/qml/qdeclarativecontext_p.h index 7a16179..77a6d94 100644 --- a/src/declarative/qml/qdeclarativecontext_p.h +++ b/src/declarative/qml/qdeclarativecontext_p.h @@ -55,7 +55,7 @@ #include "qdeclarativecontext.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "private/qdeclarativeintegercache_p.h" #include "private/qdeclarativetypenamecache_p.h" #include "private/qdeclarativenotifier_p.h" @@ -106,6 +106,7 @@ public: static QObject *context_at(QDeclarativeListProperty<QObject> *, int); }; +class QDeclarativeComponentAttached; class QDeclarativeGuardedContextData; class QDeclarativeContextData { @@ -113,6 +114,7 @@ public: QDeclarativeContextData(); QDeclarativeContextData(QDeclarativeContext *); void destroy(); + void invalidate(); inline bool isValid() const { return engine && (!isInternal || !contextObject || !QObjectPrivate::get(contextObject)->wasDeleted); @@ -123,7 +125,6 @@ public: QDeclarativeEngine *engine; void setParent(QDeclarativeContextData *); - void invalidateEngines(); void refreshExpressions(); void addObject(QObject *); @@ -166,7 +167,7 @@ public: QDeclarativeAbstractExpression *expressions; // Doubly-linked list of objects that are owned by this context - QDeclarativeDeclarativeData *contextObjects; + QDeclarativeData *contextObjects; // Doubly-linked list of context guards (XXX merge with contextObjects) QDeclarativeGuardedContextData *contextGuards; @@ -194,6 +195,10 @@ public: // Linked contexts. this owns linkedContext. QDeclarativeContextData *linkedContext; + // Linked list of uses of the Component attached property in this + // context + QDeclarativeComponentAttached *componentAttached; + QString findObjectId(const QObject *obj) const; static QDeclarativeContextData *get(QDeclarativeContext *context) { diff --git a/src/declarative/qml/qdeclarativedeclarativedata_p.h b/src/declarative/qml/qdeclarativedata_p.h index 5b12629..2ddd7e5 100644 --- a/src/declarative/qml/qdeclarativedeclarativedata_p.h +++ b/src/declarative/qml/qdeclarativedata_p.h @@ -39,8 +39,8 @@ ** ****************************************************************************/ -#ifndef QDECLARATIVEDECLARATIVEDATA_P_H -#define QDECLARATIVEDECLARATIVEDATA_P_H +#ifndef QDECLARATIVEDATA_P_H +#define QDECLARATIVEDATA_P_H // // W A R N I N G @@ -68,10 +68,10 @@ class QDeclarativeContextData; // default state for elemental object allocations. This is crucial in the // workings of the QDeclarativeInstruction::CreateSimpleObject instruction. // Don't change anything here without first considering that case! -class Q_AUTOTEST_EXPORT QDeclarativeDeclarativeData : public QDeclarativeData +class Q_AUTOTEST_EXPORT QDeclarativeData : public QAbstractDeclarativeData { public: - QDeclarativeDeclarativeData() + QDeclarativeData() : ownMemory(true), ownContext(false), indestructible(true), explicitIndestructibleSet(false), context(0), outerContext(0), bindings(0), nextContextObject(0), prevContextObject(0), bindingBitsSize(0), bindingBits(0), lineNumber(0), columnNumber(0), deferredComponent(0), deferredIdx(0), @@ -80,12 +80,12 @@ public: } static inline void init() { - QDeclarativeData::destroyed = destroyed; - QDeclarativeData::parentChanged = parentChanged; + QAbstractDeclarativeData::destroyed = destroyed; + QAbstractDeclarativeData::parentChanged = parentChanged; } - static void destroyed(QDeclarativeData *, QObject *); - static void parentChanged(QDeclarativeData *, QObject *, QObject *); + static void destroyed(QAbstractDeclarativeData *, QObject *); + static void parentChanged(QAbstractDeclarativeData *, QObject *, QObject *); void destroyed(QObject *); void parentChanged(QObject *, QObject *); @@ -100,14 +100,16 @@ public: quint32 explicitIndestructibleSet:1; quint32 dummy:28; - QDeclarativeContextData *context; + // The context that created the C++ object + QDeclarativeContextData *context; + // The outermost context in which this object lives QDeclarativeContextData *outerContext; QDeclarativeAbstractBinding *bindings; // Linked list for QDeclarativeContext::contextObjects - QDeclarativeDeclarativeData *nextContextObject; - QDeclarativeDeclarativeData**prevContextObject; + QDeclarativeData *nextContextObject; + QDeclarativeData**prevContextObject; int bindingBitsSize; quint32 *bindingBits; @@ -130,16 +132,16 @@ public: QDeclarativeGuard<QObject> *guards; - static QDeclarativeDeclarativeData *get(const QObject *object, bool create = false) { + static QDeclarativeData *get(const QObject *object, bool create = false) { QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object)); if (priv->wasDeleted) { Q_ASSERT(!create); return 0; } else if (priv->declarativeData) { - return static_cast<QDeclarativeDeclarativeData *>(priv->declarativeData); + return static_cast<QDeclarativeData *>(priv->declarativeData); } else if (create) { - priv->declarativeData = new QDeclarativeDeclarativeData; - return static_cast<QDeclarativeDeclarativeData *>(priv->declarativeData); + priv->declarativeData = new QDeclarativeData; + return static_cast<QDeclarativeData *>(priv->declarativeData); } else { return 0; } @@ -154,7 +156,7 @@ void QDeclarativeGuard<T>::addGuard() return; } - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(o, true); + QDeclarativeData *data = QDeclarativeData::get(o, true); next = data->guards; if (next) reinterpret_cast<QDeclarativeGuard<T> *>(next)->prev = &next; data->guards = reinterpret_cast<QDeclarativeGuard<QObject> *>(this); @@ -172,4 +174,4 @@ void QDeclarativeGuard<T>::remGuard() QT_END_NAMESPACE -#endif // QDECLARATIVEDECLARATIVEDATA_P_H +#endif // QDECLARATIVEDATA_P_H diff --git a/src/declarative/qml/qdeclarativeengine.cpp b/src/declarative/qml/qdeclarativeengine.cpp index c5afe92..96145fb 100644 --- a/src/declarative/qml/qdeclarativeengine.cpp +++ b/src/declarative/qml/qdeclarativeengine.cpp @@ -155,7 +155,7 @@ QDeclarativeEnginePrivate::QDeclarativeEnginePrivate(QDeclarativeEngine *e) : captureProperties(false), rootContext(0), currentExpression(0), isDebugging(false), contextClass(0), sharedContext(0), sharedScope(0), objectClass(0), valueTypeClass(0), globalClass(0), cleanup(0), erroredBindings(0), inProgressCreations(0), - scriptEngine(this), workerScriptEngine(0), componentAttacheds(0), inBeginCreate(false), + scriptEngine(this), workerScriptEngine(0), componentAttached(0), inBeginCreate(false), networkAccessManager(0), networkAccessManagerFactory(0), typeManager(e), uniqueId(1) { @@ -350,14 +350,23 @@ typedef QMap<QString, QString> StringStringMap; Q_GLOBAL_STATIC(StringStringMap, qmlEnginePluginsWithRegisteredTypes); // stores the uri -void QDeclarativeDeclarativeData::destroyed(QDeclarativeData *d, QObject *o) +void QDeclarativePrivate::qdeclarativeelement_destructor(QObject *o) { - static_cast<QDeclarativeDeclarativeData *>(d)->destroyed(o); + QObjectPrivate *p = QObjectPrivate::get(o); + Q_ASSERT(p->declarativeData); + QDeclarativeData *d = static_cast<QDeclarativeData*>(p->declarativeData); + if (d->ownContext) + d->context->destroy(); } -void QDeclarativeDeclarativeData::parentChanged(QDeclarativeData *d, QObject *o, QObject *p) +void QDeclarativeData::destroyed(QAbstractDeclarativeData *d, QObject *o) { - static_cast<QDeclarativeDeclarativeData *>(d)->parentChanged(o, p); + static_cast<QDeclarativeData *>(d)->destroyed(o); +} + +void QDeclarativeData::parentChanged(QAbstractDeclarativeData *d, QObject *o, QObject *p) +{ + static_cast<QDeclarativeData *>(d)->parentChanged(o, p); } void QDeclarativeEnginePrivate::init() @@ -367,7 +376,7 @@ void QDeclarativeEnginePrivate::init() qRegisterMetaType<QDeclarativeScriptString>("QDeclarativeScriptString"); qRegisterMetaType<QScriptValue>("QScriptValue"); - QDeclarativeDeclarativeData::init(); + QDeclarativeData::init(); contextClass = new QDeclarativeContextScriptClass(q); objectClass = new QDeclarativeObjectScriptClass(q); @@ -659,8 +668,8 @@ QDeclarativeContext *QDeclarativeEngine::contextForObject(const QObject *object) QObjectPrivate *priv = QObjectPrivate::get(const_cast<QObject *>(object)); - QDeclarativeDeclarativeData *data = - static_cast<QDeclarativeDeclarativeData *>(priv->declarativeData); + QDeclarativeData *data = + static_cast<QDeclarativeData *>(priv->declarativeData); if (!data) return 0; @@ -683,7 +692,7 @@ void QDeclarativeEngine::setContextForObject(QObject *object, QDeclarativeContex if (!object || !context) return; - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, true); + QDeclarativeData *data = QDeclarativeData::get(object, true); if (data->context) { qWarning("QDeclarativeEngine::setContextForObject(): Object already has a QDeclarativeContext"); return; @@ -734,7 +743,7 @@ void QDeclarativeEngine::setContextForObject(QObject *object, QDeclarativeContex */ void QDeclarativeEngine::setObjectOwnership(QObject *object, ObjectOwnership ownership) { - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, true); + QDeclarativeData *ddata = QDeclarativeData::get(object, true); if (!ddata) return; @@ -747,7 +756,7 @@ void QDeclarativeEngine::setObjectOwnership(QObject *object, ObjectOwnership own */ QDeclarativeEngine::ObjectOwnership QDeclarativeEngine::objectOwnership(QObject *object) { - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, false); + QDeclarativeData *ddata = QDeclarativeData::get(object, false); if (!ddata) return CppOwnership; else @@ -756,14 +765,14 @@ QDeclarativeEngine::ObjectOwnership QDeclarativeEngine::objectOwnership(QObject void qmlExecuteDeferred(QObject *object) { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object); + QDeclarativeData *data = QDeclarativeData::get(object); if (data && data->deferredComponent) { QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(data->context->engine); QDeclarativeComponentPrivate::ConstructionState state; - QDeclarativeComponentPrivate::beginDeferred(data->context, ep, object, &state); + QDeclarativeComponentPrivate::beginDeferred(ep, object, &state); data->deferredComponent->release(); data->deferredComponent = 0; @@ -789,7 +798,7 @@ QDeclarativeEngine *qmlEngine(const QObject *obj) QObject *qmlAttachedPropertiesObjectById(int id, const QObject *object, bool create) { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object); + QDeclarativeData *data = QDeclarativeData::get(object); if (!data) return 0; // Attached properties are only on objects created by QML @@ -824,7 +833,7 @@ QObject *qmlAttachedPropertiesObject(int *idCache, const QObject *object, return qmlAttachedPropertiesObjectById(*idCache, object, create); } -void QDeclarativeDeclarativeData::destroyed(QObject *object) +void QDeclarativeData::destroyed(QObject *object) { if (deferredComponent) deferredComponent->release(); @@ -851,7 +860,7 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) if (propertyCache) propertyCache->release(); - if (ownContext) + if (ownContext && context) context->destroy(); QDeclarativeGuard<QObject> *guard = guards; @@ -871,12 +880,12 @@ void QDeclarativeDeclarativeData::destroyed(QObject *object) delete this; } -void QDeclarativeDeclarativeData::parentChanged(QObject *, QObject *parent) +void QDeclarativeData::parentChanged(QObject *, QObject *parent) { if (!parent && scriptValue) { delete scriptValue; scriptValue = 0; } } -bool QDeclarativeDeclarativeData::hasBindingBit(int bit) const +bool QDeclarativeData::hasBindingBit(int bit) const { if (bindingBitsSize > bit) return bindingBits[bit / 32] & (1 << (bit % 32)); @@ -884,13 +893,13 @@ bool QDeclarativeDeclarativeData::hasBindingBit(int bit) const return false; } -void QDeclarativeDeclarativeData::clearBindingBit(int bit) +void QDeclarativeData::clearBindingBit(int bit) { if (bindingBitsSize > bit) bindingBits[bit / 32] &= ~(1 << (bit % 32)); } -void QDeclarativeDeclarativeData::setBindingBit(QObject *obj, int bit) +void QDeclarativeData::setBindingBit(QObject *obj, int bit) { if (bindingBitsSize <= bit) { int props = obj->metaObject()->propertyCount(); @@ -956,7 +965,7 @@ QScriptValue QDeclarativeEnginePrivate::createComponent(QScriptContext *ctxt, QS QUrl url = QUrl(context->resolvedUrl(QUrl(arg))); QDeclarativeComponent *c = new QDeclarativeComponent(activeEngine, url, activeEngine); QDeclarativeComponentPrivate::get(c)->creationContext = context; - QDeclarativeDeclarativeData::get(c, true)->setImplicitDestructible(); + QDeclarativeData::get(c, true)->setImplicitDestructible(); return activeEnginePriv->objectClass->newQObject(c, qMetaTypeId<QDeclarativeComponent*>()); } } @@ -1027,7 +1036,7 @@ QScriptValue QDeclarativeEnginePrivate::createQmlObject(QScriptContext *ctxt, QS if(gobj && gparent) gobj->setParentItem(gparent); - QDeclarativeDeclarativeData::get(obj, true)->setImplicitDestructible(); + QDeclarativeData::get(obj, true)->setImplicitDestructible(); return activeEnginePriv->objectClass->newQObject(obj, QMetaType::QObjectStar); } @@ -1356,7 +1365,9 @@ QScriptValue QDeclarativeEnginePrivate::scriptValueFromVariant(const QVariant &v rv.setProperty(ii, objectClass->newQObject(object)); } return rv; - } + } else if (QDeclarativeValueType *vt = valueTypes[val.userType()]) { + return valueTypeClass->newObject(val, vt); + } bool objOk; QObject *obj = QDeclarativeMetaType::toQObject(val, &objOk); diff --git a/src/declarative/qml/qdeclarativeengine_p.h b/src/declarative/qml/qdeclarativeengine_p.h index 7766ad6..b3bba43 100644 --- a/src/declarative/qml/qdeclarativeengine_p.h +++ b/src/declarative/qml/qdeclarativeengine_p.h @@ -215,7 +215,7 @@ public: QList<SimpleList<QDeclarativeAbstractBinding> > bindValues; QList<SimpleList<QDeclarativeParserStatus> > parserStatus; - QDeclarativeComponentAttached *componentAttacheds; + QDeclarativeComponentAttached *componentAttached; bool inBeginCreate; diff --git a/src/declarative/qml/qdeclarativeenginedebug.cpp b/src/declarative/qml/qdeclarativeenginedebug.cpp index 3455883..578733c 100644 --- a/src/declarative/qml/qdeclarativeenginedebug.cpp +++ b/src/declarative/qml/qdeclarativeenginedebug.cpp @@ -264,7 +264,7 @@ void QDeclarativeEngineDebugServer::buildObjectList(QDataStream &message, QDecla QDeclarativeEngineDebugServer::QDeclarativeObjectData QDeclarativeEngineDebugServer::objectData(QObject *object) { - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object); + QDeclarativeData *ddata = QDeclarativeData::get(object); QDeclarativeObjectData rv; if (ddata && ddata->outerContext) { rv.url = ddata->outerContext->url; diff --git a/src/declarative/qml/qdeclarativeguard_p.h b/src/declarative/qml/qdeclarativeguard_p.h index 747d58f..be60ce4 100644 --- a/src/declarative/qml/qdeclarativeguard_p.h +++ b/src/declarative/qml/qdeclarativeguard_p.h @@ -65,7 +65,7 @@ class QDeclarativeGuard QObject *o; QDeclarativeGuard<QObject> *next; QDeclarativeGuard<QObject> **prev; - friend class QDeclarativeDeclarativeData; + friend class QDeclarativeData; public: inline QDeclarativeGuard(); inline QDeclarativeGuard(T *); @@ -99,7 +99,7 @@ QT_END_NAMESPACE Q_DECLARE_METATYPE(QDeclarativeGuard<QObject>); -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeinfo.cpp b/src/declarative/qml/qdeclarativeinfo.cpp index 6199aa9..0a4352f 100644 --- a/src/declarative/qml/qdeclarativeinfo.cpp +++ b/src/declarative/qml/qdeclarativeinfo.cpp @@ -41,7 +41,7 @@ #include "qdeclarativeinfo.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "qdeclarativecontext.h" #include "private/qdeclarativecontext_p.h" #include "private/qdeclarativemetatype_p.h" @@ -100,7 +100,7 @@ QDeclarativeInfo::QDeclarativeInfo(const QObject *object) pos += typeName; } - QDeclarativeDeclarativeData *ddata = object?QDeclarativeDeclarativeData::get(object):0; + QDeclarativeData *ddata = object?QDeclarativeData::get(object):0; pos += QLatin1String(" ("); if (ddata) { if (ddata->outerContext && !ddata->outerContext->url.isEmpty()) { diff --git a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp index e1e33ab..5773fe6 100644 --- a/src/declarative/qml/qdeclarativeobjectscriptclass.cpp +++ b/src/declarative/qml/qdeclarativeobjectscriptclass.cpp @@ -43,7 +43,7 @@ #include "private/qdeclarativeengine_p.h" #include "private/qdeclarativecontext_p.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "private/qdeclarativetypenamescriptclass_p.h" #include "private/qdeclarativelistscriptclass_p.h" #include "private/qdeclarativebinding_p.h" @@ -63,7 +63,7 @@ struct ObjectData : public QScriptDeclarativeClass::Object { virtual ~ObjectData() { if (object && !object->parent()) { - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, false); + QDeclarativeData *ddata = QDeclarativeData::get(object, false); if (ddata && !ddata->indestructible) object->deleteLater(); } @@ -104,7 +104,7 @@ QScriptValue QDeclarativeObjectScriptClass::newQObject(QObject *object, int type if (QObjectPrivate::get(object)->wasDeleted) return scriptEngine->undefinedValue(); - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(object, true); + QDeclarativeData *ddata = QDeclarativeData::get(object, true); if (!ddata) { return scriptEngine->undefinedValue(); @@ -428,7 +428,7 @@ QScriptValue QDeclarativeObjectScriptClass::destroy(QScriptContext *context, QSc if (!data->object) return engine->undefinedValue(); - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(data->object, false); + QDeclarativeData *ddata = QDeclarativeData::get(data->object, false); if (!ddata || ddata->indestructible) return engine->currentContext()->throwError(QLatin1String("Invalid attempt to destroy() an indestructible object")); @@ -453,7 +453,7 @@ QStringList QDeclarativeObjectScriptClass::propertyNames(Object *object) QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine); QDeclarativePropertyCache *cache = 0; - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(obj); + QDeclarativeData *ddata = QDeclarativeData::get(obj); if (ddata) cache = ddata->propertyCache; if (!cache) { @@ -752,7 +752,7 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) return QScriptDeclarativeClass::Value(engine, *((QString *)&data)); } else if (type == QMetaType::QObjectStar) { QObject *object = *((QObject **)&data); - QDeclarativeDeclarativeData::get(object, true)->setImplicitDestructible(); + QDeclarativeData::get(object, true)->setImplicitDestructible(); QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e); return QScriptDeclarativeClass::Value(engine, priv->objectClass->newQObject(object)); } else if (type == qMetaTypeId<QList<QObject *> >()) { @@ -761,7 +761,7 @@ QScriptDeclarativeClass::Value MetaCallArgument::toValue(QDeclarativeEngine *e) QDeclarativeEnginePrivate *priv = QDeclarativeEnginePrivate::get(e); for (int ii = 0; ii < list.count(); ++ii) { QObject *object = list.at(ii); - QDeclarativeDeclarativeData::get(object, true)->setImplicitDestructible(); + QDeclarativeData::get(object, true)->setImplicitDestructible(); rv.setProperty(ii, priv->objectClass->newQObject(object)); } return QScriptDeclarativeClass::Value(engine, rv); diff --git a/src/declarative/qml/qdeclarativeprivate.h b/src/declarative/qml/qdeclarativeprivate.h index bebe82c..6e240d8 100644 --- a/src/declarative/qml/qdeclarativeprivate.h +++ b/src/declarative/qml/qdeclarativeprivate.h @@ -69,11 +69,18 @@ public: class QDeclarativeCustomParser; namespace QDeclarativePrivate { + void Q_DECLARATIVE_EXPORT qdeclarativeelement_destructor(QObject *); template<typename T> - QObject *create() { return new T; } + class QDeclarativeElement : public T + { + public: + virtual ~QDeclarativeElement() { + QDeclarativePrivate::qdeclarativeelement_destructor(this); + } + }; template<typename T> - void createInto(void *memory) { new (memory) T; } + void createInto(void *memory) { new (memory) QDeclarativeElement<T>; } template<typename T> QObject *createParent(QObject *p) { return new T(p); } diff --git a/src/declarative/qml/qdeclarativeproperty.cpp b/src/declarative/qml/qdeclarativeproperty.cpp index affb6b9..afd0d84 100644 --- a/src/declarative/qml/qdeclarativeproperty.cpp +++ b/src/declarative/qml/qdeclarativeproperty.cpp @@ -50,7 +50,7 @@ #include "private/qdeclarativeboundsignal_p.h" #include "qdeclarativeengine.h" #include "private/qdeclarativeengine_p.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "private/qdeclarativestringconverters_p.h" #include "private/qdeclarativelist_p.h" #include "private/qdeclarativecompiler_p.h" @@ -286,7 +286,7 @@ void QDeclarativePropertyPrivate::initProperty(QObject *obj, const QString &name QString signalName = terminal.mid(2); signalName[0] = signalName.at(0).toLower(); - QMetaMethod method = QDeclarativeCompiler::findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData()); + QMetaMethod method = findSignalByName(currentObject->metaObject(), signalName.toLatin1().constData()); if (method.signature()) { object = currentObject; core.load(method); @@ -606,7 +606,7 @@ QDeclarativePropertyPrivate::binding(const QDeclarativeProperty &that) if (!that.isProperty() || !that.d->object) return 0; - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(that.d->object); + QDeclarativeData *data = QDeclarativeData::get(that.d->object); if (!data) return 0; @@ -660,7 +660,7 @@ QDeclarativeAbstractBinding * QDeclarativePropertyPrivate::setBinding(QObject *object, int coreIndex, int valueTypeIndex, QDeclarativeAbstractBinding *newBinding, WriteFlags flags) { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object, 0 != newBinding); + QDeclarativeData *data = QDeclarativeData::get(object, 0 != newBinding); QDeclarativeAbstractBinding *binding = 0; if (data && data->hasBindingBit(coreIndex)) { @@ -1353,4 +1353,36 @@ bool QDeclarativePropertyPrivate::canConvert(const QMetaObject *from, const QMet return false; } +/*! + Return the signal corresponding to \a name +*/ +QMetaMethod QDeclarativePropertyPrivate::findSignalByName(const QMetaObject *mo, const QByteArray &name) +{ + Q_ASSERT(mo); + int methods = mo->methodCount(); + for (int ii = methods - 1; ii >= 2; --ii) { // >= 2 to block the destroyed signal + QMetaMethod method = mo->method(ii); + QByteArray methodName = method.signature(); + int idx = methodName.indexOf('('); + methodName = methodName.left(idx); + + if (methodName == name) + return method; + } + + // If no signal is found, but the signal is of the form "onBlahChanged", + // return the notify signal for the property "Blah" + if (name.endsWith("Changed")) { + QByteArray propName = name.mid(0, name.length() - 7); + int propIdx = mo->indexOfProperty(propName.constData()); + if (propIdx >= 0) { + QMetaProperty prop = mo->property(propIdx); + if (prop.hasNotifySignal()) + return prop.notifySignal(); + } + } + + return QMetaMethod(); +} + QT_END_NAMESPACE diff --git a/src/declarative/qml/qdeclarativeproperty_p.h b/src/declarative/qml/qdeclarativeproperty_p.h index 420a1ba..8522561 100644 --- a/src/declarative/qml/qdeclarativeproperty_p.h +++ b/src/declarative/qml/qdeclarativeproperty_p.h @@ -96,8 +96,6 @@ public: void initProperty(QObject *obj, const QString &name); void initDefault(QObject *obj); - QMetaMethod findSignal(QObject *, const QString &); - bool isValueType() const; int propertyType() const; QDeclarativeProperty::PropertyTypeCategory propertyTypeCategory() const; @@ -134,6 +132,7 @@ public: static bool write(const QDeclarativeProperty &that, const QVariant &, WriteFlags); static int valueTypeCoreIndex(const QDeclarativeProperty &that); static int bindingIndex(const QDeclarativeProperty &that); + static QMetaMethod findSignalByName(const QMetaObject *mo, const QByteArray &); }; Q_DECLARE_OPERATORS_FOR_FLAGS(QDeclarativePropertyPrivate::WriteFlags) diff --git a/src/declarative/qml/qdeclarativepropertycache.cpp b/src/declarative/qml/qdeclarativepropertycache.cpp index 111259d..888945b 100644 --- a/src/declarative/qml/qdeclarativepropertycache.cpp +++ b/src/declarative/qml/qdeclarativepropertycache.cpp @@ -147,7 +147,7 @@ QDeclarativePropertyCache::Data QDeclarativePropertyCache::create(const QMetaObj } int methodCount = metaObject->methodCount(); - for (int ii = methodCount - 1; ii >= 0; --ii) { + for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) continue; @@ -216,7 +216,7 @@ void QDeclarativePropertyCache::append(QDeclarativeEngine *engine, const QMetaOb } int methodCount = metaObject->methodCount(); - int methodOffset = metaObject->methodOffset(); + int methodOffset = qMax(2, metaObject->methodOffset()); // 2 to block the destroyed signal for (int ii = methodOffset; ii < methodCount; ++ii) { QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) @@ -289,7 +289,7 @@ void QDeclarativePropertyCache::update(QDeclarativeEngine *engine, const QMetaOb } int methodCount = metaObject->methodCount(); - for (int ii = methodCount - 1; ii >= 0; --ii) { + for (int ii = methodCount - 1; ii >= 2; --ii) { // >=2 to block the destroyed signal QMetaMethod m = metaObject->method(ii); if (m.access() == QMetaMethod::Private) continue; @@ -368,7 +368,7 @@ QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativ QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine); QDeclarativePropertyCache *cache = 0; - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(obj); + QDeclarativeData *ddata = QDeclarativeData::get(obj); if (ddata && ddata->propertyCache && ddata->propertyCache->qmlEngine() == engine) cache = ddata->propertyCache; if (!cache) { @@ -400,7 +400,7 @@ QDeclarativePropertyCache::Data *QDeclarativePropertyCache::property(QDeclarativ QDeclarativeEnginePrivate *enginePrivate = QDeclarativeEnginePrivate::get(engine); QDeclarativePropertyCache *cache = 0; - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(obj); + QDeclarativeData *ddata = QDeclarativeData::get(obj); if (ddata && ddata->propertyCache && ddata->propertyCache->qmlEngine() == engine) cache = ddata->propertyCache; if (!cache) { diff --git a/src/declarative/qml/qdeclarativevaluetype.cpp b/src/declarative/qml/qdeclarativevaluetype.cpp index 261c84a..352a6c0 100644 --- a/src/declarative/qml/qdeclarativevaluetype.cpp +++ b/src/declarative/qml/qdeclarativevaluetype.cpp @@ -99,12 +99,6 @@ void QDeclarativeValueTypeFactory::registerValueTypes() qmlRegisterValueTypeEnums<QDeclarativeFontValueType>("Font"); } -QDeclarativeValueType *QDeclarativeValueTypeFactory::operator[](int idx) const -{ - return valueTypes[idx]; -} - - QDeclarativeValueType *QDeclarativeValueTypeFactory::valueType(int t) { switch (t) { diff --git a/src/declarative/qml/qdeclarativevaluetype_p.h b/src/declarative/qml/qdeclarativevaluetype_p.h index 5bfc27d..d1833bb 100644 --- a/src/declarative/qml/qdeclarativevaluetype_p.h +++ b/src/declarative/qml/qdeclarativevaluetype_p.h @@ -86,7 +86,10 @@ public: static void registerValueTypes(); - QDeclarativeValueType *operator[](int idx) const; + QDeclarativeValueType *operator[](int idx) const { + if (idx >= (int)QVariant::UserType) return 0; + else return valueTypes[idx]; + } private: QDeclarativeValueType *valueTypes[QVariant::UserType - 1]; diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp index fdb71c6..cb1f27d 100644 --- a/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp +++ b/src/declarative/qml/qdeclarativevaluetypescriptclass.cpp @@ -48,12 +48,24 @@ QT_BEGIN_NAMESPACE -struct QDeclarativeValueTypeReference : public QScriptDeclarativeClass::Object { +struct QDeclarativeValueTypeObject : public QScriptDeclarativeClass::Object { + enum Type { Reference, Copy }; + QDeclarativeValueTypeObject(Type t) : objectType(t) {} + Type objectType; QDeclarativeValueType *type; +}; + +struct QDeclarativeValueTypeReference : public QDeclarativeValueTypeObject { + QDeclarativeValueTypeReference() : QDeclarativeValueTypeObject(Reference) {} QDeclarativeGuard<QObject> object; int property; }; +struct QDeclarativeValueTypeCopy : public QDeclarativeValueTypeObject { + QDeclarativeValueTypeCopy() : QDeclarativeValueTypeObject(Copy) {} + QVariant value; +}; + QDeclarativeValueTypeScriptClass::QDeclarativeValueTypeScriptClass(QDeclarativeEngine *bindEngine) : QScriptDeclarativeClass(QDeclarativeEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine) { @@ -73,40 +85,67 @@ QScriptValue QDeclarativeValueTypeScriptClass::newObject(QObject *object, int co return QScriptDeclarativeClass::newObject(scriptEngine, this, ref); } +QScriptValue QDeclarativeValueTypeScriptClass::newObject(const QVariant &v, QDeclarativeValueType *type) +{ + QDeclarativeValueTypeCopy *copy = new QDeclarativeValueTypeCopy; + copy->type = type; + copy->value = v; + QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); + return QScriptDeclarativeClass::newObject(scriptEngine, this, copy); +} + QScriptClass::QueryFlags QDeclarativeValueTypeScriptClass::queryProperty(Object *obj, const Identifier &name, - QScriptClass::QueryFlags) + QScriptClass::QueryFlags) { - QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj); m_lastIndex = -1; - if (!ref->object) - return 0; - QByteArray propName = toString(name).toUtf8(); - m_lastIndex = ref->type->metaObject()->indexOfProperty(propName.constData()); + m_lastIndex = o->type->metaObject()->indexOfProperty(propName.constData()); if (m_lastIndex == -1) return 0; - QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex); + QScriptClass::QueryFlags rv = 0; + + if (o->objectType == QDeclarativeValueTypeObject::Reference) { + QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(o); + + if (!ref->object) + return 0; - QScriptClass::QueryFlags rv = - QScriptClass::HandlesReadAccess; - if (prop.isWritable()) - rv |= QScriptClass::HandlesWriteAccess; + QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex); + + rv = QScriptClass::HandlesReadAccess; + if (prop.isWritable()) + rv |= QScriptClass::HandlesWriteAccess; + } else { + rv = QScriptClass::HandlesReadAccess | QScriptClass::HandlesWriteAccess; + } return rv; } QDeclarativeValueTypeScriptClass::Value QDeclarativeValueTypeScriptClass::property(Object *obj, const Identifier &) { - QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj); - QMetaProperty p = ref->type->metaObject()->property(m_lastIndex); - ref->type->read(ref->object, ref->property); - QVariant rv = p.read(ref->type); + QVariant rv; + if (o->objectType == QDeclarativeValueTypeObject::Reference) { + QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + + QMetaProperty p = ref->type->metaObject()->property(m_lastIndex); + ref->type->read(ref->object, ref->property); + rv = p.read(ref->type); + } else { + QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj); + + QMetaProperty p = copy->type->metaObject()->property(m_lastIndex); + copy->type->setValue(copy->value); + rv = p.read(copy->type); + } QScriptEngine *scriptEngine = QDeclarativeEnginePrivate::getScriptEngine(engine); return Value(scriptEngine, static_cast<QDeclarativeEnginePrivate *>(QObjectPrivate::get(engine))->scriptValueFromVariant(rv)); @@ -115,33 +154,53 @@ QDeclarativeValueTypeScriptClass::Value QDeclarativeValueTypeScriptClass::proper void QDeclarativeValueTypeScriptClass::setProperty(Object *obj, const Identifier &, const QScriptValue &value) { - QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); - - QDeclarativeAbstractBinding *delBinding = - QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, 0); - if (delBinding) - delBinding->destroy(); + QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj); QVariant v = QDeclarativeEnginePrivate::get(engine)->scriptValueToVariant(value); - ref->type->read(ref->object, ref->property); - QMetaProperty p = ref->type->metaObject()->property(m_lastIndex); - p.write(ref->type, v); - ref->type->write(ref->object, ref->property, 0); + if (o->objectType == QDeclarativeValueTypeObject::Reference) { + QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + + QDeclarativeAbstractBinding *delBinding = + QDeclarativePropertyPrivate::setBinding(ref->object, ref->property, m_lastIndex, 0); + if (delBinding) + delBinding->destroy(); + + ref->type->read(ref->object, ref->property); + QMetaProperty p = ref->type->metaObject()->property(m_lastIndex); + p.write(ref->type, v); + ref->type->write(ref->object, ref->property, 0); + } else { + QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj); + copy->type->setValue(copy->value); + QMetaProperty p = copy->type->metaObject()->property(m_lastIndex); + p.write(copy->type, v); + copy->value = copy->type->value(); + } } QVariant QDeclarativeValueTypeScriptClass::toVariant(Object *obj, bool *ok) { - QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); + QDeclarativeValueTypeObject *o = static_cast<QDeclarativeValueTypeObject *>(obj); - if (ok) *ok = true; + if (o->objectType == QDeclarativeValueTypeObject::Reference) { + QDeclarativeValueTypeReference *ref = static_cast<QDeclarativeValueTypeReference *>(obj); - if (ref->object) { - ref->type->read(ref->object, ref->property); - return ref->type->value(); + if (ok) *ok = true; + + if (ref->object) { + ref->type->read(ref->object, ref->property); + return ref->type->value(); + } } else { - return QVariant(); + QDeclarativeValueTypeCopy *copy = static_cast<QDeclarativeValueTypeCopy *>(obj); + + if (ok) *ok = true; + + return copy->value; } + + return QVariant(); } QVariant QDeclarativeValueTypeScriptClass::toVariant(const QScriptValue &value) diff --git a/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h b/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h index 2bbb61f..9dafa99 100644 --- a/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h +++ b/src/declarative/qml/qdeclarativevaluetypescriptclass_p.h @@ -67,6 +67,7 @@ public: ~QDeclarativeValueTypeScriptClass(); QScriptValue newObject(QObject *object, int coreIndex, QDeclarativeValueType *); + QScriptValue newObject(const QVariant &, QDeclarativeValueType *); virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); diff --git a/src/declarative/qml/qdeclarativevme.cpp b/src/declarative/qml/qdeclarativevme.cpp index 3575c17..fdcbeee 100644 --- a/src/declarative/qml/qdeclarativevme.cpp +++ b/src/declarative/qml/qdeclarativevme.cpp @@ -45,7 +45,7 @@ #include "private/qdeclarativeboundsignal_p.h" #include "private/qdeclarativestringconverters_p.h" #include "private/qmetaobjectbuilder_p.h" -#include "private/qdeclarativedeclarativedata_p.h" +#include "private/qdeclarativedata_p.h" #include "qdeclarative.h" #include "private/qdeclarativecustomparser_p.h" #include "qdeclarativeengine.h" @@ -112,7 +112,7 @@ QObject *QDeclarativeVME::run(QDeclarativeContextData *ctxt, QDeclarativeCompile void QDeclarativeVME::runDeferred(QObject *object) { - QDeclarativeDeclarativeData *data = QDeclarativeDeclarativeData::get(object); + QDeclarativeData *data = QDeclarativeData::get(object); if (!data || !data->context || !data->deferredComponent) return; @@ -194,7 +194,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, VME_EXCEPTION(QCoreApplication::translate("QDeclarativeVME","Unable to create object of type %1").arg(QString::fromLatin1(types.at(instr.create.type).className))); } - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(o); + QDeclarativeData *ddata = QDeclarativeData::get(o); Q_ASSERT(ddata); if (stack.isEmpty()) { @@ -245,12 +245,12 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, case QDeclarativeInstruction::CreateSimpleObject: { QObject *o = (QObject *)operator new(instr.createSimple.typeSize + - sizeof(QDeclarativeDeclarativeData)); - ::memset(o, 0, instr.createSimple.typeSize + sizeof(QDeclarativeDeclarativeData)); + sizeof(QDeclarativeData)); + ::memset(o, 0, instr.createSimple.typeSize + sizeof(QDeclarativeData)); instr.createSimple.create(o); - QDeclarativeDeclarativeData *ddata = - (QDeclarativeDeclarativeData *)(((const char *)o) + instr.createSimple.typeSize); + QDeclarativeData *ddata = + (QDeclarativeData *)(((const char *)o) + instr.createSimple.typeSize); ddata->lineNumber = instr.line; ddata->columnNumber = instr.createSimple.column; @@ -289,7 +289,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, new QDeclarativeComponent(ctxt->engine, comp, ii + 1, instr.createComponent.count, stack.isEmpty() ? 0 : stack.top()); - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(qcomp, true); + QDeclarativeData *ddata = QDeclarativeData::get(qcomp, true); Q_ASSERT(ddata); ctxt->addObject(qcomp); @@ -322,7 +322,7 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, (void)new QDeclarativeVMEMetaObject(target, &mo, data, comp); - QDeclarativeDeclarativeData *ddata = QDeclarativeDeclarativeData::get(target, true); + QDeclarativeData *ddata = QDeclarativeData::get(target, true); if (ddata->propertyCache) ddata->propertyCache->release(); ddata->propertyCache = propertyCaches.at(instr.storeMeta.propertyCache); ddata->propertyCache->addref(); @@ -854,8 +854,8 @@ QObject *QDeclarativeVME::run(QDeclarativeVMEStack<QObject *> &stack, { if (instr.defer.deferCount) { QObject *target = stack.top(); - QDeclarativeDeclarativeData *data = - QDeclarativeDeclarativeData::get(target, true); + QDeclarativeData *data = + QDeclarativeData::get(target, true); comp->addref(); data->deferredComponent = comp; data->deferredIdx = ii; @@ -935,8 +935,8 @@ QDeclarativeCompiledData::TypeReference::createInstance(QDeclarativeContextData QObject *rv = 0; void *memory = 0; - type->create(&rv, &memory, sizeof(QDeclarativeDeclarativeData)); - QDeclarativeDeclarativeData *ddata = new (memory) QDeclarativeDeclarativeData; + type->create(&rv, &memory, sizeof(QDeclarativeData)); + QDeclarativeData *ddata = new (memory) QDeclarativeData; ddata->ownMemory = false; QObjectPrivate::get(rv)->declarativeData = ddata; diff --git a/src/declarative/qml/qdeclarativevmemetaobject.cpp b/src/declarative/qml/qdeclarativevmemetaobject.cpp index 2e2a8e8..c4d47b3 100644 --- a/src/declarative/qml/qdeclarativevmemetaobject.cpp +++ b/src/declarative/qml/qdeclarativevmemetaobject.cpp @@ -379,7 +379,7 @@ QDeclarativeVMEMetaObject::QDeclarativeVMEMetaObject(QObject *obj, const QMetaObject *other, const QDeclarativeVMEMetaData *meta, QDeclarativeCompiledData *cdata) -: object(obj), compiledData(cdata), ctxt(QDeclarativeDeclarativeData::get(obj)->outerContext), +: object(obj), compiledData(cdata), ctxt(QDeclarativeData::get(obj)->outerContext), metaData(meta), data(0), methods(0), parent(0) { compiledData->addref(); diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri index 1087f44..c48662c 100644 --- a/src/declarative/qml/qml.pri +++ b/src/declarative/qml/qml.pri @@ -94,7 +94,7 @@ HEADERS += \ $$PWD/qdeclarativecompositetypemanager_p.h \ $$PWD/qdeclarativelist.h \ $$PWD/qdeclarativelist_p.h \ - $$PWD/qdeclarativedeclarativedata_p.h \ + $$PWD/qdeclarativedata_p.h \ $$PWD/qdeclarativeerror.h \ $$PWD/qdeclarativescriptparser_p.h \ $$PWD/qdeclarativeenginedebug_p.h \ |