summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-14 05:12:55 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-14 05:12:55 (GMT)
commit4922be635aeaf25343892a73b30ec0d99d467e37 (patch)
tree2fd2454402347a872e556442132c8b530182db39 /src
parent339c91215f0bae4af44fe3124f41244541607a2b (diff)
downloadQt-4922be635aeaf25343892a73b30ec0d99d467e37.zip
Qt-4922be635aeaf25343892a73b30ec0d99d467e37.tar.gz
Qt-4922be635aeaf25343892a73b30ec0d99d467e37.tar.bz2
Support read-only iteration of list properties
Eventually this should be extended to support modifying list properties.
Diffstat (limited to 'src')
-rw-r--r--src/declarative/qml/qml.pri6
-rw-r--r--src/declarative/qml/qmlengine.cpp4
-rw-r--r--src/declarative/qml/qmlengine_p.h2
-rw-r--r--src/declarative/qml/qmllistscriptclass.cpp141
-rw-r--r--src/declarative/qml/qmllistscriptclass_p.h85
-rw-r--r--src/declarative/qml/qmlobjectscriptclass.cpp12
6 files changed, 245 insertions, 5 deletions
diff --git a/src/declarative/qml/qml.pri b/src/declarative/qml/qml.pri
index 2e62a3b..58a18a2 100644
--- a/src/declarative/qml/qml.pri
+++ b/src/declarative/qml/qml.pri
@@ -44,7 +44,8 @@ SOURCES += qml/qmlparser.cpp \
qml/qmlcontextscriptclass.cpp \
qml/qmlglobalscriptclass.cpp \
qml/qmlvaluetypescriptclass.cpp \
- qml/qmltypenamescriptclass.cpp
+ qml/qmltypenamescriptclass.cpp \
+ qml/qmllistscriptclass.cpp
HEADERS += qml/qmlparser_p.h \
qml/qmlinstruction_p.h \
@@ -105,7 +106,8 @@ HEADERS += qml/qmlparser_p.h \
qml/qmlcontextscriptclass_p.h \
qml/qmlglobalscriptclass_p.h \
qml/qmlvaluetypescriptclass_p.h \
- qml/qmltypenamescriptclass_p.h
+ qml/qmltypenamescriptclass_p.h \
+ qml/qmllistscriptclass_p.h
# for qtscript debugger
contains(QT_CONFIG, scripttools):QT += scripttools
diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp
index 7e95428..4dbc336 100644
--- a/src/declarative/qml/qmlengine.cpp
+++ b/src/declarative/qml/qmlengine.cpp
@@ -86,6 +86,7 @@
#include <private/qmlxmlhttprequest_p.h>
#include <private/qmlsqldatabase_p.h>
#include <private/qmltypenamescriptclass_p.h>
+#include <private/qmllistscriptclass_p.h>
#ifdef Q_OS_WIN // for %APPDATA%
#include "qt_windows.h"
@@ -173,6 +174,8 @@ QmlEnginePrivate::~QmlEnginePrivate()
valueTypeClass = 0;
delete typeNameClass;
typeNameClass = 0;
+ delete listClass;
+ listClass = 0;
delete networkAccessManager;
networkAccessManager = 0;
delete nodeListClass;
@@ -218,6 +221,7 @@ void QmlEnginePrivate::init()
objectClass = new QmlObjectScriptClass(q);
valueTypeClass = new QmlValueTypeScriptClass(q);
typeNameClass = new QmlTypeNameScriptClass(q);
+ listClass = new QmlListScriptClass(q);
rootContext = new QmlContext(q,true);
#ifdef QT_SCRIPTTOOLS_LIB
if (qmlDebugger()){
diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h
index 4c90a80..a85ac55 100644
--- a/src/declarative/qml/qmlengine_p.h
+++ b/src/declarative/qml/qmlengine_p.h
@@ -96,6 +96,7 @@ class QScriptDeclarativeClass;
class QmlTypeNameScriptClass;
class QmlTypeNameCache;
class QmlComponentAttached;
+class QmlListScriptClass;
class QmlEnginePrivate : public QObjectPrivate
{
@@ -129,6 +130,7 @@ public:
QmlObjectScriptClass *objectClass;
QmlValueTypeScriptClass *valueTypeClass;
QmlTypeNameScriptClass *typeNameClass;
+ QmlListScriptClass *listClass;
// Global script class
QScriptClass *globalClass;
// Used by DOM Core 3 API
diff --git a/src/declarative/qml/qmllistscriptclass.cpp b/src/declarative/qml/qmllistscriptclass.cpp
new file mode 100644
index 0000000..09bde8c
--- /dev/null
+++ b/src/declarative/qml/qmllistscriptclass.cpp
@@ -0,0 +1,141 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "qmllistscriptclass_p.h"
+#include <private/qmlengine_p.h>
+
+QT_BEGIN_NAMESPACE
+
+struct ListData : public QScriptDeclarativeClass::Object {
+ QGuard<QObject> object;
+ int propertyIdx;
+ QmlListScriptClass::ListType type;
+};
+
+QmlListScriptClass::QmlListScriptClass(QmlEngine *e)
+: QScriptDeclarativeClass(QmlEnginePrivate::getScriptEngine(e)), engine(e)
+{
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
+
+ m_lengthId = createPersistentIdentifier(QLatin1String("length"));
+}
+
+QmlListScriptClass::~QmlListScriptClass()
+{
+}
+
+QScriptValue QmlListScriptClass::newList(QObject *object, int propId, ListType type)
+{
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
+
+ if (!object || propId == -1)
+ return scriptEngine->nullValue();
+
+ ListData *data = new ListData;
+ data->object = object;
+ data->propertyIdx = propId;
+ data->type = type;
+
+ return newObject(scriptEngine, this, data);
+}
+
+QScriptClass::QueryFlags
+QmlListScriptClass::queryProperty(Object *object, const Identifier &name,
+ QScriptClass::QueryFlags flags)
+{
+ if (name == m_lengthId.identifier)
+ return QScriptClass::HandlesReadAccess;
+
+ bool ok = false;
+ quint32 idx = toArrayIndex(name, &ok);
+
+ if (ok) {
+ lastIndex = idx;
+ return QScriptClass::HandlesReadAccess;
+ } else {
+ return 0;
+ }
+}
+
+QScriptValue QmlListScriptClass::property(Object *obj, const Identifier &name)
+{
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
+ QmlEnginePrivate *enginePriv = QmlEnginePrivate::get(engine);
+
+ ListData *data = (ListData *)obj;
+ if (!data->object)
+ return scriptEngine->undefinedValue();
+
+ void *list = 0;
+ void *args[] = { &list, 0 };
+ QMetaObject::metacall(data->object, QMetaObject::ReadProperty,
+ data->propertyIdx, args);
+
+ if (!list)
+ return scriptEngine->undefinedValue();
+
+ if (data->type == QListPtr) {
+ const QList<QObject *> &qlist = *((QList<QObject *>*)list);
+
+ if (name == m_lengthId.identifier)
+ return qlist.count();
+ else if (lastIndex < qlist.count())
+ return enginePriv->objectClass->newQObject(qlist.at(lastIndex));
+ else
+ return scriptEngine->undefinedValue();
+
+ } else {
+ Q_ASSERT(data->type == QmlListPtr);
+ const QmlList<QObject *> &qmllist = *((QmlList<QObject *>*)list);
+
+ int count = qmllist.count();
+
+ if (name == m_lengthId.identifier)
+ return count;
+ else if (lastIndex < count)
+ return enginePriv->objectClass->newQObject(qmllist.at(lastIndex));
+ else
+ return scriptEngine->undefinedValue();
+ }
+}
+
+QT_END_NAMESPACE
+
diff --git a/src/declarative/qml/qmllistscriptclass_p.h b/src/declarative/qml/qmllistscriptclass_p.h
new file mode 100644
index 0000000..7592098
--- /dev/null
+++ b/src/declarative/qml/qmllistscriptclass_p.h
@@ -0,0 +1,85 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtDeclarative module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QMLLISTSCRIPTCLASS_P_H
+#define QMLLISTSCRIPTCLASS_P_H
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists purely as an
+// implementation detail. This header file may change from version to
+// version without notice, or even be removed.
+//
+// We mean it.
+//
+
+#include <private/qscriptdeclarativeclass_p.h>
+
+QT_BEGIN_NAMESPACE
+
+class QmlEngine;
+class QmlListScriptClass : public QScriptDeclarativeClass
+{
+public:
+ QmlListScriptClass(QmlEngine *);
+ ~QmlListScriptClass();
+
+ enum ListType { QListPtr, QmlListPtr };
+ QScriptValue newList(QObject *, int, ListType);
+
+protected:
+ virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &,
+ QScriptClass::QueryFlags flags);
+ virtual QScriptValue property(Object *, const Identifier &);
+
+private:
+ PersistentIdentifier m_lengthId;
+ QmlEngine *engine;
+
+ quint32 lastIndex;
+};
+
+QT_END_NAMESPACE
+
+#endif // QMLLISTSCRIPTCLASS_P_H
+
diff --git a/src/declarative/qml/qmlobjectscriptclass.cpp b/src/declarative/qml/qmlobjectscriptclass.cpp
index 80f2786..122db51 100644
--- a/src/declarative/qml/qmlobjectscriptclass.cpp
+++ b/src/declarative/qml/qmlobjectscriptclass.cpp
@@ -45,6 +45,7 @@
#include <private/qmlcontext_p.h>
#include <private/qmldeclarativedata_p.h>
#include <private/qmltypenamescriptclass_p.h>
+#include <private/qmllistscriptclass_p.h>
#include <QtDeclarative/qmlbinding.h>
#include <QtCore/qtimer.h>
@@ -64,8 +65,7 @@ QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine)
: QScriptDeclarativeClass(QmlEnginePrivate::getScriptEngine(bindEngine)), lastData(0),
engine(bindEngine)
{
- engine = bindEngine;
- QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(bindEngine);
+ QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine);
m_destroy = scriptEngine->newFunction(destroy);
m_destroyId = createPersistentIdentifier(QLatin1String("destroy"));
@@ -214,7 +214,13 @@ QScriptValue QmlObjectScriptClass::property(QObject *obj, const Identifier &name
return enginePriv->valueTypeClass->newObject(obj, lastData->coreIndex, valueType);
}
- if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) {
+ if (lastData->flags & QmlPropertyCache::Data::IsQList) {
+ return enginePriv->listClass->newList(obj, lastData->coreIndex,
+ QmlListScriptClass::QListPtr);
+ } else if (lastData->flags & QmlPropertyCache::Data::IsQmlList) {
+ return enginePriv->listClass->newList(obj, lastData->coreIndex,
+ QmlListScriptClass::QmlListPtr);
+ } if (lastData->flags & QmlPropertyCache::Data::IsQObjectDerived) {
QObject *rv = 0;
void *args[] = { &rv, 0 };
QMetaObject::metacall(obj, QMetaObject::ReadProperty, lastData->coreIndex, args);