diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-02 08:02:14 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2009-10-05 02:40:48 (GMT) |
commit | 5b37c01aa721057ad0cbef16a79cf179e3c53934 (patch) | |
tree | bc09b0ffc8cfec17260b449634560082905be62d | |
parent | a712a6243be29dbfa49c3d1705c8b1babd8c7a1a (diff) | |
download | Qt-5b37c01aa721057ad0cbef16a79cf179e3c53934.zip Qt-5b37c01aa721057ad0cbef16a79cf179e3c53934.tar.gz Qt-5b37c01aa721057ad0cbef16a79cf179e3c53934.tar.bz2 |
Update to new QScriptDeclarativeClass API
-rw-r--r-- | src/declarative/qml/qmlcontextscriptclass.cpp | 48 | ||||
-rw-r--r-- | src/declarative/qml/qmlcontextscriptclass_p.h | 6 | ||||
-rw-r--r-- | src/declarative/qml/qmlobjectscriptclass.cpp | 23 | ||||
-rw-r--r-- | src/declarative/qml/qmlobjectscriptclass_p.h | 9 | ||||
-rw-r--r-- | src/declarative/qml/qmltypenamecache.cpp | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmltypenamecache_p.h | 1 | ||||
-rw-r--r-- | src/declarative/qml/qmltypenamescriptclass.cpp | 12 | ||||
-rw-r--r-- | src/declarative/qml/qmltypenamescriptclass_p.h | 6 |
8 files changed, 31 insertions, 75 deletions
diff --git a/src/declarative/qml/qmlcontextscriptclass.cpp b/src/declarative/qml/qmlcontextscriptclass.cpp index d8ae4f0..4b149f7 100644 --- a/src/declarative/qml/qmlcontextscriptclass.cpp +++ b/src/declarative/qml/qmlcontextscriptclass.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE -struct ContextData { +struct ContextData : public QScriptDeclarativeClass::Object { ContextData(QmlContext *c) : context(c) {} QGuard<QmlContext> context; }; @@ -69,11 +69,11 @@ QScriptValue QmlContextScriptClass::newContext(QmlContext *context) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - return newObject(scriptEngine, this, (Object)new ContextData(context)); + return newObject(scriptEngine, this, new ContextData(context)); } QScriptClass::QueryFlags -QmlContextScriptClass::queryProperty(const Object &object, const Identifier &name, +QmlContextScriptClass::queryProperty(Object *object, const Identifier &name, QScriptClass::QueryFlags flags) { Q_UNUSED(flags); @@ -93,7 +93,6 @@ QmlContextScriptClass::queryProperty(const Object &object, const Identifier &nam if (lastPropertyIndex != -1) return QScriptClass::HandlesReadAccess; - // ### Check for attached properties if (ep->currentExpression && cp->imports && bindContext == ep->currentExpression->context()) { QmlTypeNameCache::Data *data = cp->imports->data(name); @@ -103,22 +102,6 @@ QmlContextScriptClass::queryProperty(const Object &object, const Identifier &nam } } -#if 0 - QmlType *type = 0; ImportedNamespace *ns = 0; - if (currentExpression && bindContext == currentExpression->context() && - propName.at(0).isUpper() && resolveType(bindContext->d_func()->imports, propName.toUtf8(), &type, 0, 0, 0, &ns)) { - - if (type || ns) { - // Must be either an attached property, or an enum - resolveData.object = bindContext->d_func()->defaultObjects.first(); - resolveData.type = type; - resolveData.ns = ns; - return QScriptClass::HandlesReadAccess; - } - - } -#endif - for (int ii = 0; ii < cp->defaultObjects.count(); ++ii) { QScriptClass::QueryFlags rv = ep->objectClass->queryProperty(cp->defaultObjects.at(ii), name, flags); @@ -137,12 +120,10 @@ QmlContextScriptClass::queryProperty(const Object &object, const Identifier &nam return 0; } -QScriptValue QmlContextScriptClass::property(const Object &object, const Identifier &name) +QScriptValue QmlContextScriptClass::property(Object *object, const Identifier &name) { Q_UNUSED(object); - Q_ASSERT(lastPropertyIndex != -1 || lastDefaultObject != -1); - QmlContext *bindContext = ((ContextData *)object)->context.data(); Q_ASSERT(bindContext); @@ -150,18 +131,6 @@ QScriptValue QmlContextScriptClass::property(const Object &object, const Identif QmlContextPrivate *cp = QmlContextPrivate::get(bindContext); - // ### Check for attached properties -#if 0 - if (resolveData.type || resolveData.ns) { - QmlTypeNameBridge tnb = { - resolveData.object, - resolveData.type, - resolveData.ns - }; - return scriptEngine.newObject(typeNameClass, scriptEngine.newVariant(qVariantFromValue(tnb))); - } -#endif - if (lastData) { if (lastData->type) @@ -176,12 +145,7 @@ QScriptValue QmlContextScriptClass::property(const Object &object, const Identif rv = ep->objectClass->newQObject(cp->idValues[lastPropertyIndex].data()); } else { QVariant value = cp->propertyValues.at(lastPropertyIndex); - if (QmlMetaType::isObject(value.userType())) { - rv = ep->objectClass->newQObject(QmlMetaType::toQObject(value)); - } else { - // ### Shouldn't this be qScriptValueFromValue() - rv = ep->scriptEngine.newVariant(value); - } + return ep->scriptValueFromVariant(value); } ep->capturedProperties << @@ -200,7 +164,7 @@ QScriptValue QmlContextScriptClass::property(const Object &object, const Identif } } -void QmlContextScriptClass::setProperty(const Object &object, const Identifier &name, +void QmlContextScriptClass::setProperty(Object *object, const Identifier &name, const QScriptValue &value) { Q_ASSERT(lastDefaultObject != -1); diff --git a/src/declarative/qml/qmlcontextscriptclass_p.h b/src/declarative/qml/qmlcontextscriptclass_p.h index a00e567..acb8926 100644 --- a/src/declarative/qml/qmlcontextscriptclass_p.h +++ b/src/declarative/qml/qmlcontextscriptclass_p.h @@ -70,10 +70,10 @@ public: QScriptValue newContext(QmlContext *); protected: - virtual QScriptClass::QueryFlags queryProperty(const Object &, const Identifier &, + virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); - virtual QScriptValue property(const Object &, const Identifier &); - virtual void setProperty(const Object &, const Identifier &name, const QScriptValue &); + virtual QScriptValue property(Object *, const Identifier &); + virtual void setProperty(Object *, const Identifier &name, const QScriptValue &); private: QmlEngine *engine; diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp index 6a34a2f..33fd409 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -46,7 +46,7 @@ QT_BEGIN_NAMESPACE -struct ObjectData { +struct ObjectData : public QScriptDeclarativeClass::Object { ObjectData(QObject *o) : object(o) {} QGuard<QObject> object; }; @@ -77,7 +77,7 @@ QScriptValue QmlObjectScriptClass::newQObject(QObject *object) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - return newObject(scriptEngine, this, (Object)new ObjectData(object)); + return newObject(scriptEngine, this, new ObjectData(object)); } QObject *QmlObjectScriptClass::toQObject(const QScriptValue &value) const @@ -86,7 +86,7 @@ QObject *QmlObjectScriptClass::toQObject(const QScriptValue &value) const } QScriptClass::QueryFlags -QmlObjectScriptClass::queryProperty(const Object &object, const Identifier &name, +QmlObjectScriptClass::queryProperty(Object *object, const Identifier &name, QScriptClass::QueryFlags flags) { return queryProperty(toQObject(object), name, flags); @@ -132,7 +132,7 @@ QmlObjectScriptClass::queryProperty(QObject *obj, const Identifier &name, return rv; } -QScriptValue QmlObjectScriptClass::property(const Object &object, const Identifier &name) +QScriptValue QmlObjectScriptClass::property(Object *object, const Identifier &name) { return property(toQObject(object), name); } @@ -155,7 +155,7 @@ QScriptValue QmlObjectScriptClass::property(QObject *obj, const Identifier &name QScriptValue sobj = scriptEngine->newQObject(obj); return sobj.property(toString(name)); } else { - if (lastData->propType < QVariant::UserType) { + if ((uint)lastData->propType < QVariant::UserType) { QmlValueType *valueType = enginePriv->valueTypes[lastData->propType]; if (valueType) return enginePriv->valueTypeClass->newObject(obj, lastData->coreIndex, valueType); @@ -177,7 +177,7 @@ QScriptValue QmlObjectScriptClass::property(QObject *obj, const Identifier &name } } -void QmlObjectScriptClass::setProperty(const Object &object, +void QmlObjectScriptClass::setProperty(Object *object, const Identifier &name, const QScriptValue &value) { @@ -193,7 +193,6 @@ void QmlObjectScriptClass::setProperty(QObject *obj, Q_ASSERT(obj); Q_ASSERT(lastData); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine); // ### Can well known types be optimized? @@ -201,7 +200,7 @@ void QmlObjectScriptClass::setProperty(QObject *obj, QmlMetaPropertyPrivate::write(obj, *lastData, v, enginePriv->currentExpression->context()); } -QObject *QmlObjectScriptClass::toQObject(const Object &object, bool *ok) +QObject *QmlObjectScriptClass::toQObject(Object *object, bool *ok) { if (ok) *ok = true; @@ -209,13 +208,7 @@ QObject *QmlObjectScriptClass::toQObject(const Object &object, bool *ok) return data->object.data(); } -void QmlObjectScriptClass::destroyed(const Object &object) -{ - ObjectData *data = (ObjectData*)object; - delete data; -} - -QScriptValue QmlObjectScriptClass::tostring(QScriptContext *context, QScriptEngine *engine) +QScriptValue QmlObjectScriptClass::tostring(QScriptContext *context, QScriptEngine *) { QObject* obj = context->thisObject().toQObject(); diff --git a/src/declarative/qml/qmlobjectscriptclass_p.h b/src/declarative/qml/qmlobjectscriptclass_p.h index c86abdb..6406f0d 100644 --- a/src/declarative/qml/qmlobjectscriptclass_p.h +++ b/src/declarative/qml/qmlobjectscriptclass_p.h @@ -77,13 +77,12 @@ public: void setProperty(QObject *, const Identifier &name, const QScriptValue &); protected: - virtual QScriptClass::QueryFlags queryProperty(const Object &, const Identifier &, + virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); - virtual QScriptValue property(const Object &, const Identifier &); - virtual void setProperty(const Object &, const Identifier &name, const QScriptValue &); - virtual QObject *toQObject(const Object &, bool *ok = 0); - virtual void destroyed(const Object &); + virtual QScriptValue property(Object *, const Identifier &); + virtual void setProperty(Object *, const Identifier &name, const QScriptValue &); + virtual QObject *toQObject(Object *, bool *ok = 0); private: QmlPropertyCache::Data *lastData; diff --git a/src/declarative/qml/qmltypenamecache.cpp b/src/declarative/qml/qmltypenamecache.cpp index 2b0f2c9..aa1c938 100644 --- a/src/declarative/qml/qmltypenamecache.cpp +++ b/src/declarative/qml/qmltypenamecache.cpp @@ -40,6 +40,7 @@ ****************************************************************************/ #include "qmltypenamecache_p.h" +#include <private/qmlengine_p.h> QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qmltypenamecache_p.h b/src/declarative/qml/qmltypenamecache_p.h index 6022b43..f11fe68 100644 --- a/src/declarative/qml/qmltypenamecache_p.h +++ b/src/declarative/qml/qmltypenamecache_p.h @@ -55,7 +55,6 @@ #include <private/qmlrefcount_p.h> #include <private/qscriptdeclarativeclass_p.h> -#include <private/qmlengine_p.h> QT_BEGIN_NAMESPACE diff --git a/src/declarative/qml/qmltypenamescriptclass.cpp b/src/declarative/qml/qmltypenamescriptclass.cpp index 29e2978..7c5e5b0 100644 --- a/src/declarative/qml/qmltypenamescriptclass.cpp +++ b/src/declarative/qml/qmltypenamescriptclass.cpp @@ -45,7 +45,7 @@ QT_BEGIN_NAMESPACE -struct TypeNameData { +struct TypeNameData : public QScriptDeclarativeClass::Object { TypeNameData(QObject *o, QmlType *t) : object(o), type(t), typeNamespace(0) {} TypeNameData(QObject *o, QmlTypeNameCache *n) : object(o), type(0), typeNamespace(n) { if (typeNamespace) typeNamespace->addref(); @@ -73,19 +73,19 @@ QScriptValue QmlTypeNameScriptClass::newObject(QObject *object, QmlType *type) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - return QScriptDeclarativeClass::newObject(scriptEngine, this, (Object)new TypeNameData(object, type)); + return QScriptDeclarativeClass::newObject(scriptEngine, this, new TypeNameData(object, type)); } QScriptValue QmlTypeNameScriptClass::newObject(QObject *object, QmlTypeNameCache *ns) { QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); - return QScriptDeclarativeClass::newObject(scriptEngine, this, (Object)new TypeNameData(object, ns)); + return QScriptDeclarativeClass::newObject(scriptEngine, this, new TypeNameData(object, ns)); } QScriptClass::QueryFlags -QmlTypeNameScriptClass::queryProperty(const Object &obj, const Identifier &name, +QmlTypeNameScriptClass::queryProperty(Object *obj, const Identifier &name, QScriptClass::QueryFlags flags) { Q_UNUSED(flags); @@ -134,7 +134,7 @@ QmlTypeNameScriptClass::queryProperty(const Object &obj, const Identifier &name, } } -QScriptValue QmlTypeNameScriptClass::property(const Object &obj, const Identifier &name) +QScriptValue QmlTypeNameScriptClass::property(Object *obj, const Identifier &name) { QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); if (type) { @@ -146,7 +146,7 @@ QScriptValue QmlTypeNameScriptClass::property(const Object &obj, const Identifie } } -void QmlTypeNameScriptClass::setProperty(const Object &o, const Identifier &n, const QScriptValue &v) +void QmlTypeNameScriptClass::setProperty(Object *o, const Identifier &n, const QScriptValue &v) { Q_ASSERT(object); Q_ASSERT(!type); diff --git a/src/declarative/qml/qmltypenamescriptclass_p.h b/src/declarative/qml/qmltypenamescriptclass_p.h index c642ea4..3bd51e6 100644 --- a/src/declarative/qml/qmltypenamescriptclass_p.h +++ b/src/declarative/qml/qmltypenamescriptclass_p.h @@ -71,11 +71,11 @@ public: QScriptValue newObject(QObject *, QmlTypeNameCache *); protected: - virtual QScriptClass::QueryFlags queryProperty(const Object &, const Identifier &, + virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, QScriptClass::QueryFlags flags); - virtual QScriptValue property(const Object &, const Identifier &); - virtual void setProperty(const Object &, const Identifier &name, const QScriptValue &); + virtual QScriptValue property(Object *, const Identifier &); + virtual void setProperty(Object *, const Identifier &name, const QScriptValue &); private: QmlEngine *engine; |