summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml
diff options
context:
space:
mode:
authorWarwick Allison <warwick.allison@nokia.com>2010-02-09 21:39:42 (GMT)
committerWarwick Allison <warwick.allison@nokia.com>2010-02-09 21:39:42 (GMT)
commit4adf3144d79cf3affe2b83dabf5333134b6ec6f7 (patch)
treee6b0a817300eb4a195ee92e5c6c6a19ed4a36f60 /src/declarative/qml
parent9a3b5988a089429e016334a434023bc5c992f0ed (diff)
parent969b61f508294d1f683e09e78641127d0f0def05 (diff)
downloadQt-4adf3144d79cf3affe2b83dabf5333134b6ec6f7.zip
Qt-4adf3144d79cf3affe2b83dabf5333134b6ec6f7.tar.gz
Qt-4adf3144d79cf3affe2b83dabf5333134b6ec6f7.tar.bz2
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt-qml
Diffstat (limited to 'src/declarative/qml')
-rw-r--r--src/declarative/qml/qml.h4
-rw-r--r--src/declarative/qml/qmlengine.cpp1
-rw-r--r--src/declarative/qml/qmllist.h66
-rw-r--r--src/declarative/qml/qmllistscriptclass.cpp57
-rw-r--r--src/declarative/qml/qmllistscriptclass_p.h2
-rw-r--r--src/declarative/qml/qmlmetaproperty.cpp3
-rw-r--r--src/declarative/qml/qmlmetatype.cpp66
-rw-r--r--src/declarative/qml/qmlmetatype.h49
-rw-r--r--src/declarative/qml/qmlobjectscriptclass.cpp2
-rw-r--r--src/declarative/qml/qmlprivate.h163
-rw-r--r--src/declarative/qml/qmlvme.cpp26
11 files changed, 167 insertions, 272 deletions
diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h
index c009093..859fd66 100644
--- a/src/declarative/qml/qml.h
+++ b/src/declarative/qml/qml.h
@@ -59,11 +59,11 @@ QT_MODULE(Declarative)
#define QML_DECLARE_TYPE(TYPE) \
Q_DECLARE_METATYPE(TYPE *) \
- Q_DECLARE_METATYPE(QList<TYPE *> *) \
+ Q_DECLARE_METATYPE(QmlListProperty<TYPE>) \
Q_DECLARE_METATYPE(QmlList<TYPE *> *)
#define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \
- Q_DECLARE_METATYPE(QList<TYPE *> *) \
+ Q_DECLARE_METATYPE(QmlListProperty<TYPE>) \
Q_DECLARE_METATYPE(QmlList<TYPE *> *)
#define QML_DECLARE_INTERFACE(INTERFACE) \
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index f4dcb7a..81988ed 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -543,6 +543,7 @@ void QmlEngine::setContextForObject(QObject *object, QmlContext *context)
data->context = context;
data->nextContextObject = context->d_func()->contextObjects;
data->prevContextObject = &context->d_func()->contextObjects;
+ context->d_func()->contextObjects = data;
}
void qmlExecuteDeferred(QObject *object)
diff --git a/src/declarative/qml/qmllist.h b/src/declarative/qml/qmllist.h
index ad2d874..b1a81c4 100644
--- a/src/declarative/qml/qmllist.h
+++ b/src/declarative/qml/qmllist.h
@@ -119,6 +119,72 @@ class Qml_ProxyList_ ##ListName : public QmlList<ListType> \
friend class Qml_ProxyList_ ##ListName ; \
Qml_ProxyList_##ListName ListName;
+template<typename T>
+struct QmlListProperty {
+ typedef void (*AppendFunction)(QmlListProperty<T> *, T*);
+ typedef int (*CountFunction)(QmlListProperty<T> *);
+ typedef T *(*AtFunction)(QmlListProperty<T> *, int);
+ typedef void (*ClearFunction)(QmlListProperty<T> *);
+ typedef void (*InsertFunction)(QmlListProperty<T> *, int, T *);
+ typedef void (*RemoveAtFunction)(QmlListProperty<T> *, int);
+
+ QmlListProperty()
+ : version(1), object(0), data(0), append(0), count(0), at(0), clear(0), insert(0), removeAt(0) {}
+ QmlListProperty(QObject *o, QList<T *> &list)
+ : version(1), object(o), data(&list), append(qlist_append), count(qlist_count), at(qlist_at),
+ clear(qlist_clear), insert(qlist_insert), removeAt(qlist_removeAt) {}
+ QmlListProperty(QObject *o, void *d, AppendFunction a, CountFunction c = 0, AtFunction t = 0,
+ ClearFunction l = 0, InsertFunction i = 0, RemoveAtFunction r = 0)
+ : version(1), object(o), data(d), append(a), count(c), at(t), clear(l), insert(i), removeAt(r) {}
+
+ bool operator==(const QmlListProperty &o) const {
+ return version == o.version &&
+ object == o.object &&
+ data == o.data &&
+ append == o.append &&
+ count == o.count &&
+ at == o.at &&
+ clear == o.clear &&
+ insert == o.insert &&
+ removeAt == o.removeAt;
+ }
+
+ int version;
+
+ QObject *object;
+ void *data;
+
+ AppendFunction append;
+
+ CountFunction count;
+ AtFunction at;
+
+ ClearFunction clear;
+
+ InsertFunction insert;
+ RemoveAtFunction removeAt;
+
+private:
+ static void qlist_append(QmlListProperty *p, T *v) {
+ ((QList<T *> *)p->data)->append(v);
+ }
+ static int qlist_count(QmlListProperty *p) {
+ return ((QList<T *> *)p->data)->count();
+ }
+ static T *qlist_at(QmlListProperty *p, int idx) {
+ return ((QList<T *> *)p->data)->at(idx);
+ }
+ static void qlist_clear(QmlListProperty *p) {
+ return ((QList<T *> *)p->data)->clear();
+ }
+ static void qlist_insert(QmlListProperty *p, int idx, T *v) {
+ return ((QList<T *> *)p->data)->insert(idx, v);
+ }
+ static void qlist_removeAt(QmlListProperty *p, int idx) {
+ return ((QList<T *> *)p->data)->removeAt(idx);
+ }
+};
+
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/declarative/qml/qmllistscriptclass.cpp b/src/declarative/qml/qmllistscriptclass.cpp
index d4cdc6e..caa4e4e 100644
--- a/src/declarative/qml/qmllistscriptclass.cpp
+++ b/src/declarative/qml/qmllistscriptclass.cpp
@@ -111,27 +111,31 @@ QmlListScriptClass::ScriptValue QmlListScriptClass::property(Object *obj, const
if (!data->object)
return Value();
- void *list = 0;
- void *args[] = { &list, 0 };
- QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
- data->propertyIdx, args);
+ if (data->type == ListProperty) {
+ QmlListProperty<QObject> list;
+ void *args[] = { &list, 0 };
- if (!list)
- return Value();
-
- if (data->type == QListPtr) {
- const QList<QObject *> &qlist = *((QList<QObject *>*)list);
+ QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
+ data->propertyIdx, args);
- quint32 count = qlist.count();
+ quint32 count = list.count(&list);
if (name == m_lengthId.identifier)
return Value(scriptEngine, count);
else if (lastIndex < count)
- return Value(scriptEngine, enginePriv->objectClass->newQObject(qlist.at(lastIndex)));
+ return Value(scriptEngine, enginePriv->objectClass->newQObject(list.at(&list, lastIndex)));
else
return Value();
} else {
+ void *list = 0;
+ void *args[] = { &list, 0 };
+ QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
+ data->propertyIdx, args);
+
+ if (!list)
+ return Value();
+
Q_ASSERT(data->type == QmlListPtr);
const QmlList<QObject *> &qmllist = *((QmlList<QObject *>*)list);
@@ -155,18 +159,29 @@ QVariant QmlListScriptClass::toVariant(Object *obj, bool *ok)
return QVariant();
}
- void *list = 0;
- void *args[] = { &list, 0 };
- QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
- data->propertyIdx, args);
+ if (data->type == QmlListScriptClass::QmlListPtr) {
+ void *list = 0;
+ void *args[] = { &list, 0 };
+ QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
+ data->propertyIdx, args);
- if (!list) {
- if (ok) *ok = false;
- return QVariant();
- }
+ if (!list) {
+ if (ok) *ok = false;
+ return QVariant();
+ }
+
+ if (ok) *ok = true;
+ return QVariant(data->propertyType, &list);
+ } else {
+ QmlListProperty<QObject> list;
+ void *args[] = { &list, 0 };
+
+ QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
+ data->propertyIdx, args);
- if (ok) *ok = true;
- return QVariant(data->propertyType, &list);
+ if (ok) *ok = true;
+ return QVariant(data->propertyType, &list);
+ }
}
QT_END_NAMESPACE
diff --git a/src/declarative/qml/qmllistscriptclass_p.h b/src/declarative/qml/qmllistscriptclass_p.h
index e484b34..464f91e 100644
--- a/src/declarative/qml/qmllistscriptclass_p.h
+++ b/src/declarative/qml/qmllistscriptclass_p.h
@@ -64,7 +64,7 @@ public:
QmlListScriptClass(QmlEngine *);
~QmlListScriptClass();
- enum ListCategory { QListPtr, QmlListPtr };
+ enum ListCategory { ListProperty, QmlListPtr };
QScriptValue newList(QObject *, int, ListCategory, int);
protected:
diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp
index 09c936e..a0857df 100644
--- a/src/declarative/qml/qmlmetaproperty.cpp
+++ b/src/declarative/qml/qmlmetaproperty.cpp
@@ -892,7 +892,8 @@ 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);
+ QObject *o = list.at(ii);
+ QVariant v = QVariant(listType, &o);
QmlMetaType::append(listVar, v);
}
diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp
index d9c007d..973f04f 100644
--- a/src/declarative/qml/qmlmetatype.cpp
+++ b/src/declarative/qml/qmlmetatype.cpp
@@ -124,7 +124,7 @@ public:
int m_version_maj;
int m_version_min;
int m_typeId; int m_listId; int m_qmlListId;
- QmlPrivate::Func m_opFunc;
+ QObject *(*m_newFunc)();
const QMetaObject *m_baseMetaObject;
QmlAttachedPropertiesFunc m_attachedPropertiesFunc;
const QMetaObject *m_attachedPropertiesType;
@@ -141,15 +141,14 @@ public:
QmlTypePrivate::QmlTypePrivate()
: m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0),
- m_opFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
+ m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0),
m_parserStatusCast(-1), m_propertyValueSourceCast(-1), m_propertyValueInterceptorCast(-1),
m_extFunc(0), m_extMetaObject(0), m_index(-1), m_customParser(0), m_isSetup(false)
{
}
-QmlType::QmlType(int type, int listType, int qmlListType,
- QmlPrivate::Func opFunc, const char *iid, int index)
+QmlType::QmlType(int type, int listType, int qmlListType, const char *iid, int index)
: d(new QmlTypePrivate)
{
d->m_isInterface = true;
@@ -157,7 +156,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
d->m_typeId = type;
d->m_listId = listType;
d->m_qmlListId = qmlListType;
- d->m_opFunc = opFunc;
+ d->m_newFunc = 0;
d->m_index = index;
d->m_isSetup = true;
d->m_version_maj = 0;
@@ -165,7 +164,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
}
QmlType::QmlType(int type, int listType, int qmlListType,
- QmlPrivate::Func opFunc, const char *qmlName,
+ QObject *(*newFunc)(), const char *qmlName,
int version_maj, int version_min,
const QMetaObject *metaObject,
QmlAttachedPropertiesFunc attachedPropertiesFunc,
@@ -182,7 +181,7 @@ QmlType::QmlType(int type, int listType, int qmlListType,
d->m_typeId = type;
d->m_listId = listType;
d->m_qmlListId = qmlListType;
- d->m_opFunc = opFunc;
+ d->m_newFunc = newFunc;
d->m_baseMetaObject = metaObject;
d->m_attachedPropertiesFunc = attachedPropertiesFunc;
d->m_attachedPropertiesType = attachedType;
@@ -282,10 +281,7 @@ QObject *QmlType::create() const
{
d->init();
- QVariant v;
- QObject *rv = 0;
- d->m_opFunc(QmlPrivate::Create, 0, v, v, (void **)&rv);
-
+ QObject *rv = d->m_newFunc();
if (rv && !d->m_metaObjects.isEmpty())
(void *)new QmlProxyMetaObject(rv, &d->m_metaObjects);
@@ -320,29 +316,35 @@ int QmlType::qmlListTypeId() const
void QmlType::listClear(const QVariant &list)
{
Q_ASSERT(list.userType() == qListTypeId());
- QVariant arg;
- d->m_opFunc(QmlPrivate::Clear, 0, list, arg, 0);
+ QmlListProperty<void> *l = (QmlListProperty<void> *)list.data();
+ if (l->clear) l->clear(l);
}
void QmlType::listAppend(const QVariant &list, const QVariant &item)
{
Q_ASSERT(list.userType() == qListTypeId());
- d->m_opFunc(QmlPrivate::Append, 0, list, item, 0);
+ QmlListProperty<void> *l = (QmlListProperty<void> *)list.data();
+ if (l->append) l->append(l, *(void **)item.data());
}
QVariant QmlType::listAt(const QVariant &list, int idx)
{
Q_ASSERT(list.userType() == qListTypeId());
- QVariant rv;
- void *ptr = (void *)&rv;
- d->m_opFunc(QmlPrivate::Value, idx, list, QVariant(), &ptr);
- return rv;
+ QmlListProperty<void> *l = (QmlListProperty<void> *)list.data();
+ if (l->at) {
+ void *v = l->at(l, idx);
+ return QVariant(typeId(), &v);
+ } else {
+ return QVariant();
+ }
}
int QmlType::listCount(const QVariant &list)
{
Q_ASSERT(list.userType() == qListTypeId());
- return d->m_opFunc(QmlPrivate::Length, 0, list, QVariant(), 0);
+ QmlListProperty<void> *l = (QmlListProperty<void> *)list.data();
+ if (l->count) return l->count(l);
+ return 0;
}
const QMetaObject *QmlType::metaObject() const
@@ -386,15 +388,6 @@ int QmlType::propertyValueInterceptorCast() const
return d->m_propertyValueInterceptorCast;
}
-QVariant QmlType::fromObject(QObject *obj) const
-{
- QVariant rv;
- QVariant *v_ptr = &rv;
- QVariant vobj = QVariant::fromValue(obj);
- d->m_opFunc(QmlPrivate::FromObject, 0, QVariant(), vobj, (void **)&v_ptr);
- return rv;
-}
-
const char *QmlType::interfaceIId() const
{
return d->m_iid;
@@ -406,7 +399,6 @@ int QmlType::index() const
}
int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
- QmlPrivate::Func listFunction,
const char *iid)
{
QWriteLocker lock(metaTypeDataLock());
@@ -415,7 +407,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
int index = data->types.count();
QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId,
- listFunction, iid, index);
+ iid, index);
data->types.append(type);
data->idToType.insert(type->typeId(), type);
@@ -438,7 +430,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id,
return index;
}
-int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func func,
+int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QObject *(*func)(),
const char *uri, int version_maj, int version_min, const char *cname,
const QMetaObject *mo, QmlAttachedPropertiesFunc attach, const QMetaObject *attachMo,
int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *parser)
@@ -593,18 +585,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)
diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h
index e0c65c5..32174ff 100644
--- a/src/declarative/qml/qmlmetatype.h
+++ b/src/declarative/qml/qmlmetatype.h
@@ -46,6 +46,7 @@
#include "qmlparserstatus.h"
#include "qmlpropertyvaluesource.h"
#include "qmlpropertyvalueinterceptor.h"
+#include "qmllist.h"
#include <QtCore/qglobal.h>
#include <QtCore/qvariant.h>
@@ -62,8 +63,8 @@ class QmlCustomParser;
class Q_DECLARATIVE_EXPORT QmlMetaType
{
public:
- static int registerType(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *, int vmaj, int vmin, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
- static int registerInterface(const QmlPrivate::MetaTypeIds &, QmlPrivate::Func, const char *);
+ static int registerType(const QmlPrivate::MetaTypeIds &, QObject *(*)(), const char *, int vmaj, int vmin, const char *qmlName, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int pStatus, int object, int valueSource, int valueInterceptor, QmlPrivate::CreateFunc extFunc, const QMetaObject *extmo, QmlCustomParser *);
+ static int registerInterface(const QmlPrivate::MetaTypeIds &, const char *);
static bool copy(int type, void *data, const void *copy = 0);
@@ -86,7 +87,6 @@ public:
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 *);
@@ -142,7 +142,6 @@ public:
const QMetaObject *attachedPropertiesType() const;
int parserStatusCast() const;
- QVariant fromObject(QObject *) const;
const char *interfaceIId() const;
int propertyValueSourceCast() const;
int propertyValueInterceptorCast() const;
@@ -152,8 +151,8 @@ private:
friend class QmlMetaType;
friend class QmlTypePrivate;
friend struct QmlMetaTypeData;
- QmlType(int, int, int, QmlPrivate::Func, const char *, int);
- QmlType(int, int, int, QmlPrivate::Func, const char *, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
+ QmlType(int, int, int, const char *, int);
+ QmlType(int, int, int, QObject *(*)(), const char *, int, int, const QMetaObject *, QmlAttachedPropertiesFunc, const QMetaObject *, int, int, int, QmlPrivate::CreateFunc, const QMetaObject *, int, QmlCustomParser *);
~QmlType();
QmlTypePrivate *d;
@@ -165,11 +164,11 @@ int qmlRegisterType(const char *typeName)
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
- return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0,
+ return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
QmlPrivate::attachedPropertiesMetaObject<T>(),
@@ -186,11 +185,11 @@ int qmlRegisterType(const char *uri, int version_maj, int version_min, const cha
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
- return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
+ return QmlMetaType::registerType(ids, QmlPrivate::create<T>,
uri, version_maj, version_min, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
@@ -208,8 +207,8 @@ int qmlRegisterExtendedType(const char *typeName)
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
QmlAttachedPropertiesFunc attached =
@@ -221,7 +220,7 @@ int qmlRegisterExtendedType(const char *typeName)
attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
}
- return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0,
+ return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0,
&T::staticMetaObject, attached, attachedMo,
QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(),
QmlPrivate::StaticCastSelector<T,QObject>::cast(),
@@ -236,8 +235,8 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
QmlAttachedPropertiesFunc attached =
@@ -249,7 +248,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c
attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>();
}
- return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
+ return QmlMetaType::registerType(ids, QmlPrivate::create<T>,
uri, version_maj, version_min, qmlName,
&T::staticMetaObject,
attached, attachedMo,
@@ -267,13 +266,11 @@ int qmlRegisterInterface(const char *typeName)
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
- return QmlMetaType::registerInterface(ids,
- QmlPrivate::list_interface_op<T>,
- qobject_interface_iid<T *>());
+ return QmlMetaType::registerInterface(ids, qobject_interface_iid<T *>());
}
template<typename T>
@@ -282,11 +279,11 @@ int qmlRegisterCustomType(const char *uri, int version_maj, int version_min, con
QByteArray name(typeName);
QmlPrivate::MetaTypeIds ids = {
qRegisterMetaType<T *>(QByteArray(name + '*').constData()),
- qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()),
- qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData())
+ qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()),
+ qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData())
};
- return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>,
+ return QmlMetaType::registerType(ids, QmlPrivate::create<T>,
uri, version_maj, version_min, qmlName,
&T::staticMetaObject,
QmlPrivate::attachedPropertiesFunc<T>(),
diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp
index 7bbb7df..09d326f 100644
--- a/src/declarative/qml/qmlobjectscriptclass.cpp
+++ b/src/declarative/qml/qmlobjectscriptclass.cpp
@@ -238,7 +238,7 @@ QmlObjectScriptClass::property(QObject *obj, const Identifier &name)
}
if (lastData->flags & QmlPropertyCache::Data::IsQList) {
- return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::QListPtr, lastData->propType));
+ return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::ListProperty, lastData->propType));
} else if (lastData->flags & QmlPropertyCache::Data::IsQmlList) {
return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::QmlListPtr, lastData->propType));
} else if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) {
diff --git a/src/declarative/qml/qmlprivate.h b/src/declarative/qml/qmlprivate.h
index dd98110..c367497 100644
--- a/src/declarative/qml/qmlprivate.h
+++ b/src/declarative/qml/qmlprivate.h
@@ -85,26 +85,8 @@ namespace QmlPrivate
virtual void clear() = 0;
};
- enum ListOp { Append, Set, Insert, Prepend, Length, FromObject,
- Object, Create, Value, Clear };
-
- template<typename T>
- int list_op(ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out);
-
template<typename T>
- int list_nocreate_op(ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out);
-
- template<typename T>
- int list_interface_op(ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out);
+ QObject *create() { return new T; }
template<class From, class To, int N>
struct StaticCastSelectorClass
@@ -203,7 +185,6 @@ namespace QmlPrivate
int listId;
int qmlListId;
};
- typedef int (*Func)(QmlPrivate::ListOp, int, const QVariant &, const QVariant &, void **);
typedef QObject *(*CreateFunc)(QObject *);
template<typename T>
@@ -237,148 +218,6 @@ namespace QmlPrivate
};
}
-template<typename T>
-int QmlPrivate::list_op(QmlPrivate::ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out)
-{
- if (op == QmlPrivate::Create) {
- QObject *obj = static_cast<QObject *>(new T);
- *((QObject **)out) = obj;
- return 0;
- }
- QList<T *> *list = vlist.value<QList<T *> *>();
- switch(op) {
- case QmlPrivate::Append:
- list->append(value.value<T *>());
- break;
- case QmlPrivate::Set:
- (*list)[val] = value.value<T *>();
- break;
- case QmlPrivate::Insert:
- list->insert(val, value.value<T *>());
- break;
- case QmlPrivate::Prepend:
- list->prepend(value.value<T *>());
- break;
- case QmlPrivate::Length:
- return list->count();
- break;
- case QmlPrivate::Clear:
- list->clear();
- return 0;
- break;
- case QmlPrivate::Create:
- break;
- case QmlPrivate::Object:
- *out = static_cast<QObject *>(value.value<T *>());
- break;
- case QmlPrivate::FromObject:
- {
- QObject *fromObj = value.value<QObject *>();
- T *me = qobject_cast<T *>(fromObj);
- if (me) {
- *((QVariant *)*out) = QVariant::fromValue(me);
- }
- }
- break;
- case QmlPrivate::Value:
- if (list->count() <= val) *((QVariant *)*out) = QVariant();
- else *((QVariant *)*out) = QVariant::fromValue(list->at(val));
- break;
- }
- return 0;
-}
-
-template<typename T>
-int QmlPrivate::list_nocreate_op(QmlPrivate::ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out)
-{
- QList<T *> *list = vlist.value<QList<T *> *>();
- switch(op) {
- case QmlPrivate::Append:
- list->append(value.value<T *>());
- break;
- case QmlPrivate::Set:
- (*list)[val] = value.value<T *>();
- break;
- case QmlPrivate::Insert:
- list->insert(val, value.value<T *>());
- break;
- case QmlPrivate::Prepend:
- list->prepend(value.value<T *>());
- break;
- case QmlPrivate::Length:
- return list->count();
- break;
- case QmlPrivate::Clear:
- list->clear();
- return 0;
- break;
- case QmlPrivate::Create:
- break;
- case QmlPrivate::Object:
- *out = static_cast<QObject *>(value.value<T *>());
- break;
- case QmlPrivate::FromObject:
- {
- QObject *fromObj = value.value<QObject *>();
- T *me = qobject_cast<T *>(fromObj);
- if (me) {
- *((QVariant *)*out) = QVariant::fromValue(me);
- }
- }
- break;
- case QmlPrivate::Value:
- *((QVariant *)*out) = QVariant::fromValue(list->at(val));
- break;
- }
- return 0;
-}
-
-template<typename T>
-int QmlPrivate::list_interface_op(QmlPrivate::ListOp op, int val,
- const QVariant &vlist,
- const QVariant &value,
- void **out)
-{
- QList<T *> *list = vlist.value<QList<T *> *>();
- switch(op) {
- case QmlPrivate::Append:
- list->append(value.value<T *>());
- break;
- case QmlPrivate::Set:
- (*list)[val] = value.value<T *>();
- break;
- case QmlPrivate::Insert:
- list->insert(val, value.value<T *>());
- break;
- case QmlPrivate::Prepend:
- list->prepend(value.value<T *>());
- break;
- case QmlPrivate::Length:
- return list->count();
- break;
- case QmlPrivate::Clear:
- list->clear();
- return 0;
- break;
- case QmlPrivate::Create:
- break;
- case QmlPrivate::Object:
- break;
- case QmlPrivate::FromObject:
- break;
- case QmlPrivate::Value:
- *((QVariant *)*out) = QVariant::fromValue(list->at(val));
- break;
- }
- return 0;
-}
-
QT_END_NAMESPACE
QT_END_HEADER
diff --git a/src/declarative/qml/qmlvme.cpp b/src/declarative/qml/qmlvme.cpp
index e9a0449..4ab205e 100644
--- a/src/declarative/qml/qmlvme.cpp
+++ b/src/declarative/qml/qmlvme.cpp
@@ -91,14 +91,15 @@ QmlVME::QmlVME()
struct ListInstance
{
- ListInstance() {}
- ListInstance(QList<void *> *q, int t)
- : type(t), qListInterface(q), qmlListInterface(0) {}
+ ListInstance()
+ : type(0), qmlListInterface(0) {}
+ ListInstance(int t)
+ : type(t), qmlListInterface(0) {}
ListInstance(QmlPrivate::ListInterface *q, int t)
- : type(t), qListInterface(0), qmlListInterface(q) {}
+ : type(t), qmlListInterface(q) {}
int type;
- QList<void *> *qListInterface;
+ QmlListProperty<void> qListProperty;
QmlPrivate::ListInterface *qmlListInterface;
};
@@ -669,7 +670,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt,
QObject *assign = stack.pop();
const ListInstance &list = qliststack.top();
- list.qListInterface->append((void *)assign);
+ list.qListProperty.append((QmlListProperty<void>*)&list.qListProperty, assign);
}
break;
@@ -694,7 +695,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt,
void *d = (void *)&ptr;
list.qmlListInterface->append(d);
} else {
- list.qListInterface->append(ptr);
+ list.qListProperty.append((QmlListProperty<void>*)&list.qListProperty, ptr);
}
}
break;
@@ -772,17 +773,12 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt,
{
QObject *target = stack.top();
+ qliststack.push(ListInstance(instr.fetchQmlList.type));
+
void *a[1];
- // We know that QList<T *>* can be converted to
- // QList<void *>*
- QList<void *> *list = 0;
- a[0] = &list;
+ a[0] = (void *)&(qliststack.top().qListProperty);
QMetaObject::metacall(target, QMetaObject::ReadProperty,
instr.fetchQmlList.property, a);
- if (!list)
- VME_EXCEPTION(QCoreApplication::translate("QmlVME","Cannot assign to null list"));
-
- qliststack.push(ListInstance(list, instr.fetchQmlList.type));
}
break;