summaryrefslogtreecommitdiffstats
path: root/src/declarative/qml/qmllistscriptclass.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/declarative/qml/qmllistscriptclass.cpp')
-rw-r--r--src/declarative/qml/qmllistscriptclass.cpp72
1 files changed, 24 insertions, 48 deletions
diff --git a/src/declarative/qml/qmllistscriptclass.cpp b/src/declarative/qml/qmllistscriptclass.cpp
index d74a9b0..bb29763 100644
--- a/src/declarative/qml/qmllistscriptclass.cpp
+++ b/src/declarative/qml/qmllistscriptclass.cpp
@@ -43,13 +43,13 @@
#include "qmlengine_p.h"
#include "qmlguard_p.h"
+#include "qmllist_p.h"
QT_BEGIN_NAMESPACE
struct ListData : public QScriptDeclarativeClass::Object {
QmlGuard<QObject> object;
- int propertyIdx;
- QmlListScriptClass::ListCategory type;
+ QmlListProperty<QObject> property;
int propertyType;
};
@@ -66,7 +66,7 @@ QmlListScriptClass::~QmlListScriptClass()
{
}
-QScriptValue QmlListScriptClass::newList(QObject *object, int propId, ListCategory type, int propType)
+QScriptValue QmlListScriptClass::newList(QObject *object, int propId, int propType)
{
QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
@@ -75,8 +75,20 @@ QScriptValue QmlListScriptClass::newList(QObject *object, int propId, ListCatego
ListData *data = new ListData;
data->object = object;
- data->propertyIdx = propId;
- data->type = type;
+ data->propertyType = propType;
+ void *args[] = { &data->property, 0 };
+ QMetaObject::metacall(object, QMetaObject::ReadProperty, propId, args);
+
+ return newObject(scriptEngine, this, data);
+}
+
+QScriptValue QmlListScriptClass::newList(const QmlListProperty<QObject> &prop, int propType)
+{
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
+
+ ListData *data = new ListData;
+ data->object = prop.object;
+ data->property = prop;
data->propertyType = propType;
return newObject(scriptEngine, this, data);
@@ -111,39 +123,14 @@ 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);
+ quint32 count = data->property.count?data->property.count(&data->property):0;
- if (!list)
+ if (name == m_lengthId.identifier)
+ return Value(scriptEngine, count);
+ else if (lastIndex < count && data->property.at)
+ return Value(scriptEngine, enginePriv->objectClass->newQObject(data->property.at(&data->property, lastIndex)));
+ else
return Value();
-
- if (data->type == QListPtr) {
- const QList<QObject *> &qlist = *((QList<QObject *>*)list);
-
- quint32 count = qlist.count();
-
- if (name == m_lengthId.identifier)
- return Value(scriptEngine, count);
- else if (lastIndex < count)
- return Value(scriptEngine, enginePriv->objectClass->newQObject(qlist.at(lastIndex)));
- else
- return Value();
-
- } else {
- Q_ASSERT(data->type == QmlListPtr);
- const QmlList<QObject *> &qmllist = *((QmlList<QObject *>*)list);
-
- quint32 count = qmllist.count();
-
- if (name == m_lengthId.identifier)
- return Value(scriptEngine, count);
- else if (lastIndex < count)
- return Value(scriptEngine, enginePriv->objectClass->newQObject(qmllist.at(lastIndex)));
- else
- return Value();
- }
}
QVariant QmlListScriptClass::toVariant(Object *obj, bool *ok)
@@ -155,18 +142,7 @@ 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 (!list) {
- if (ok) *ok = false;
- return QVariant();
- }
-
- if (ok) *ok = true;
- return QVariant(data->propertyType, &list);
+ return QVariant::fromValue(QmlListReferencePrivate::init(data->property, data->propertyType, engine));
}
QT_END_NAMESPACE