summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorBea Lam <bea.lam@nokia.com>2009-11-09 03:09:12 (GMT)
committerBea Lam <bea.lam@nokia.com>2009-11-09 03:09:12 (GMT)
commit5e5ee991ad4261516cf099c9b237f8c72c9d49cc (patch)
treef0f0f96e9b51baf85e22eb5698b1ea66a0223f2b /src/declarative/qml
parent034c9f1b81cfa2d854f87b08e945296d3c1fac85 (diff)
parent7620586aa79c027e5dfd246d53232826333ce715 (diff)
downloadQt-5e5ee991ad4261516cf099c9b237f8c72c9d49cc.zip
Qt-5e5ee991ad4261516cf099c9b237f8c72c9d49cc.tar.gz
Qt-5e5ee991ad4261516cf099c9b237f8c72c9d49cc.tar.bz2
Merge branch 'kinetic-declarativeui' of scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlboundsignal.cpp2
-rw-r--r--src/declarative/qml/qmlcompiler.cpp13
-rw-r--r--src/declarative/qml/qmlcontext_p.h2
-rw-r--r--src/declarative/qml/qmldom.cpp7
-rw-r--r--src/declarative/qml/qmlengine.cpp22
-rw-r--r--src/declarative/qml/qmlinfo.cpp12
-rw-r--r--src/declarative/qml/qmlintegercache.cpp29
-rw-r--r--src/declarative/qml/qmlintegercache_p.h2
-rw-r--r--src/declarative/qml/qmlmetatype.cpp45
-rw-r--r--src/declarative/qml/qmlmetatype.h3
-rw-r--r--src/declarative/qml/qmlparser.cpp94
-rw-r--r--src/declarative/qml/qmlparser_p.h6
-rw-r--r--src/declarative/qml/qmlprivate.h3
-rw-r--r--src/declarative/qml/qmlvaluetype_p.h20
-rw-r--r--src/declarative/qml/qmlvaluetypescriptclass.cpp101
-rw-r--r--src/declarative/qml/qmlvaluetypescriptclass_p.h18
16 files changed, 93 insertions, 286 deletions
diff --git a/src/declarative/qml/qmlboundsignal.cpp b/src/declarative/qml/qmlboundsignal.cpp
index def11c3..deb15dc 100644
--- a/src/declarative/qml/qmlboundsignal.cpp
+++ b/src/declarative/qml/qmlboundsignal.cpp
@@ -177,7 +177,7 @@ int QmlBoundSignal::qt_metacall(QMetaObject::Call c, int id, void **a)
if (m_params) m_params->setValues(a);
if (m_expression) {
QmlExpressionPrivate::get(m_expression)->value(m_params);
- if (m_expression->hasError())
+ if (m_expression && m_expression->hasError())
qWarning().nospace() << qPrintable(m_expression->error().toString());
}
if (m_params) m_params->clearValues();
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 240f16c..8e92eb4 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -1714,7 +1714,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop,
prop->value, obj, ctxt.incr()));
obj->addValueTypeProperty(prop);
} else {
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property access"));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access"));
}
} else {
@@ -1722,7 +1722,7 @@ bool QmlCompiler::buildGroupedProperty(QmlParser::Property *prop,
prop->value->metatype =
QmlEnginePrivate::get(engine)->metaObjectForType(prop->type);
if (!prop->value->metatype)
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Cannot nest non-QObject property \"%1\"").arg(QString::fromUtf8(prop->name)));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid grouped property access"));
obj->addGroupedProperty(prop);
@@ -1749,8 +1749,11 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type,
prop->index = idx;
prop->type = p.userType();
- if (prop->value || prop->values.count() != 1)
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use"));
+ if (prop->value)
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Property assignment expected"));
+
+ if (prop->values.count() != 1)
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Single property assignment expected"));
Value *value = prop->values.at(0);
@@ -1758,7 +1761,7 @@ bool QmlCompiler::buildValueTypeProperty(QObject *type,
bool isPropertyValue = output->types.at(value->object->type).type->propertyValueSourceCast() != -1;
bool isPropertyInterceptor = output->types.at(value->object->type).type->propertyValueInterceptorCast() != -1;
if (!isPropertyValue && !isPropertyInterceptor) {
- COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Invalid property use"));
+ COMPILE_EXCEPTION(prop, qApp->translate("QmlCompiler","Unexpected object assignment"));
} else {
COMPILE_CHECK(buildObject(value->object, ctxt));
diff --git a/src/declarative/qml/qmlcontext_p.h b/src/declarative/qml/qmlcontext_p.h
index 7f9be0f..22d981f 100644
--- a/src/declarative/qml/qmlcontext_p.h
+++ b/src/declarative/qml/qmlcontext_p.h
@@ -74,7 +74,7 @@ class QmlExpressionPrivate;
class QmlAbstractExpression;
class QmlBinding_Id;
-class QmlContextPrivate : public QObjectPrivate
+class Q_DECLARATIVE_EXPORT QmlContextPrivate : public QObjectPrivate
{
Q_DECLARE_PUBLIC(QmlContext)
public:
diff --git a/src/declarative/qml/qmldom.cpp b/src/declarative/qml/qmldom.cpp
index b6e794b..39d6730 100644
--- a/src/declarative/qml/qmldom.cpp
+++ b/src/declarative/qml/qmldom.cpp
@@ -52,8 +52,6 @@
QT_BEGIN_NAMESPACE
-DEFINE_BOOL_CONFIG_OPTION(compilerDump, QML_COMPILER_DUMP)
-
QmlDomDocumentPrivate::QmlDomDocumentPrivate()
: root(0)
{
@@ -191,11 +189,6 @@ bool QmlDomDocument::load(QmlEngine *engine, const QByteArray &data, const QUrl
}
if (td->data.tree()) {
- if (compilerDump()) {
- qWarning() << "-AST------------------------------------------------------------------------------";
- td->data.tree()->dump();
- qWarning() << "----------------------------------------------------------------------------------";
- }
d->root = td->data.tree();
d->root->addref();
}
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 3df04b2..177818f 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -626,6 +626,11 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi
url = QUrl(ctxt->argument(2).toString());
QObject *parentArg = activeEnginePriv->objectClass->toQObject(ctxt->argument(1));
QmlContext *qmlCtxt = qmlContext(parentArg);
+ if(!parentArg || !qmlCtxt){
+ //TODO: Could use a qmlInfo() like function for script functions
+ qWarning() << "createQmlObject called with invalid parent object";
+ return engine->nullValue();
+ }
if (url.isEmpty()) {
url = qmlCtxt->resolvedUrl(QUrl(QLatin1String("<Unknown File>")));
} else {
@@ -903,7 +908,7 @@ QVariant QmlEnginePrivate::scriptValueToVariant(const QScriptValue &val)
else if (dc == contextClass)
return QVariant();
- QScriptClass *sc = val.scriptClass();
+ QScriptDeclarativeClass *sc = QScriptDeclarativeClass::scriptClass(val);
if (!sc) {
return val.toVariant();
} else if (sc == valueTypeClass) {
@@ -924,20 +929,7 @@ QVariant QmlScriptClass::toVariant(QmlEngine *engine, const QScriptValue &val)
QmlEnginePrivate *ep =
static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine));
- QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(val);
- if (dc == ep->objectClass)
- return QVariant::fromValue(ep->objectClass->toQObject(val));
- else if (dc == ep->contextClass)
- return QVariant();
-
- QScriptClass *sc = val.scriptClass();
- if (!sc) {
- return val.toVariant();
- } else if (sc == ep->valueTypeClass) {
- return ep->valueTypeClass->toVariant(val);
- }
-
- return QVariant();
+ return ep->scriptValueToVariant(val);
}
// XXX this beyonds in QUrl::toLocalFile()
diff --git a/src/declarative/qml/qmlinfo.cpp b/src/declarative/qml/qmlinfo.cpp
index c0d9eca..f62f5fd 100644
--- a/src/declarative/qml/qmlinfo.cpp
+++ b/src/declarative/qml/qmlinfo.cpp
@@ -80,18 +80,18 @@ void qmlInfo(const QString& msg, QObject* object)
pos += QLatin1Char(' ');
pos += QLatin1String(object->metaObject()->className());
}
- QmlDeclarativeData *ddata = QmlDeclarativeData::get(object);
+ QmlDeclarativeData *ddata = object?QmlDeclarativeData::get(object):0;
pos += QLatin1String(" (");
if (ddata) {
if (ddata->outerContext) {
pos += ddata->outerContext->baseUrl().toString();
+ pos += QLatin1String(":");
+ pos += QString::number(ddata->lineNumber);
+ pos += QLatin1String(":");
+ pos += QString::number(ddata->columnNumber);
} else {
- pos += qApp->translate("QmlInfo","unknown");
+ pos += qApp->translate("QmlInfo","unknown location");
}
- pos += QLatin1String(":");
- pos += QString::number(ddata->lineNumber);
- pos += QLatin1String(":");
- pos += QString::number(ddata->columnNumber);
} else {
pos += qApp->translate("QmlInfo","unknown location");
}
diff --git a/src/declarative/qml/qmlintegercache.cpp b/src/declarative/qml/qmlintegercache.cpp
index b20b6eb..d1927b3 100644
--- a/src/declarative/qml/qmlintegercache.cpp
+++ b/src/declarative/qml/qmlintegercache.cpp
@@ -82,33 +82,4 @@ int QmlIntegerCache::value(const QString &id)
return d?d->value:-1;
}
-QmlIntegerCache *QmlIntegerCache::createForEnums(QmlType *type, QmlEngine *engine)
-{
- Q_ASSERT(type);
- Q_ASSERT(engine);
-
- QmlIntegerCache *cache = new QmlIntegerCache(engine);
-
- const QMetaObject *mo = type->metaObject();
-
- for (int ii = mo->enumeratorCount() - 1; ii >= 0; --ii) {
- QMetaEnum enumerator = mo->enumerator(ii);
-
- for (int jj = 0; jj < enumerator.keyCount(); ++jj) {
- QString name = QString::fromUtf8(enumerator.key(jj));
- int value = enumerator.value(jj);
-
- if (!name.at(0).isUpper())
- continue;
-
- if (cache->stringCache.contains(name))
- continue;
-
- cache->add(name, value);
- }
- }
-
- return cache;
-}
-
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlintegercache_p.h b/src/declarative/qml/qmlintegercache_p.h
index 7816004..2b10dcc 100644
--- a/src/declarative/qml/qmlintegercache_p.h
+++ b/src/declarative/qml/qmlintegercache_p.h
@@ -73,8 +73,6 @@ public:
int value(const QString &);
inline int value(const QScriptDeclarativeClass::Identifier &id) const;
- static QmlIntegerCache *createForEnums(QmlType *, QmlEngine *);
-
protected:
virtual void clear();
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index 6ecaa9f..5fb2f50 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -134,7 +134,6 @@ public:
QmlCustomParser *m_customParser;
mutable volatile bool m_isSetup:1;
mutable QList<QmlProxyMetaObject::ProxyData> m_metaObjects;
- mutable QByteArray m_hash;
};
QmlTypePrivate::QmlTypePrivate()
@@ -259,27 +258,6 @@ void QmlTypePrivate::init() const
m_metaObjects.at(ii).metaObject->methodOffset();
}
- // Calculate hash
- QByteArray hashData;
-
- const QMetaObject *myMetaObject = m_metaObjects.isEmpty()?m_baseMetaObject:m_metaObjects.first().metaObject;
-
- for (int ii = 0; ii < myMetaObject->propertyCount(); ++ii) {
- QMetaProperty prop = myMetaObject->property(ii);
- hashData.append(prop.type());
- hashData.append("|");
- hashData.append(prop.name());
- hashData.append("|");
- }
-
- for (int ii = 0; ii < myMetaObject->methodCount(); ++ii) {
- QMetaMethod method = myMetaObject->method(ii);
- hashData.append(method.signature());
- hashData.append("|");
- }
-
- m_hash = QCryptographicHash::hash(hashData, QCryptographicHash::Md5);
-
m_isSetup = true;
lock.unlock();
}
@@ -297,13 +275,6 @@ QByteArray QmlType::qmlTypeName() const
return d->m_name;
}
-QByteArray QmlType::hash() const
-{
- d->init();
-
- return d->m_hash;
-}
-
QObject *QmlType::create() const
{
d->init();
@@ -804,17 +775,6 @@ const char *QmlMetaType::interfaceIId(int userType)
return 0;
}
-bool QmlMetaType::isObject(const QMetaObject *mo)
-{
- // ### Huh?
- while(mo) {
- if (mo == &QObject::staticMetaObject)
- return true;
- mo = mo->superClass();
- }
- return false;
-}
-
bool QmlMetaType::isQmlList(int userType)
{
QReadLocker lock(metaTypeDataLock());
@@ -851,6 +811,9 @@ int QmlMetaType::listCount(const QVariant &v)
QVariant QmlMetaType::listAt(const QVariant &v, int idx)
{
+ if (idx < 0)
+ return QVariant();
+
int userType = v.userType();
QReadLocker lock(metaTypeDataLock());
@@ -861,7 +824,7 @@ QVariant QmlMetaType::listAt(const QVariant &v, int idx)
if (type && type->qListTypeId() == userType)
return type->listAt(v, idx);
else
- return 0;
+ return QVariant();
}
/*!
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index e90c367..1f493f8 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -97,7 +97,6 @@ public:
static bool isInterface(int);
static const char *interfaceIId(int);
static bool isObject(int);
- static bool isObject(const QMetaObject *);
static bool isList(int);
static bool isList(const QVariant &);
static bool isQmlList(int);
@@ -121,8 +120,6 @@ public:
int minorVersion() const;
bool availableInVersion(int vmajor, int vminor) const;
- QByteArray hash() const;
-
QObject *create() const;
QmlCustomParser *customParser() const;
diff --git a/src/declarative/qml/qmlparser.cpp b/src/declarative/qml/qmlparser.cpp
index 7fd57f3..ee69b14 100644
--- a/src/declarative/qml/qmlparser.cpp
+++ b/src/declarative/qml/qmlparser.cpp
@@ -200,28 +200,6 @@ QmlParser::Object::DynamicSlot::DynamicSlot(const DynamicSlot &o)
{
}
-void QmlParser::Object::dump(int indent) const
-{
- QByteArray ba(indent * 4, ' ');
- if (type != -1) {
- qWarning() << ba.constData() << "Object:" << typeName;
- } else {
- qWarning() << ba.constData() << "Object: fetched";
- }
-
- for (QHash<QByteArray, Property *>::ConstIterator iter = properties.begin();
- iter != properties.end();
- ++iter) {
- qWarning() << ba.constData() << " Property" << iter.key();
- (*iter)->dump(indent + 1);
- }
-
- if (defaultProperty) {
- qWarning() << ba.constData() << " Default property";
- defaultProperty->dump(indent + 1);
- }
-}
-
QmlParser::Property::Property()
: parent(0), type(0), index(-1), value(0), isDefault(true), isDeferred(false)
{
@@ -256,15 +234,6 @@ bool QmlParser::Property::isEmpty() const
return !value && values.isEmpty();
}
-void QmlParser::Property::dump(int indent) const
-{
- QByteArray ba(indent * 4, ' ');
- for (int ii = 0; ii < values.count(); ++ii)
- values.at(ii)->dump(indent);
- if (value)
- value->dump(indent);
-}
-
QmlParser::Value::Value()
: type(Unknown), object(0)
{
@@ -275,69 +244,6 @@ QmlParser::Value::~Value()
if (object) object->release();
}
-void QmlParser::Value::dump(int indent) const
-{
- QByteArray type;
- switch(this->type) {
- default:
- case Value::Unknown:
- type = "Unknown";
- break;
- case Value::Literal:
- type = "Literal";
- break;
- case Value::PropertyBinding:
- type = "PropertyBinding";
- break;
- case Value::ValueSource:
- type = "ValueSource";
- break;
- case Value::ValueInterceptor:
- type = "ValueInterceptor";
- break;
- case Value::CreatedObject:
- type = "CreatedObject";
- break;
- case Value::SignalObject:
- type = "SignalObject";
- break;
- case Value::SignalExpression:
- type = "SignalExpression";
- break;
- case Value::Id:
- type = "Id";
- break;
- }
-
- QByteArray primType;
- switch(this->value.type()) {
- default:
- case Variant::Invalid:
- primType = "Invalid";
- break;
- case Variant::Boolean:
- primType = "Boolean";
- break;
- case Variant::Number:
- primType = "Number";
- break;
- case Variant::String:
- primType = "String";
- break;
- case Variant::Script:
- primType = "Script";
- break;
- }
-
- QByteArray ba(indent * 4, ' ');
- if (object) {
- qWarning() << ba.constData() << "Value (" << type << "):";
- object->dump(indent + 1);
- } else {
- qWarning() << ba.constData() << "Value (" << type << "):" << primType.constData() << primitive();
- }
-}
-
QmlParser::Variant::Variant()
: t(Invalid) {}
diff --git a/src/declarative/qml/qmlparser_p.h b/src/declarative/qml/qmlparser_p.h
index 5bffff2..4f080e5 100644
--- a/src/declarative/qml/qmlparser_p.h
+++ b/src/declarative/qml/qmlparser_p.h
@@ -216,8 +216,6 @@ namespace QmlParser
QList<DynamicSignal> dynamicSignals;
// The list of dynamic slots
QList<DynamicSlot> dynamicSlots;
-
- void dump(int = 0) const;
};
class Variant
@@ -299,8 +297,6 @@ namespace QmlParser
Object *object;
LocationSpan location;
-
- void dump(int = 0) const;
};
class Property : public QmlRefCount
@@ -342,8 +338,6 @@ namespace QmlParser
LocationSpan location;
LocationRange listValueRange;
QList<int> listCommaPositions;
-
- void dump(int = 0) const;
};
}
diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h
index e5b1060..0eec43c 100644
--- a/src/declarative/qml/qmlprivate.h
+++ b/src/declarative/qml/qmlprivate.h
@@ -283,7 +283,8 @@ int QmlPrivate::list_op(QmlPrivate::ListOp op, int val,
}
break;
case QmlPrivate::Value:
- *((QVariant *)*out) = QVariant::fromValue(list->at(val));
+ if (list->count() <= val) *((QVariant *)*out) = QVariant();
+ else *((QVariant *)*out) = QVariant::fromValue(list->at(val));
break;
}
return 0;
diff --git a/src/declarative/qml/qmlvaluetype_p.h b/src/declarative/qml/qmlvaluetype_p.h
index 0af3813..e7566f9 100644
--- a/src/declarative/qml/qmlvaluetype_p.h
+++ b/src/declarative/qml/qmlvaluetype_p.h
@@ -62,7 +62,7 @@
QT_BEGIN_NAMESPACE
-class QmlValueType : public QObject
+class Q_AUTOTEST_EXPORT QmlValueType : public QObject
{
Q_OBJECT
public:
@@ -73,7 +73,7 @@ public:
virtual void setValue(QVariant) = 0;
};
-class QmlValueTypeFactory
+class Q_AUTOTEST_EXPORT QmlValueTypeFactory
{
public:
QmlValueTypeFactory();
@@ -84,7 +84,7 @@ public:
QmlValueType *operator[](int idx) const { return valueTypes[idx]; }
};
-class QmlPointFValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlPointFValueType : public QmlValueType
{
Q_PROPERTY(qreal x READ x WRITE setX)
Q_PROPERTY(qreal y READ y WRITE setY)
@@ -106,7 +106,7 @@ private:
QPointF point;
};
-class QmlPointValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlPointValueType : public QmlValueType
{
Q_PROPERTY(int x READ x WRITE setX)
Q_PROPERTY(int y READ y WRITE setY)
@@ -128,7 +128,7 @@ private:
QPoint point;
};
-class QmlSizeFValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlSizeFValueType : public QmlValueType
{
Q_PROPERTY(qreal width READ width WRITE setWidth)
Q_PROPERTY(qreal height READ height WRITE setHeight)
@@ -150,7 +150,7 @@ private:
QSizeF size;
};
-class QmlSizeValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlSizeValueType : public QmlValueType
{
Q_PROPERTY(int width READ width WRITE setWidth)
Q_PROPERTY(int height READ height WRITE setHeight)
@@ -172,7 +172,7 @@ private:
QSize size;
};
-class QmlRectFValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlRectFValueType : public QmlValueType
{
Q_PROPERTY(qreal x READ x WRITE setX)
Q_PROPERTY(qreal y READ y WRITE setY)
@@ -201,7 +201,7 @@ private:
QRectF rect;
};
-class QmlRectValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlRectValueType : public QmlValueType
{
Q_PROPERTY(int x READ x WRITE setX)
Q_PROPERTY(int y READ y WRITE setY)
@@ -230,7 +230,7 @@ private:
QRect rect;
};
-class QmlVector3DValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlVector3DValueType : public QmlValueType
{
Q_PROPERTY(qreal x READ x WRITE setX)
Q_PROPERTY(qreal y READ y WRITE setY)
@@ -255,7 +255,7 @@ private:
QVector3D vector;
};
-class QmlFontValueType : public QmlValueType
+class Q_AUTOTEST_EXPORT QmlFontValueType : public QmlValueType
{
Q_OBJECT
Q_ENUMS(FontWeight)
diff --git a/src/declarative/qml/qmlvaluetypescriptclass.cpp b/src/declarative/qml/qmlvaluetypescriptclass.cpp
index 0c30992..e939e80 100644
--- a/src/declarative/qml/qmlvaluetypescriptclass.cpp
+++ b/src/declarative/qml/qmlvaluetypescriptclass.cpp
@@ -44,15 +44,14 @@
QT_BEGIN_NAMESPACE
-struct QmlValueTypeReference {
+struct QmlValueTypeReference : public QScriptDeclarativeClass::Object {
QmlValueType *type;
QGuard<QObject> object;
int property;
};
-Q_DECLARE_METATYPE(QmlValueTypeReference);
QmlValueTypeScriptClass::QmlValueTypeScriptClass(QmlEngine *bindEngine)
-: QScriptClass(QmlEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
+: QScriptDeclarativeClass(QmlEnginePrivate::getScriptEngine(bindEngine)), engine(bindEngine)
{
}
@@ -62,89 +61,83 @@ QmlValueTypeScriptClass::~QmlValueTypeScriptClass()
QScriptValue QmlValueTypeScriptClass::newObject(QObject *object, int coreIndex, QmlValueType *type)
{
- QmlValueTypeReference ref = { type, object, coreIndex };
- QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
- return scriptEngine->newObject(this, scriptEngine->newVariant(qVariantFromValue(ref)));
+ QmlValueTypeReference *ref = new QmlValueTypeReference;
+ ref->type = type;
+ ref->object = object;
+ ref->property = coreIndex;
+ return QScriptDeclarativeClass::newObject(QmlEnginePrivate::getScriptEngine(engine), this, ref);
}
-QmlValueTypeScriptClass::QueryFlags
-QmlValueTypeScriptClass::queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id)
+QScriptClass::QueryFlags
+QmlValueTypeScriptClass::queryProperty(Object *obj, const Identifier &name,
+ QScriptClass::QueryFlags)
{
- Q_UNUSED(flags);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- if (!ref.object)
+ m_lastIndex = -1;
+
+ if (!ref->object)
return 0;
- QByteArray propName = name.toString().toUtf8();
+ QByteArray propName = toString(name).toUtf8();
- int idx = ref.type->metaObject()->indexOfProperty(propName.constData());
- if (idx == -1)
+ m_lastIndex = ref->type->metaObject()->indexOfProperty(propName.constData());
+ if (m_lastIndex == -1)
return 0;
- *id = idx;
- QMetaProperty prop = ref.object->metaObject()->property(idx);
+ QMetaProperty prop = ref->object->metaObject()->property(m_lastIndex);
- QmlValueTypeScriptClass::QueryFlags rv =
- QmlValueTypeScriptClass::HandlesReadAccess;
+ QScriptClass::QueryFlags rv =
+ QScriptClass::HandlesReadAccess;
if (prop.isWritable())
- rv |= QmlValueTypeScriptClass::HandlesWriteAccess;
+ rv |= QScriptClass::HandlesWriteAccess;
return rv;
}
-QScriptValue QmlValueTypeScriptClass::property(const QScriptValue &object,
- const QScriptString &name,
- uint id)
+QScriptValue QmlValueTypeScriptClass::property(Object *obj, const Identifier &)
{
- Q_UNUSED(name);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
-
- if (!ref.object)
- return QScriptValue();
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- ref.type->read(ref.object, ref.property);
-
- QMetaProperty p = ref.type->metaObject()->property(id);
- QVariant rv = p.read(ref.type);
+ QMetaProperty p = ref->type->metaObject()->property(m_lastIndex);
+ ref->type->read(ref->object, ref->property);
+ QVariant rv = p.read(ref->type);
return static_cast<QmlEnginePrivate *>(QObjectPrivate::get(engine))->scriptValueFromVariant(rv);
}
-void QmlValueTypeScriptClass::setProperty(QScriptValue &object,
- const QScriptString &name,
- uint id,
+void QmlValueTypeScriptClass::setProperty(Object *obj, const Identifier &,
const QScriptValue &value)
{
- Q_UNUSED(name);
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(object.data().toVariant());
-
- if (!ref.object)
- return;
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
QVariant v = QmlScriptClass::toVariant(engine, value);
- ref.type->read(ref.object, ref.property);
- QMetaProperty p = ref.type->metaObject()->property(id);
- p.write(ref.type, v);
- ref.type->write(ref.object, ref.property, 0);
+ 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);
}
-QVariant QmlValueTypeScriptClass::toVariant(const QScriptValue &val)
+QVariant QmlValueTypeScriptClass::toVariant(Object *obj, bool *ok)
{
- QmlValueTypeReference ref =
- qvariant_cast<QmlValueTypeReference>(val.data().toVariant());
+ QmlValueTypeReference *ref = static_cast<QmlValueTypeReference *>(obj);
- if (!ref.object)
+ if (ok) *ok = true;
+
+ if (ref->object) {
+ ref->type->read(ref->object, ref->property);
+ return ref->type->value();
+ } else {
return QVariant();
+ }
+}
+
+QVariant QmlValueTypeScriptClass::toVariant(const QScriptValue &value)
+{
+ Q_ASSERT(scriptClass(value) == this);
- QMetaProperty p = ref.object->metaObject()->property(ref.property);
- return p.read(ref.object);
+ return toVariant(object(value), 0);
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmlvaluetypescriptclass_p.h b/src/declarative/qml/qmlvaluetypescriptclass_p.h
index bd31ec1..19020b2 100644
--- a/src/declarative/qml/qmlvaluetypescriptclass_p.h
+++ b/src/declarative/qml/qmlvaluetypescriptclass_p.h
@@ -59,7 +59,7 @@ QT_BEGIN_NAMESPACE
class QmlEngine;
class QmlValueType;
-class QmlValueTypeScriptClass : public QScriptClass
+class QmlValueTypeScriptClass : public QScriptDeclarativeClass
{
public:
QmlValueTypeScriptClass(QmlEngine *);
@@ -67,20 +67,16 @@ public:
QScriptValue newObject(QObject *object, int coreIndex, QmlValueType *);
- virtual QueryFlags queryProperty(const QScriptValue &object,
- const QScriptString &name,
- QueryFlags flags, uint *id);
- virtual QScriptValue property(const QScriptValue &object,
- const QScriptString &name,
- uint id);
- virtual void setProperty(QScriptValue &object,
- const QScriptString &name,
- uint id,
- const QScriptValue &value);
+ virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
+ QScriptClass::QueryFlags flags);
+ virtual QScriptValue property(Object *, const Identifier &);
+ virtual void setProperty(Object *, const Identifier &name, const QScriptValue &);
+ virtual QVariant toVariant(Object *, bool *ok = 0);
QVariant toVariant(const QScriptValue &);
private:
QmlEngine *engine;
+ int m_lastIndex;
};
QT_END_NAMESPACE