summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2010-02-11 04:52:34 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2010-02-12 04:58:22 (GMT)
commit1d2b1b31166e029e009f08877ef95f95e58a03a4 (patch)
treeae2ce1a9465f885ff6e24b583fe7330c74a9dd78 /src/declarative/qml
parent4b740bdf8cbaaf97541a821c28bae075067343d3 (diff)
downloadQt-1d2b1b31166e029e009f08877ef95f95e58a03a4.zip
Qt-1d2b1b31166e029e009f08877ef95f95e58a03a4.tar.gz
Qt-1d2b1b31166e029e009f08877ef95f95e58a03a4.tar.bz2
Cleanup public QmlMetaType API
Remove some unnecessary methods from the QmlMetaType class
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qmlboundsignal.cpp2
-rw-r--r--src/declarative/qml/qmlcompiledbindings.cpp4
-rw-r--r--src/declarative/qml/qmlcontext.cpp31
-rw-r--r--src/declarative/qml/qmlengine.cpp28
-rw-r--r--src/declarative/qml/qmlengine_p.h3
-rw-r--r--src/declarative/qml/qmlenginedebug.cpp4
-rw-r--r--src/declarative/qml/qmlguard_p.h2
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp23
-rw-r--r--src/declarative/qml/qmlmetaproperty_p.h3
-rw-r--r--src/declarative/qml/qmlmetatype.cpp148
-rw-r--r--src/declarative/qml/qmlmetatype.h15
11 files changed, 109 insertions, 154 deletions
diff --git a/src/declarative/qml/qmlboundsignal.cpp b/src/declarative/qml/qmlboundsignal.cpp
index 110a56c..d42e7ba 100644
--- a/src/declarative/qml/qmlboundsignal.cpp
+++ b/src/declarative/qml/qmlboundsignal.cpp
@@ -214,7 +214,7 @@ QmlBoundSignalParameters::QmlBoundSignalParameters(const QMetaMethod &method,
}
QVariant::Type t = (QVariant::Type)QMetaType::type(type.constData());
- if (QmlMetaType::isObject(t)) {
+ if (QmlMetaType::isQObject(t)) {
types[ii] = QMetaType::QObjectStar;
QMetaPropertyBuilder prop = mob.addProperty(name, "QObject*");
prop.setWritable(false);
diff --git a/src/declarative/qml/qmlcompiledbindings.cpp b/src/declarative/qml/qmlcompiledbindings.cpp
index cdea96f..b5fbab9 100644
--- a/src/declarative/qml/qmlcompiledbindings.cpp
+++ b/src/declarative/qml/qmlcompiledbindings.cpp
@@ -1682,7 +1682,7 @@ bool QmlBindingCompilerPrivate::compile(QmlJS::AST::Node *node)
} else if (type.type == destination->type) {
} else {
const QMetaObject *from = type.metaObject;
- const QMetaObject *to = QmlMetaType::rawMetaObjectForType(destination->type);
+ const QMetaObject *to = engine->rawMetaObjectForType(destination->type);
if (QmlMetaPropertyPrivate::canConvert(from, to))
type.type = destination->type;
@@ -2420,7 +2420,7 @@ bool QmlBindingCompilerPrivate::fetch(Result &rv, const QMetaObject *mo, int reg
fetch.fetch.exceptionId = exceptionId(node);
rv.type = prop.userType();
- rv.metaObject = QmlMetaType::metaObjectForType(rv.type);
+ rv.metaObject = engine->metaObjectForType(rv.type);
rv.reg = reg;
if (rv.type == QMetaType::QString) {
diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp
index 4c6dc6f..d9fc76b 100644
--- a/src/declarative/qml/qmlcontext.cpp
+++ b/src/declarative/qml/qmlcontext.cpp
@@ -383,23 +383,26 @@ void QmlContext::setContextProperty(const QString &name, const QVariant &value)
if (d->notifyIndex == -1)
d->notifyIndex = this->metaObject()->methodCount();
- if (d->engine && QmlEnginePrivate::get(d->engine)->isObject(value.userType())) {
- QObject *o = *(QObject **)value.constData();
- setContextProperty(name, o);
- } else {
+ if (d->engine) {
+ bool ok;
+ QObject *o = QmlEnginePrivate::get(d->engine)->toQObject(value, &ok);
+ if (ok) {
+ setContextProperty(name, o);
+ return;
+ }
+ }
- if (!d->propertyNames) d->propertyNames = new QmlIntegerCache(d->engine);
+ if (!d->propertyNames) d->propertyNames = new QmlIntegerCache(d->engine);
- int idx = d->propertyNames->value(name);
- if (idx == -1) {
- d->propertyNames->add(name, d->idValueCount + d->propertyValues.count());
- d->propertyValues.append(value);
+ int idx = d->propertyNames->value(name);
+ if (idx == -1) {
+ d->propertyNames->add(name, d->idValueCount + d->propertyValues.count());
+ d->propertyValues.append(value);
- d->refreshExpressions();
- } else {
- d->propertyValues[idx] = value;
- QMetaObject::activate(this, idx + d->notifyIndex, 0);
- }
+ d->refreshExpressions();
+ } else {
+ d->propertyValues[idx] = value;
+ QMetaObject::activate(this, idx + d->notifyIndex, 0);
}
}
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 372821e..cdbe5f3 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -1085,9 +1085,10 @@ QScriptValue QmlEnginePrivate::tint(QScriptContext *ctxt, QScriptEngine *engine)
QScriptValue QmlEnginePrivate::scriptValueFromVariant(const QVariant &val)
{
- if (QmlMetaType::isObject(val.userType())) {
- QObject *rv = *(QObject **)val.constData();
- return objectClass->newQObject(rv);
+ bool objOk;
+ QObject *obj = QmlMetaType::toQObject(val, &objOk);
+ if (objOk) {
+ return objectClass->newQObject(obj);
} else {
return qScriptValueFromValue(&scriptEngine, val);
}
@@ -1598,9 +1599,20 @@ bool QmlEnginePrivate::isQmlList(int t) const
return m_qmlLists.contains(t) || QmlMetaType::isQmlList(t);
}
-bool QmlEnginePrivate::isObject(int t)
+bool QmlEnginePrivate::isQObject(int t)
{
- return m_compositeTypes.contains(t) || QmlMetaType::isObject(t);
+ return m_compositeTypes.contains(t) || QmlMetaType::isQObject(t);
+}
+
+QObject *QmlEnginePrivate::toQObject(const QVariant &v, bool *ok) const
+{
+ int t = v.userType();
+ if (m_compositeTypes.contains(t)) {
+ if (ok) *ok = true;
+ return *(QObject **)(v.constData());
+ } else {
+ return QmlMetaType::toQObject(v, ok);
+ }
}
int QmlEnginePrivate::qmlListType(int t) const
@@ -1628,7 +1640,8 @@ const QMetaObject *QmlEnginePrivate::rawMetaObjectForType(int t) const
if (iter != m_compositeTypes.end()) {
return (*iter)->root;
} else {
- return QmlMetaType::rawMetaObjectForType(t);
+ QmlType *type = QmlMetaType::qmlType(t);
+ return type?type->baseMetaObject():0;
}
}
@@ -1638,7 +1651,8 @@ const QMetaObject *QmlEnginePrivate::metaObjectForType(int t) const
if (iter != m_compositeTypes.end()) {
return (*iter)->root;
} else {
- return QmlMetaType::metaObjectForType(t);
+ QmlType *type = QmlMetaType::qmlType(t);
+ return type?type->metaObject():0;
}
}
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 8349090..13ed5ef 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -268,7 +268,8 @@ public:
void registerCompositeType(QmlCompiledData *);
bool isQmlList(int) const;
- bool isObject(int);
+ bool isQObject(int);
+ QObject *toQObject(const QVariant &, bool *ok = 0) const;
int qmlListType(int) const;
QmlMetaType::TypeCategory typeCategory(int) const;
const QMetaObject *rawMetaObjectForType(int) const;
diff --git a/src/declarative/qml/qmlenginedebug.cpp b/src/declarative/qml/qmlenginedebug.cpp
index 2abd6e6..b0c1ec9 100644
--- a/src/declarative/qml/qmlenginedebug.cpp
+++ b/src/declarative/qml/qmlenginedebug.cpp
@@ -117,7 +117,7 @@ QmlEngineDebugServer::propertyData(QObject *obj, int propIdx)
if (QVariant::Type(prop.userType()) < QVariant::UserType) {
rv.type = QmlObjectProperty::Basic;
- } else if (QmlMetaType::isObject(prop.userType())) {
+ } else if (QmlMetaType::isQObject(prop.userType())) {
rv.type = QmlObjectProperty::Object;
} else if (QmlMetaType::isList(prop.userType()) ||
QmlMetaType::isQmlList(prop.userType())) {
@@ -140,7 +140,7 @@ QVariant QmlEngineDebugServer::valueContents(const QVariant &value) const
for (int i=0; i<count; i++)
contents << valueContents(QmlMetaType::listAt(value, i));
return contents;
- } else if (QmlMetaType::isObject(userType)) {
+ } else if (QmlMetaType::isQObject(userType)) {
QObject *o = QmlMetaType::toQObject(value);
if (o) {
QString name = o->objectName();
diff --git a/src/declarative/qml/qmlguard_p.h b/src/declarative/qml/qmlguard_p.h
index 42a4406..1e55bcb 100644
--- a/src/declarative/qml/qmlguard_p.h
+++ b/src/declarative/qml/qmlguard_p.h
@@ -94,6 +94,8 @@ private:
inline void remGuard();
};
+Q_DECLARE_METATYPE(QmlGuard<QObject>);
+
QT_END_NAMESPACE
#include "qmldeclarativedata_p.h"
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 09c936e..f23a50a 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -852,17 +852,13 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data
} else if (property.flags & QmlPropertyCache::Data::IsQObjectDerived) {
- const QMetaObject *valMo = 0;
- if (enginePriv) valMo = enginePriv->rawMetaObjectForType(value.userType());
- else valMo = QmlMetaType::rawMetaObjectForType(value.userType());
+ const QMetaObject *valMo = rawMetaObjectForType(enginePriv, value.userType());
if (!valMo)
return false;
QObject *o = *(QObject **)value.constData();
- const QMetaObject *propMo = 0;
- if (enginePriv) propMo = enginePriv->rawMetaObjectForType(t);
- else propMo = QmlMetaType::rawMetaObjectForType(t);
+ const QMetaObject *propMo = rawMetaObjectForType(enginePriv, t);
if (o) valMo = o->metaObject();
@@ -892,7 +888,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data
QVariant listVar = prop.read(object);
QmlMetaType::clear(listVar);
for (int ii = 0; ii < list.count(); ++ii) {
- QVariant v = QmlMetaType::fromObject(list.at(ii), listType);
+ QVariant v = QmlMetaType::qmlType(listType)->fromObject(list.at(ii));
QmlMetaType::append(listVar, v);
}
@@ -913,8 +909,7 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data
int type = li->type();
if (QObject *obj = QmlMetaType::toQObject(value)) {
- const QMetaObject *mo =
- QmlMetaType::rawMetaObjectForType(type);
+ const QMetaObject *mo = rawMetaObjectForType(enginePriv, type);
const QMetaObject *objMo = obj->metaObject();
bool found = false;
@@ -966,6 +961,16 @@ bool QmlMetaPropertyPrivate::write(QObject *object, const QmlPropertyCache::Data
return true;
}
+const QMetaObject *QmlMetaPropertyPrivate::rawMetaObjectForType(QmlEnginePrivate *engine, int userType)
+{
+ if (engine) {
+ return engine->rawMetaObjectForType(userType);
+ } else {
+ QmlType *type = QmlMetaType::qmlType(userType);
+ return type?type->baseMetaObject():0;
+ }
+}
+
/*!
Set the property value to \a value.
*/
diff --git a/src/declarative/qml/qmlmetaproperty_p.h b/src/declarative/qml/qmlmetaproperty_p.h
index 97b5208..90b443e 100644
--- a/src/declarative/qml/qmlmetaproperty_p.h
+++ b/src/declarative/qml/qmlmetaproperty_p.h
@@ -63,6 +63,7 @@
QT_BEGIN_NAMESPACE
class QmlContext;
+class QmlEnginePrivate;
class QmlMetaPropertyPrivate
{
public:
@@ -102,6 +103,8 @@ public:
QVariant readValueProperty();
bool writeValueProperty(const QVariant &, QmlMetaProperty::WriteFlags);
+
+ static const QMetaObject *rawMetaObjectForType(QmlEnginePrivate *, int);
static bool writeEnumProperty(const QMetaProperty &prop, int idx, QObject *object, const QVariant &value, int flags);
static bool write(QObject *, const QmlPropertyCache::Data &, const QVariant &, QmlContext *,
QmlMetaProperty::WriteFlags flags = 0);
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index d9c007d..e66f600 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -43,6 +43,7 @@
#include "qmlproxymetaobject_p.h"
#include "qmlcustomparser_p.h"
+#include "qmlguard_p.h"
#include <QtCore/qdebug.h>
#include <QtCore/qstringlist.h>
@@ -490,48 +491,26 @@ int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Fun
return index;
}
-int QmlMetaType::qmlParserStatusCast(int userType)
+QObject *QmlMetaType::toQObject(const QVariant &v, bool *ok)
{
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
- QmlType *type = data->idToType.value(userType);
- if (type && type->typeId() == userType)
- return type->parserStatusCast();
- else
- return -1;
-}
+ if (!isQObject(v.userType())) {
+ if (ok) *ok = false;
+ return 0;
+ }
-int QmlMetaType::qmlPropertyValueSourceCast(int userType)
-{
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
- QmlType *type = data->idToType.value(userType);
- if (type && type->typeId() == userType)
- return type->propertyValueSourceCast();
- else
- return -1;
-}
+ if (ok) *ok = true;
-int QmlMetaType::qmlPropertyValueInterceptorCast(int userType)
-{
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
- QmlType *type = data->idToType.value(userType);
- if (type && type->typeId() == userType)
- return type->propertyValueInterceptorCast();
- else
- return -1;
+ return *(QObject **)v.constData();
}
-QObject *QmlMetaType::toQObject(const QVariant &v)
+bool QmlMetaType::isQObject(int userType)
{
- if (!isObject(v.userType()))
- return 0;
+ if (userType == QMetaType::QObjectStar)
+ return true;
- // NOTE: This assumes a cast to QObject does not alter the
- // object pointer
- QObject *rv = *(QObject **)v.constData();
- return rv;
+ QReadLocker lock(metaTypeDataLock());
+ QmlMetaTypeData *data = metaTypeData();
+ return userType >= 0 && userType < data->objects.size() && data->objects.testBit(userType);
}
/*
@@ -593,46 +572,6 @@ bool QmlMetaType::append(const QVariant &list, const QVariant &item)
}
}
-QVariant QmlMetaType::fromObject(QObject *obj, int typeId)
-{
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
-
- QmlType *type = data->idToType.value(typeId);
- if (type && type->typeId() == typeId)
- return type->fromObject(obj);
- else
- return QVariant();
-}
-
-const QMetaObject *QmlMetaType::rawMetaObjectForType(int id)
-{
- if (id == QMetaType::QObjectStar)
- return &QObject::staticMetaObject;
-
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
-
- QmlType *type = data->idToType.value(id);
- if (type && type->typeId() == id)
- return type->baseMetaObject();
- else
- return 0;
-}
-
-const QMetaObject *QmlMetaType::metaObjectForType(int id)
-{
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
- QmlType *type = data->idToType.value(id);
- lock.unlock();
-
- if (type && type->typeId() == id)
- return type->metaObject();
- else
- return 0;
-}
-
int QmlMetaType::attachedPropertiesFuncId(const QMetaObject *mo)
{
QReadLocker lock(metaTypeDataLock());
@@ -706,29 +645,6 @@ QMetaMethod QmlMetaType::defaultMethod(QObject *obj)
return defaultMethod(metaObject);
}
-/*!
- */
-QMetaProperty QmlMetaType::property(QObject *obj, const QByteArray &bname)
-{
- return property(obj, bname.constData());
-}
-
-/*!
- */
-QMetaProperty QmlMetaType::property(QObject *obj, const char *name)
-{
- if (!obj)
- return QMetaProperty();
-
- const QMetaObject *metaObject = obj->metaObject();
-
- int idx = metaObject->indexOfProperty(name);
- if (-1 == idx)
- return QMetaProperty();
-
- return metaObject->property(idx);
-}
-
QmlMetaType::TypeCategory QmlMetaType::typeCategory(int userType)
{
if (userType < 0)
@@ -748,16 +664,6 @@ QmlMetaType::TypeCategory QmlMetaType::typeCategory(int userType)
return Unknown;
}
-bool QmlMetaType::isObject(int userType)
-{
- if (userType == QMetaType::QObjectStar)
- return true;
-
- QReadLocker lock(metaTypeDataLock());
- QmlMetaTypeData *data = metaTypeData();
- return userType >= 0 && userType < data->objects.size() && data->objects.testBit(userType);
-}
-
bool QmlMetaType::isInterface(int userType)
{
QReadLocker lock(metaTypeDataLock());
@@ -884,6 +790,10 @@ QmlType *QmlMetaType::qmlType(const QByteArray &name, int version_major, int ver
return 0;
}
+/*!
+ Returns the type (if any) that corresponds to the \a metaObject. Returns null if no
+ type is registered.
+*/
QmlType *QmlMetaType::qmlType(const QMetaObject *metaObject)
{
QReadLocker lock(metaTypeDataLock());
@@ -892,6 +802,25 @@ QmlType *QmlMetaType::qmlType(const QMetaObject *metaObject)
return data->metaObjectToType.value(metaObject);
}
+/*!
+ Returns the type (if any) that corresponds to the QVariant::Type \a userType.
+ Returns null if no type is registered.
+*/
+QmlType *QmlMetaType::qmlType(int userType)
+{
+ QReadLocker lock(metaTypeDataLock());
+ QmlMetaTypeData *data = metaTypeData();
+
+ QmlType *type = data->idToType.value(userType);
+ if (type && type->typeId() == userType)
+ return type;
+ else
+ return 0;
+}
+
+/*!
+ Returns the list of registered QML type names.
+*/
QList<QByteArray> QmlMetaType::qmlTypeNames()
{
QReadLocker lock(metaTypeDataLock());
@@ -900,6 +829,9 @@ QList<QByteArray> QmlMetaType::qmlTypeNames()
return data->nameToType.keys();
}
+/*!
+ Returns the list of registered QML types.
+*/
QList<QmlType*> QmlMetaType::qmlTypes()
{
QReadLocker lock(metaTypeDataLock());
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index e0c65c5..45ec11d 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -72,23 +72,19 @@ public:
static QmlType *qmlType(const QByteArray &, int, int);
static QmlType *qmlType(const QMetaObject *);
+ static QmlType *qmlType(int);
static QMetaProperty defaultProperty(const QMetaObject *);
static QMetaProperty defaultProperty(QObject *);
static QMetaMethod defaultMethod(const QMetaObject *);
static QMetaMethod defaultMethod(QObject *);
- static QMetaProperty property(QObject *, const QByteArray &);
- static QMetaProperty property(QObject *, const char *);
- static QObject *toQObject(const QVariant &);
- static int qmlParserStatusCast(int);
- static int qmlPropertyValueSourceCast(int);
- static int qmlPropertyValueInterceptorCast(int);
+
+ static bool isQObject(int);
+ static QObject *toQObject(const QVariant &, bool *ok = 0);
+
static int listType(int);
static bool clear(const QVariant &);
static bool append(const QVariant &, const QVariant &);
- static QVariant fromObject(QObject *, int type);
- static const QMetaObject *rawMetaObjectForType(int);
- static const QMetaObject *metaObjectForType(int);
static int attachedPropertiesFuncId(const QMetaObject *);
static QmlAttachedPropertiesFunc attachedPropertiesFuncById(int);
@@ -97,7 +93,6 @@ public:
static bool isInterface(int);
static const char *interfaceIId(int);
- static bool isObject(int);
static bool isList(int);
static bool isList(const QVariant &);
static bool isQmlList(int);