diff options
author | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-02-17 03:39:45 (GMT) |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy@nokia.com> | 2010-02-17 03:39:45 (GMT) |
commit | 9f12ede32d9eaadde7b1f72cf2191f39d5780d57 (patch) | |
tree | 96bbdc9d95c9cd9e087ab2f7c0d19e18e28a1e4a /src/declarative | |
parent | b4754aa9a3761c1bcd8519280d98e34371f4ff10 (diff) | |
download | Qt-9f12ede32d9eaadde7b1f72cf2191f39d5780d57.zip Qt-9f12ede32d9eaadde7b1f72cf2191f39d5780d57.tar.gz Qt-9f12ede32d9eaadde7b1f72cf2191f39d5780d57.tar.bz2 |
Revert "Replace QList<>* support with QmlListProperty"
This was accidentally pushed early.
This reverts commit 8454c53b304a4aba7c058b315041b3a38ad4fff5.
Diffstat (limited to 'src/declarative')
20 files changed, 307 insertions, 215 deletions
diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index e10c919..2fbf18b 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -892,6 +892,7 @@ void QmlGraphicsKeyNavigationAttached::keyReleased(QKeyEvent *event) parameter provides information about the event. */ + const QmlGraphicsKeysAttached::SigMap QmlGraphicsKeysAttached::sigMap[] = { { Qt::Key_Left, "leftPressed" }, { Qt::Key_Right, "rightPressed" }, diff --git a/src/declarative/graphicsitems/qmlgraphicsitem_p.h b/src/declarative/graphicsitems/qmlgraphicsitem_p.h index 7ebbd85..9a77dbb 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsitem_p.h @@ -381,7 +381,7 @@ class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QmlListProperty<QmlGraphicsItem> forwardTo READ forwardTo) + Q_PROPERTY(QList<QmlGraphicsItem *> *forwardTo READ forwardTo) public: QmlGraphicsKeysAttached(QObject *parent=0); @@ -396,9 +396,9 @@ public: } } - QmlListProperty<QmlGraphicsItem> forwardTo() { + QList<QmlGraphicsItem *> *forwardTo() { Q_D(QmlGraphicsKeysAttached); - return QmlListProperty<QmlGraphicsItem>(this, d->targets); + return &d->targets; } virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index eaf0d88..fae8161 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -155,10 +155,10 @@ bool QmlGraphicsPath::isClosed() const \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 */ -QmlListProperty<QmlGraphicsPathElement> QmlGraphicsPath::pathElements() +QList<QmlGraphicsPathElement *>* QmlGraphicsPath::pathElements() { Q_D(QmlGraphicsPath); - return QmlListProperty<QmlGraphicsPathElement>(this, d->_pathElements); + return &(d->_pathElements); } void QmlGraphicsPath::interpolate(int idx, const QString &name, qreal value) diff --git a/src/declarative/graphicsitems/qmlgraphicspath_p.h b/src/declarative/graphicsitems/qmlgraphicspath_p.h index 50ea15b..2b4b0fd 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath_p.h +++ b/src/declarative/graphicsitems/qmlgraphicspath_p.h @@ -189,7 +189,7 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsPath : public QObject, public QmlParserSta Q_OBJECT Q_INTERFACES(QmlParserStatus) - Q_PROPERTY(QmlListProperty<QmlGraphicsPathElement> pathElements READ pathElements) + Q_PROPERTY(QList<QmlGraphicsPathElement *>* pathElements READ pathElements) Q_PROPERTY(qreal startX READ startX WRITE setStartX) Q_PROPERTY(qreal startY READ startY WRITE setStartY) Q_PROPERTY(bool closed READ isClosed NOTIFY changed) @@ -199,7 +199,7 @@ public: QmlGraphicsPath(QObject *parent=0); ~QmlGraphicsPath(); - QmlListProperty<QmlGraphicsPathElement> pathElements(); + QList<QmlGraphicsPathElement *>* pathElements(); qreal startX() const; void setStartX(qreal x); diff --git a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h index b8c2179..4f4c1cf 100644 --- a/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h +++ b/src/declarative/graphicsitems/qmlgraphicsrectangle_p.h @@ -107,14 +107,14 @@ class Q_DECLARATIVE_EXPORT QmlGraphicsGradient : public QObject { Q_OBJECT - Q_PROPERTY(QmlListProperty<QmlGraphicsGradientStop> stops READ stops) + Q_PROPERTY(QList<QmlGraphicsGradientStop *> *stops READ stops) Q_CLASSINFO("DefaultProperty", "stops") public: QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} ~QmlGraphicsGradient() { delete m_gradient; } - QmlListProperty<QmlGraphicsGradientStop> stops() { return QmlListProperty<QmlGraphicsGradientStop>(this, m_stops); } + QList<QmlGraphicsGradientStop *> *stops() { return &m_stops; } const QGradient *gradient() const; diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index d14fc84..cc416d0 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -423,7 +423,7 @@ int QmlGraphicsVisualDataModelDataMetaObject::createProperty(const char *name, c if ((!model->m_listModelInterface || !model->m_abstractItemModel) && model->m_listAccessor) { if (model->m_listAccessor->type() == QmlListAccessor::QmlList - || model->m_listAccessor->type() == QmlListAccessor::ListProperty) { + || model->m_listAccessor->type() == QmlListAccessor::QListPtr) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value<QObject*>(); if (object && object->property(name).isValid()) @@ -685,7 +685,7 @@ void QmlGraphicsVisualDataModel::setModel(const QVariant &model) } d->m_listAccessor = new QmlListAccessor; d->m_listAccessor->setList(model, d->m_context?d->m_context->engine():qmlEngine(this)); - if (d->m_listAccessor->type() != QmlListAccessor::QmlList && d->m_listAccessor->type() != QmlListAccessor::ListProperty) + if (d->m_listAccessor->type() != QmlListAccessor::QmlList && d->m_listAccessor->type() != QmlListAccessor::QListPtr) d->m_metaDataCacheable = true; if (d->m_delegate && d->modelCount()) { emit itemsInserted(0, d->modelCount()); diff --git a/src/declarative/qml/qml.h b/src/declarative/qml/qml.h index 859fd66..c009093 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(QmlListProperty<TYPE>) \ + Q_DECLARE_METATYPE(QList<TYPE *> *) \ Q_DECLARE_METATYPE(QmlList<TYPE *> *) #define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \ - Q_DECLARE_METATYPE(QmlListProperty<TYPE>) \ + Q_DECLARE_METATYPE(QList<TYPE *> *) \ Q_DECLARE_METATYPE(QmlList<TYPE *> *) #define QML_DECLARE_INTERFACE(INTERFACE) \ diff --git a/src/declarative/qml/qmllist.h b/src/declarative/qml/qmllist.h index b1a81c4..ad2d874 100644 --- a/src/declarative/qml/qmllist.h +++ b/src/declarative/qml/qmllist.h @@ -119,72 +119,6 @@ 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 caa4e4e..d4cdc6e 100644 --- a/src/declarative/qml/qmllistscriptclass.cpp +++ b/src/declarative/qml/qmllistscriptclass.cpp @@ -111,31 +111,27 @@ QmlListScriptClass::ScriptValue QmlListScriptClass::property(Object *obj, const if (!data->object) return Value(); - if (data->type == ListProperty) { - QmlListProperty<QObject> list; - void *args[] = { &list, 0 }; + void *list = 0; + void *args[] = { &list, 0 }; + QMetaObject::metacall(data->object, QMetaObject::ReadProperty, + data->propertyIdx, args); - QMetaObject::metacall(data->object, QMetaObject::ReadProperty, - data->propertyIdx, args); + if (!list) + return Value(); + + if (data->type == QListPtr) { + const QList<QObject *> &qlist = *((QList<QObject *>*)list); - quint32 count = list.count(&list); + quint32 count = qlist.count(); if (name == m_lengthId.identifier) return Value(scriptEngine, count); else if (lastIndex < count) - return Value(scriptEngine, enginePriv->objectClass->newQObject(list.at(&list, lastIndex))); + return Value(scriptEngine, enginePriv->objectClass->newQObject(qlist.at(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); @@ -159,29 +155,18 @@ QVariant QmlListScriptClass::toVariant(Object *obj, bool *ok) return QVariant(); } - 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(); - } + void *list = 0; + void *args[] = { &list, 0 }; + QMetaObject::metacall(data->object, QMetaObject::ReadProperty, + data->propertyIdx, args); - 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 (!list) { + if (ok) *ok = false; + return QVariant(); } + + 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 464f91e..e484b34 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 { ListProperty, QmlListPtr }; + enum ListCategory { QListPtr, QmlListPtr }; QScriptValue newList(QObject *, int, ListCategory, int); protected: diff --git a/src/declarative/qml/qmlmetaproperty.cpp b/src/declarative/qml/qmlmetaproperty.cpp index fc11bd6..70f9ad3 100644 --- a/src/declarative/qml/qmlmetaproperty.cpp +++ b/src/declarative/qml/qmlmetaproperty.cpp @@ -889,8 +889,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) { - QObject *o = list.at(ii); - QVariant v = QVariant(listType, &o); + QVariant v = QmlMetaType::qmlType(listType)->fromObject(list.at(ii)); QmlMetaType::append(listVar, v); } diff --git a/src/declarative/qml/qmlmetatype.cpp b/src/declarative/qml/qmlmetatype.cpp index e613b7c..7dfc48d 100644 --- a/src/declarative/qml/qmlmetatype.cpp +++ b/src/declarative/qml/qmlmetatype.cpp @@ -125,7 +125,7 @@ public: int m_version_maj; int m_version_min; int m_typeId; int m_listId; int m_qmlListId; - QObject *(*m_newFunc)(); + QmlPrivate::Func m_opFunc; const QMetaObject *m_baseMetaObject; QmlAttachedPropertiesFunc m_attachedPropertiesFunc; const QMetaObject *m_attachedPropertiesType; @@ -142,14 +142,15 @@ public: QmlTypePrivate::QmlTypePrivate() : m_isInterface(false), m_iid(0), m_typeId(0), m_listId(0), m_qmlListId(0), - m_newFunc(0), m_baseMetaObject(0), m_attachedPropertiesFunc(0), m_attachedPropertiesType(0), + m_opFunc(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, const char *iid, int index) +QmlType::QmlType(int type, int listType, int qmlListType, + QmlPrivate::Func opFunc, const char *iid, int index) : d(new QmlTypePrivate) { d->m_isInterface = true; @@ -157,7 +158,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, const char *iid, int i d->m_typeId = type; d->m_listId = listType; d->m_qmlListId = qmlListType; - d->m_newFunc = 0; + d->m_opFunc = opFunc; d->m_index = index; d->m_isSetup = true; d->m_version_maj = 0; @@ -165,7 +166,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, const char *iid, int i } QmlType::QmlType(int type, int listType, int qmlListType, - QObject *(*newFunc)(), const char *qmlName, + QmlPrivate::Func opFunc, const char *qmlName, int version_maj, int version_min, const QMetaObject *metaObject, QmlAttachedPropertiesFunc attachedPropertiesFunc, @@ -182,7 +183,7 @@ QmlType::QmlType(int type, int listType, int qmlListType, d->m_typeId = type; d->m_listId = listType; d->m_qmlListId = qmlListType; - d->m_newFunc = newFunc; + d->m_opFunc = opFunc; d->m_baseMetaObject = metaObject; d->m_attachedPropertiesFunc = attachedPropertiesFunc; d->m_attachedPropertiesType = attachedType; @@ -282,7 +283,10 @@ QObject *QmlType::create() const { d->init(); - QObject *rv = d->m_newFunc(); + QVariant v; + QObject *rv = 0; + d->m_opFunc(QmlPrivate::Create, 0, v, v, (void **)&rv); + if (rv && !d->m_metaObjects.isEmpty()) (void *)new QmlProxyMetaObject(rv, &d->m_metaObjects); @@ -317,35 +321,29 @@ int QmlType::qmlListTypeId() const void QmlType::listClear(const QVariant &list) { Q_ASSERT(list.userType() == qListTypeId()); - QmlListProperty<void> *l = (QmlListProperty<void> *)list.data(); - if (l->clear) l->clear(l); + QVariant arg; + d->m_opFunc(QmlPrivate::Clear, 0, list, arg, 0); } void QmlType::listAppend(const QVariant &list, const QVariant &item) { Q_ASSERT(list.userType() == qListTypeId()); - QmlListProperty<void> *l = (QmlListProperty<void> *)list.data(); - if (l->append) l->append(l, *(void **)item.data()); + d->m_opFunc(QmlPrivate::Append, 0, list, item, 0); } QVariant QmlType::listAt(const QVariant &list, int idx) { Q_ASSERT(list.userType() == qListTypeId()); - QmlListProperty<void> *l = (QmlListProperty<void> *)list.data(); - if (l->at) { - void *v = l->at(l, idx); - return QVariant(typeId(), &v); - } else { - return QVariant(); - } + QVariant rv; + void *ptr = (void *)&rv; + d->m_opFunc(QmlPrivate::Value, idx, list, QVariant(), &ptr); + return rv; } int QmlType::listCount(const QVariant &list) { Q_ASSERT(list.userType() == qListTypeId()); - QmlListProperty<void> *l = (QmlListProperty<void> *)list.data(); - if (l->count) return l->count(l); - return 0; + return d->m_opFunc(QmlPrivate::Length, 0, list, QVariant(), 0); } const QMetaObject *QmlType::metaObject() const @@ -389,6 +387,15 @@ 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; @@ -400,6 +407,7 @@ int QmlType::index() const } int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, + QmlPrivate::Func listFunction, const char *iid) { QWriteLocker lock(metaTypeDataLock()); @@ -408,7 +416,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, int index = data->types.count(); QmlType *type = new QmlType(id.typeId, id.listId, id.qmlListId, - iid, index); + listFunction, iid, index); data->types.append(type); data->idToType.insert(type->typeId(), type); @@ -431,7 +439,7 @@ int QmlMetaType::registerInterface(const QmlPrivate::MetaTypeIds &id, return index; } -int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QObject *(*func)(), +int QmlMetaType::registerType(const QmlPrivate::MetaTypeIds &id, QmlPrivate::Func 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) diff --git a/src/declarative/qml/qmlmetatype.h b/src/declarative/qml/qmlmetatype.h index 1d9c096..45ec11d 100644 --- a/src/declarative/qml/qmlmetatype.h +++ b/src/declarative/qml/qmlmetatype.h @@ -46,7 +46,6 @@ #include "qmlparserstatus.h" #include "qmlpropertyvaluesource.h" #include "qmlpropertyvalueinterceptor.h" -#include "qmllist.h" #include <QtCore/qglobal.h> #include <QtCore/qvariant.h> @@ -63,8 +62,8 @@ class QmlCustomParser; class Q_DECLARATIVE_EXPORT QmlMetaType { public: - 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 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 bool copy(int type, void *data, const void *copy = 0); @@ -148,8 +147,8 @@ private: friend class QmlMetaType; friend class QmlTypePrivate; friend struct QmlMetaTypeData; - 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(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(); QmlTypePrivate *d; @@ -161,11 +160,11 @@ int qmlRegisterType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType<T *>(QByteArray(name + '*').constData()), - qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc<T>(), QmlPrivate::attachedPropertiesMetaObject<T>(), @@ -182,11 +181,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<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, QmlPrivate::create<T>, + return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, uri, version_maj, version_min, qmlName, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc<T>(), @@ -204,8 +203,8 @@ int qmlRegisterExtendedType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType<T *>(QByteArray(name + '*').constData()), - qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; QmlAttachedPropertiesFunc attached = @@ -217,7 +216,7 @@ int qmlRegisterExtendedType(const char *typeName) attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>(); } - return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op<T>, 0, 0, 0, 0, &T::staticMetaObject, attached, attachedMo, QmlPrivate::StaticCastSelector<T,QmlParserStatus>::cast(), QmlPrivate::StaticCastSelector<T,QObject>::cast(), @@ -232,8 +231,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<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; QmlAttachedPropertiesFunc attached = @@ -245,7 +244,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c attachedMo = QmlPrivate::attachedPropertiesMetaObject<T>(); } - return QmlMetaType::registerType(ids, QmlPrivate::create<T>, + return QmlMetaType::registerType(ids, QmlPrivate::list_op<T>, uri, version_maj, version_min, qmlName, &T::staticMetaObject, attached, attachedMo, @@ -263,11 +262,13 @@ int qmlRegisterInterface(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType<T *>(QByteArray(name + '*').constData()), - qRegisterMetaType<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerInterface(ids, qobject_interface_iid<T *>()); + return QmlMetaType::registerInterface(ids, + QmlPrivate::list_interface_op<T>, + qobject_interface_iid<T *>()); } template<typename T> @@ -276,11 +277,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<QmlListProperty<T> >(QByteArray("QmlListProperty<" + name + ">").constData()), - qRegisterMetaType<QmlList<T *>*>(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType<T *>(QByteArray("QList<" + name + "*>*").constData()), + qRegisterMetaType<T *>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, QmlPrivate::create<T>, + return QmlMetaType::registerType(ids, QmlPrivate::list_op<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 75b5c08..1c41d46 100644 --- a/src/declarative/qml/qmlobjectscriptclass.cpp +++ b/src/declarative/qml/qmlobjectscriptclass.cpp @@ -239,7 +239,7 @@ QmlObjectScriptClass::property(QObject *obj, const Identifier &name) } if (lastData->flags & QmlPropertyCache::Data::IsQList) { - return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::ListProperty, lastData->propType)); + return Value(scriptEngine, enginePriv->listClass->newList(obj, lastData->coreIndex, QmlListScriptClass::QListPtr, 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 c367497..dd98110 100644 --- a/src/declarative/qml/qmlprivate.h +++ b/src/declarative/qml/qmlprivate.h @@ -85,8 +85,26 @@ 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> - QObject *create() { return new 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); template<class From, class To, int N> struct StaticCastSelectorClass @@ -185,6 +203,7 @@ namespace QmlPrivate int listId; int qmlListId; }; + typedef int (*Func)(QmlPrivate::ListOp, int, const QVariant &, const QVariant &, void **); typedef QObject *(*CreateFunc)(QObject *); template<typename T> @@ -218,6 +237,148 @@ 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 4ab205e..e9a0449 100644 --- a/src/declarative/qml/qmlvme.cpp +++ b/src/declarative/qml/qmlvme.cpp @@ -91,15 +91,14 @@ QmlVME::QmlVME() struct ListInstance { - ListInstance() - : type(0), qmlListInterface(0) {} - ListInstance(int t) - : type(t), qmlListInterface(0) {} + ListInstance() {} + ListInstance(QList<void *> *q, int t) + : type(t), qListInterface(q), qmlListInterface(0) {} ListInstance(QmlPrivate::ListInterface *q, int t) - : type(t), qmlListInterface(q) {} + : type(t), qListInterface(0), qmlListInterface(q) {} int type; - QmlListProperty<void> qListProperty; + QList<void *> *qListInterface; QmlPrivate::ListInterface *qmlListInterface; }; @@ -670,7 +669,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, QObject *assign = stack.pop(); const ListInstance &list = qliststack.top(); - list.qListProperty.append((QmlListProperty<void>*)&list.qListProperty, assign); + list.qListInterface->append((void *)assign); } break; @@ -695,7 +694,7 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, void *d = (void *)&ptr; list.qmlListInterface->append(d); } else { - list.qListProperty.append((QmlListProperty<void>*)&list.qListProperty, ptr); + list.qListInterface->append(ptr); } } break; @@ -773,12 +772,17 @@ QObject *QmlVME::run(QmlVMEStack<QObject *> &stack, QmlContext *ctxt, { QObject *target = stack.top(); - qliststack.push(ListInstance(instr.fetchQmlList.type)); - void *a[1]; - a[0] = (void *)&(qliststack.top().qListProperty); + // We know that QList<T *>* can be converted to + // QList<void *>* + QList<void *> *list = 0; + a[0] = &list; 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; diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index 4f68b6c..abffefe 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -947,10 +947,10 @@ void QmlPropertyAction::setProperties(const QString &p) \sa exclude matchProperties PropertyAnimation::matchTargets */ -QmlListProperty<QObject> QmlPropertyAction::targets() +QList<QObject *> *QmlPropertyAction::targets() { Q_D(QmlPropertyAction); - return QmlListProperty<QObject>(this, d->targets); + return &d->targets; } /*! @@ -958,10 +958,10 @@ QmlListProperty<QObject> QmlPropertyAction::targets() This property holds the objects not to be affected by this animation. \sa matchTargets */ -QmlListProperty<QObject> QmlPropertyAction::exclude() +QList<QObject *> *QmlPropertyAction::exclude() { Q_D(QmlPropertyAction); - return QmlListProperty<QObject>(this, d->exclude); + return &d->exclude; } /*! @@ -2097,10 +2097,10 @@ void QmlPropertyAnimation::setProperties(const QString &prop) \sa exclude matchProperties */ -QmlListProperty<QObject> QmlPropertyAnimation::targets() +QList<QObject *> *QmlPropertyAnimation::targets() { Q_D(QmlPropertyAnimation); - return QmlListProperty<QObject>(this, d->targets); + return &d->targets; } /*! @@ -2108,10 +2108,10 @@ QmlListProperty<QObject> QmlPropertyAnimation::targets() This property holds the items not to be affected by this animation. \sa matchTargets */ -QmlListProperty<QObject> QmlPropertyAnimation::exclude() +QList<QObject *> *QmlPropertyAnimation::exclude() { Q_D(QmlPropertyAnimation); - return QmlListProperty<QObject>(this, d->exclude); + return &d->exclude; } void QmlPropertyAnimationPrivate::valueChanged(qreal r) diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index a566074..6a69e4d 100644 --- a/src/declarative/util/qmlanimation_p.h +++ b/src/declarative/util/qmlanimation_p.h @@ -187,8 +187,8 @@ class QmlPropertyAction : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString matchProperties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QmlListProperty<QObject> matchTargets READ targets) - Q_PROPERTY(QmlListProperty<QObject> exclude READ exclude) + Q_PROPERTY(QList<QObject *>* matchTargets READ targets) + Q_PROPERTY(QList<QObject *>* exclude READ exclude) Q_PROPERTY(QVariant value READ value WRITE setValue NOTIFY valueChanged) public: @@ -204,8 +204,8 @@ public: QString properties() const; void setProperties(const QString &); - QmlListProperty<QObject> targets(); - QmlListProperty<QObject> exclude(); + QList<QObject *> *targets(); + QList<QObject *> *exclude(); QVariant value() const; void setValue(const QVariant &); @@ -267,8 +267,8 @@ class Q_AUTOTEST_EXPORT QmlPropertyAnimation : public QmlAbstractAnimation Q_PROPERTY(QObject *target READ target WRITE setTarget NOTIFY targetChanged) Q_PROPERTY(QString property READ property WRITE setProperty NOTIFY targetChanged) Q_PROPERTY(QString matchProperties READ properties WRITE setProperties NOTIFY propertiesChanged) - Q_PROPERTY(QmlListProperty<QObject> matchTargets READ targets) - Q_PROPERTY(QmlListProperty<QObject> exclude READ exclude) + Q_PROPERTY(QList<QObject *>* matchTargets READ targets) + Q_PROPERTY(QList<QObject *>* exclude READ exclude) public: QmlPropertyAnimation(QObject *parent=0); @@ -295,8 +295,8 @@ public: QString properties() const; void setProperties(const QString &); - QmlListProperty<QObject> targets(); - QmlListProperty<QObject> exclude(); + QList<QObject *> *targets(); + QList<QObject *> *exclude(); protected: virtual void transition(QmlStateActions &actions, diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 2e37d49..6658949 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -88,7 +88,7 @@ void QmlListAccessor::setList(const QVariant &v, QmlEngine *engine) (enginePrivate && enginePrivate->isQmlList(d.userType()))) { m_type = QmlList; } else if (QmlMetaType::isList(d.userType())) { - m_type = ListProperty; + m_type = QListPtr; } else { m_type = Instance; } @@ -106,11 +106,10 @@ int QmlListAccessor::count() const QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); return li->count(); } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->count) return li->count(li); - else return 0; + QList<void *> *li = *(QList<void *> **)d.constData(); + return li->count(); } case Instance: return 1; @@ -137,11 +136,11 @@ QVariant QmlListAccessor::at(int idx) const li->at(idx, ptr); return QVariant::fromValue((QObject*)ptr[0]); } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->at) return QVariant::fromValue((QObject *)li->at(li, idx)); - else return QVariant(); + QList<void *> *li = *(QList<void *> **)d.constData(); + void *ptr = li->at(idx); + return QVariant::fromValue((QObject*)ptr); } case Instance: return d; @@ -162,10 +161,10 @@ bool QmlListAccessor::append(const QVariant &value) li->append(const_cast<void *>(value.constData())); //XXX Typesafety return true; } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->append) li->append(li, *(void **)value.constData()); // XXX Typesafety + QList<void *> *li = *(QList<void *> **)d.constData(); + li->append(*reinterpret_cast<void **>(const_cast<void *>(value.constData()))); //XXX Typesafety return true; } case StringList: @@ -187,10 +186,10 @@ bool QmlListAccessor::insert(int index, const QVariant &value) li->insert(index, const_cast<void *>(value.constData())); //XXX Typesafety return true; } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->insert) li->insert(li, index, *(void **)value.constData()); // XXX Typesafety + QList<void *> *li = *(QList<void *>**)d.constData(); + li->insert(index, *reinterpret_cast<void **>(const_cast<void *>(value.constData()))); //XXX Typesafety return true; } case StringList: @@ -212,10 +211,10 @@ bool QmlListAccessor::removeAt(int index) li->removeAt(index); return true; } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->removeAt) li->removeAt(li, index); + QList<void *> *li = *(QList<void *>**)d.constData(); + li->removeAt(index); return true; } case StringList: @@ -237,10 +236,10 @@ bool QmlListAccessor::clear() li->clear(); return true; } - case ListProperty: + case QListPtr: { - QmlListProperty<void> *li = (QmlListProperty<void>*)d.constData(); - if (li->clear) li->clear(li); + QList<void *> *li = *(QList<void *>**)d.constData(); + li->clear(); return true; } case StringList: diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 6866150..3c67e3a 100644 --- a/src/declarative/util/qmllistaccessor_p.h +++ b/src/declarative/util/qmllistaccessor_p.h @@ -70,7 +70,7 @@ public: bool removeAt(int); bool clear(); - enum Type { Invalid, StringList, VariantList, QmlList, ListProperty, Instance, Integer }; + enum Type { Invalid, StringList, VariantList, QmlList, QListPtr, Instance, Integer }; Type type() const { return m_type; } private: |