summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmlobjectscriptclass.cpp
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-01 07:36:35 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-05 02:39:05 (GMT)
commit361a605e9269f3072c1f5597a8db0622cf3b116b (patch)
tree9d99caf4ffa22a954785a1917ea043966a928064 /src/declarative/qml/qmlobjectscriptclass.cpp
parent69c58d7e1c5713d1d6badeffc6c45eeacb1ba2d8 (diff)
downloadQt-361a605e9269f3072c1f5597a8db0622cf3b116b.zip
Qt-361a605e9269f3072c1f5597a8db0622cf3b116b.tar.gz
Qt-361a605e9269f3072c1f5597a8db0622cf3b116b.tar.bz2
Read/write property directly from QmlObjectScriptClass
Diffstat (limited to 'src/declarative/qml/qmlobjectscriptclass.cpp')
-rw-r--r--src/declarative/qml/qmlobjectscriptclass.cpp110
1 files changed, 35 insertions, 75 deletions
diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp
index 0ae1809..28a808a 100644
--- a/src/declarative/qml/qmlobjectscriptclass.cpp
+++ b/src/declarative/qml/qmlobjectscriptclass.cpp
@@ -149,20 +149,19 @@ QmlObjectScriptClass::queryProperty(QObject *obj, const Identifier &name,
}
if (cache) {
- QmlPropertyCache::Data *property = cache->property(name);
- if (!property) return 0;
-
- if (flags == QScriptClass::HandlesReadAccess) {
- lastData = property;
- return QScriptClass::HandlesReadAccess;
- } else if (property->propType > 0 && property->propType < QVariant::UserType) {
- lastData = property;
- return flags;
- }
+ lastData = cache->property(name);
+ } else {
+ local = QmlPropertyCache::create(obj->metaObject(), toString(name));
+ if (local.isValid())
+ lastData = &local;
}
- // Fallback
- return QmlEnginePrivate::get(engine)->queryObject(toString(name), &m_id, obj);
+ if (!lastData) return 0;
+
+ QScriptClass::QueryFlags rv = QScriptClass::HandlesReadAccess;
+ if (lastData->flags & QmlPropertyCache::Data::IsWritable)
+ rv |= QScriptClass::HandlesWriteAccess;
+ return rv;
}
QScriptValue QmlObjectScriptClass::property(const Object &object, const Identifier &name)
@@ -175,35 +174,31 @@ QScriptValue QmlObjectScriptClass::property(QObject *obj, const Identifier &name
if (name == m_destroyId->identifier)
return m_destroy;
+ Q_ASSERT(lastData);
+ Q_ASSERT(obj);
+
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine);
- if (!obj) {
- return QScriptValue();
- } else if (lastData) {
+ if (lastData->flags & QmlPropertyCache::Data::IsFunction) {
+ // ### Optimize
+ QScriptValue sobj = scriptEngine->newQObject(obj);
+ return sobj.property(toString(name));
+ } else {
+
+ QVariant var = obj->metaObject()->property(lastData->coreIndex).read(obj);
+ if (!(lastData->flags & QmlPropertyCache::Data::IsConstant)) {
+ enginePriv->capturedProperties <<
+ QmlEnginePrivate::CapturedProperty(obj, lastData->coreIndex, lastData->notifyIndex);
+ }
- if (lastData->flags & QmlPropertyCache::Data::IsFunction) {
- // ### Optimize
- QScriptValue sobj = scriptEngine->newQObject(obj);
- return sobj.property(toString(name));
+ if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) {
+ QObject *rv = *(QObject **)var.constData();
+ return newQObject(rv);
} else {
- QVariant var = obj->metaObject()->property(lastData->coreIndex).read(obj);
- if (!(lastData->flags & QmlPropertyCache::Data::IsConstant)) {
- enginePriv->capturedProperties <<
- QmlEnginePrivate::CapturedProperty(obj, lastData->coreIndex,
- lastData->notifyIndex);
- }
-
- if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) {
- QObject *rv = *(QObject **)var.constData();
- return newQObject(rv);
- } else {
- return qScriptValueFromValue(scriptEngine, var);
- }
+ return qScriptValueFromValue(scriptEngine, var);
}
- } else {
- return QmlEnginePrivate::get(engine)->propertyObject(toString(name), obj, m_id);
}
}
@@ -219,51 +214,16 @@ void QmlObjectScriptClass::setProperty(QObject *obj,
const QScriptValue &value)
{
Q_UNUSED(name);
- Q_UNUSED(object);
+
+ Q_ASSERT(obj);
+ Q_ASSERT(lastData);
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine);
- if (!obj) {
- return;
- } else if (lastData) {
- switch (lastData->propType) {
- case 1:
- {
- bool b = value.toBoolean();
- void *a[1];
- a[0] = &b;
- QMetaObject::metacall(obj, QMetaObject::WriteProperty, lastData->coreIndex, a);
- }
- break;
-
- case 2:
- {
- int b = value.toInteger();
- void *a[1];
- a[0] = &b;
- QMetaObject::metacall(obj, QMetaObject::WriteProperty, lastData->coreIndex, a);
- }
- break;
-
- case 6:
- {
- double b = value.toNumber();
- void *a[1];
- a[0] = &b;
- QMetaObject::metacall(obj, QMetaObject::WriteProperty, lastData->coreIndex, a);
- }
- break;
-
- default:
- {
- QMetaProperty p = obj->metaObject()->property(lastData->coreIndex);
- p.write(obj, value.toVariant());
- }
- }
- } else {
- QmlEnginePrivate::get(engine)->setPropertyObject(value, m_id);
- }
+ // ### Can well known types be optimized?
+ QVariant v = QmlScriptClass::toVariant(engine, value);
+ QmlMetaPropertyPrivate::write(obj, *lastData, v, enginePriv->currentExpression->context());
}
QObject *QmlObjectScriptClass::toQObject(const Object &object, bool *ok)