From 95a0c92a9788af8ad00bd9d52bccc93d2e9c5b83 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Mon, 8 Feb 2010 17:50:58 +1000 Subject: For local fonts, we can just addApplicationFont() rather than loading data. --- src/declarative/util/qmlfontloader.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/declarative/util/qmlfontloader.cpp b/src/declarative/util/qmlfontloader.cpp index 42b34b5..b56043b 100644 --- a/src/declarative/util/qmlfontloader.cpp +++ b/src/declarative/util/qmlfontloader.cpp @@ -126,10 +126,16 @@ void QmlFontLoader::setSource(const QUrl &url) #ifndef QT_NO_LOCALFILE_OPTIMIZED_QML QString lf = toLocalFileOrQrc(d->url); if (!lf.isEmpty()) { - QFile file(lf); - file.open(QIODevice::ReadOnly); - QByteArray ba = file.readAll(); - d->addFontToDatabase(ba); + int id = QFontDatabase::addApplicationFont(lf); + if (id != -1) { + d->name = QFontDatabase::applicationFontFamilies(id).at(0); + emit nameChanged(); + d->status = QmlFontLoader::Ready; + } else { + d->status = QmlFontLoader::Error; + qWarning() << "Cannot load font:" << url; + } + emit statusChanged(); } else #endif { -- cgit v0.12 From 1feb1f131f0b0f1c782f5c82f2fe231f6c043553 Mon Sep 17 00:00:00 2001 From: Bea Lam Date: Tue, 9 Feb 2010 10:49:05 +1100 Subject: Connect to localhost instead of QHostAddress::Any. Fixes test on Windows. --- tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp index b54f133..60631d2 100644 --- a/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp +++ b/tests/auto/declarative/qpacketprotocol/tst_qpacketprotocol.cpp @@ -80,11 +80,12 @@ private slots: void tst_QPacketProtocol::init() { m_server = new QTcpServer(this); - QVERIFY(m_server->listen()); - + m_serverConn = 0; + QVERIFY(m_server->listen(QHostAddress("127.0.0.1"))); + m_client = new QTcpSocket(this); m_client->connectToHost(m_server->serverAddress(), m_server->serverPort()); - + QVERIFY(m_client->waitForConnected()); QVERIFY(m_server->waitForNewConnection()); m_serverConn = m_server->nextPendingConnection(); -- cgit v0.12 From 7e202bca9d21a70588e726e63abae6c9cb369fa8 Mon Sep 17 00:00:00 2001 From: Martin Jones Date: Tue, 9 Feb 2010 11:37:07 +1000 Subject: Use networkAccessManagerFactory() for worker threads too. Task-number: QT-2850 --- src/declarative/qml/qmlworkerscript.cpp | 32 +++++++++++++++++++------------- src/declarative/qml/qmlworkerscript_p.h | 2 +- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/src/declarative/qml/qmlworkerscript.cpp b/src/declarative/qml/qmlworkerscript.cpp index f58aa8b..5e39eaf 100644 --- a/src/declarative/qml/qmlworkerscript.cpp +++ b/src/declarative/qml/qmlworkerscript.cpp @@ -53,6 +53,7 @@ #include #include #include +#include "qmlnetworkaccessmanagerfactory.h" QT_BEGIN_NAMESPACE @@ -103,18 +104,24 @@ private: class QmlWorkerScriptEnginePrivate : public QObject { public: - QmlWorkerScriptEnginePrivate(); + QmlWorkerScriptEnginePrivate(QmlEngine *eng); struct ScriptEngine : public QmlScriptEngine { - ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent) {} - ~ScriptEngine() { delete manager; }; + ScriptEngine(QmlWorkerScriptEnginePrivate *parent) : QmlScriptEngine(0), p(parent), accessManager(0) {} + ~ScriptEngine() { delete accessManager; } QmlWorkerScriptEnginePrivate *p; - QNetworkAccessManager *manager; + QNetworkAccessManager *accessManager; virtual QNetworkAccessManager *networkAccessManager() { - if (!manager) manager = new QNetworkAccessManager; - return manager; + if (!accessManager) { + if (p->qmlengine && p->qmlengine->networkAccessManagerFactory()) { + accessManager = p->qmlengine->networkAccessManagerFactory()->create(this); + } else { + accessManager = new QNetworkAccessManager(this); + } + } + return accessManager; } }; ScriptEngine *workerEngine; @@ -122,6 +129,8 @@ public: return static_cast(e)->p; } + QmlEngine *qmlengine; + QMutex m_lock; QWaitCondition m_wait; @@ -136,9 +145,6 @@ public: QScriptValue callback; }; - QNetworkAccessManager *networkAccessManager; - QNetworkAccessManager *getNetworkAccessManager(); - QHash workers; QScriptValue getWorker(int); @@ -234,8 +240,8 @@ private: }; Q_DECLARE_METATYPE(QmlWorkerListModelAgent::VariantRef); -QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate() -: workerEngine(0), networkAccessManager(0), m_nextId(0) +QmlWorkerScriptEnginePrivate::QmlWorkerScriptEnginePrivate(QmlEngine *engine) +: workerEngine(0), qmlengine(engine), m_nextId(0) { } @@ -485,8 +491,8 @@ int WorkerRemoveEvent::workerId() const return m_id; } -QmlWorkerScriptEngine::QmlWorkerScriptEngine(QObject *parent) -: QThread(parent), d(new QmlWorkerScriptEnginePrivate) +QmlWorkerScriptEngine::QmlWorkerScriptEngine(QmlEngine *parent) +: QThread(parent), d(new QmlWorkerScriptEnginePrivate(parent)) { d->m_lock.lock(); start(QThread::LowPriority); diff --git a/src/declarative/qml/qmlworkerscript_p.h b/src/declarative/qml/qmlworkerscript_p.h index f0ef7c9..3a29498 100644 --- a/src/declarative/qml/qmlworkerscript_p.h +++ b/src/declarative/qml/qmlworkerscript_p.h @@ -69,7 +69,7 @@ class QmlWorkerScriptEngine : public QThread { Q_OBJECT public: - QmlWorkerScriptEngine(QObject *parent = 0); + QmlWorkerScriptEngine(QmlEngine *parent = 0); virtual ~QmlWorkerScriptEngine(); int registerWorkerScript(QmlWorkerScript *); -- cgit v0.12 From 2f653cc06b97b443b9832d0121dbf92b35dd32c2 Mon Sep 17 00:00:00 2001 From: Warwick Allison Date: Tue, 9 Feb 2010 12:32:22 +1000 Subject: Remove old implicit module support. Previously, it was allowed to use type qualification to refer to types defined in subdirectories - indeed, this was the only form of modularity. This is no longer desirable since we have good import features. Task-number: QTBUG-7721 --- src/declarative/qml/qmlcompositetypemanager.cpp | 16 ++++++++++------ src/declarative/qml/qmlengine.cpp | 14 ++++++-------- .../qmllanguage/data/subdir/subsubdir/SubTest.qml | 2 ++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 11 +++++++++++ 4 files changed, 29 insertions(+), 14 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml diff --git a/src/declarative/qml/qmlcompositetypemanager.cpp b/src/declarative/qml/qmlcompositetypemanager.cpp index 9c78912..3504fe9 100644 --- a/src/declarative/qml/qmlcompositetypemanager.cpp +++ b/src/declarative/qml/qmlcompositetypemanager.cpp @@ -512,14 +512,18 @@ int QmlCompositeTypeManager::resolveTypes(QmlCompositeTypeData *unit) int majorVersion; int minorVersion; QmlEnginePrivate::ImportedNamespace *typeNamespace = 0; - if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, &typeNamespace)) { - // XXX could produce error message here. - } - - if (typeNamespace) { + if (!QmlEnginePrivate::get(engine)->resolveType(unit->imports, typeName, &ref.type, &url, &majorVersion, &minorVersion, &typeNamespace) + || typeNamespace) + { + // Known to not be a type: + // - known to be a namespace (Namespace {}) + // - type with unknown namespace (UnknownNamespace.SomeType {}) QmlError error; error.setUrl(unit->imports.baseUrl()); - error.setDescription(tr("Namespace %1 cannot be used as a type").arg(QString::fromUtf8(typeName))); + if (typeNamespace) + error.setDescription(tr("Namespace %1 cannot be used as a type").arg(QString::fromUtf8(typeName))); + else + error.setDescription(tr("%1 is not a type").arg(QString::fromUtf8(typeName))); if (!parserRef->refObjects.isEmpty()) { QmlParser::Object *obj = parserRef->refObjects.first(); error.setLine(obj->location.start.line); diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index bb26d30..f4dcb7a 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1276,14 +1276,12 @@ public: QmlEnginePrivate::ImportedNamespace *s = 0; int slash = type.indexOf('/'); if (slash >= 0) { - while (!s) { - s = set.value(QString::fromUtf8(type.left(slash))); - int nslash = type.indexOf('/',slash+1); - if (nslash > 0) - slash = nslash; - else - break; - } + s = set.value(QString::fromUtf8(type.left(slash))); + if (!s) + return false; // qualifier must be a namespace + int nslash = type.indexOf('/',slash+1); + if (nslash > 0) + return false; // only single qualification allowed } else { s = &unqualifiedset; } diff --git a/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml b/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml new file mode 100644 index 0000000..c4d5905 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/subdir/subsubdir/SubTest.qml @@ -0,0 +1,2 @@ +import Qt 4.6 +Rectangle { } diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 606d4c6..357fc5f 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -1187,6 +1187,17 @@ void tst_qmllanguage::importsLocal_data() << "import Qt 4.6\nimport \"subdir\"\n" "Test {}" << "QmlGraphicsRectangle"; + QTest::newRow("local import subsubdir") + << "import Qt 4.6\nimport \"subdir/subsubdir\"\n" + "SubTest {}" + << "QmlGraphicsRectangle"; + QTest::newRow("local import QTBUG-7721 A") + << "subdir.Test {}" // no longer allowed (QTBUG-7721) + << ""; + QTest::newRow("local import QTBUG-7721 B") + << "import \"subdir\" as X\n" + "X.subsubdir.SubTest {}" // no longer allowed (QTBUG-7721) + << ""; QTest::newRow("local import as") << "import \"subdir\" as T\n" "T.Test {}" -- cgit v0.12 From d914555badcd4761864657e1e335e657b791453f Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 9 Feb 2010 15:09:42 +1000 Subject: Replace QList<>* support with QmlListProperty --- src/declarative/graphicsitems/qmlgraphicsitem.cpp | 6 +- src/declarative/graphicsitems/qmlgraphicspath.cpp | 4 +- src/declarative/graphicsitems/qmlgraphicspath_p.h | 4 +- .../graphicsitems/qmlgraphicsrectangle_p.h | 4 +- .../graphicsitems/qmlgraphicsvisualitemmodel.cpp | 4 +- src/declarative/qml/qml.h | 4 +- src/declarative/qml/qmllist.h | 66 +++++++++ src/declarative/qml/qmllistscriptclass.cpp | 57 ++++--- src/declarative/qml/qmllistscriptclass_p.h | 2 +- src/declarative/qml/qmlmetaproperty.cpp | 3 +- src/declarative/qml/qmlmetatype.cpp | 66 +++------ src/declarative/qml/qmlmetatype.h | 47 +++--- src/declarative/qml/qmlobjectscriptclass.cpp | 2 +- src/declarative/qml/qmlprivate.h | 163 +-------------------- src/declarative/qml/qmlvme.cpp | 26 ++-- src/declarative/util/qmlanimation.cpp | 16 +- src/declarative/util/qmlanimation_p.h | 16 +- src/declarative/util/qmllistaccessor.cpp | 41 +++--- src/declarative/util/qmllistaccessor_p.h | 2 +- tests/auto/declarative/qmlecmascript/testtypes.h | 8 +- .../qmlecmascript/tst_qmlecmascript.cpp | 2 +- tests/auto/declarative/qmllanguage/testtypes.h | 11 +- .../declarative/qmllanguage/tst_qmllanguage.cpp | 34 ++--- .../qmllistaccessor/tst_qmllistaccessor.cpp | 10 +- 24 files changed, 248 insertions(+), 350 deletions(-) diff --git a/src/declarative/graphicsitems/qmlgraphicsitem.cpp b/src/declarative/graphicsitems/qmlgraphicsitem.cpp index 8973cb4..ed5b18f 100644 --- a/src/declarative/graphicsitems/qmlgraphicsitem.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsitem.cpp @@ -1000,7 +1000,7 @@ class QmlGraphicsKeysAttached : public QObject, public QmlGraphicsItemKeyFilter Q_DECLARE_PRIVATE(QmlGraphicsKeysAttached) Q_PROPERTY(bool enabled READ enabled WRITE setEnabled NOTIFY enabledChanged) - Q_PROPERTY(QList *forwardTo READ forwardTo) + Q_PROPERTY(QmlListProperty forwardTo READ forwardTo) public: QmlGraphicsKeysAttached(QObject *parent=0); @@ -1015,9 +1015,9 @@ public: } } - QList *forwardTo() { + QmlListProperty forwardTo() { Q_D(QmlGraphicsKeysAttached); - return &d->targets; + return QmlListProperty(this, d->targets); } virtual void componentComplete(); diff --git a/src/declarative/graphicsitems/qmlgraphicspath.cpp b/src/declarative/graphicsitems/qmlgraphicspath.cpp index 18f27af..2bac4b6 100644 --- a/src/declarative/graphicsitems/qmlgraphicspath.cpp +++ b/src/declarative/graphicsitems/qmlgraphicspath.cpp @@ -163,10 +163,10 @@ bool QmlGraphicsPath::isClosed() const \snippet doc/src/snippets/declarative/pathview/pathattributes.qml 2 */ -QList* QmlGraphicsPath::pathElements() +QmlListProperty QmlGraphicsPath::pathElements() { Q_D(QmlGraphicsPath); - return &(d->_pathElements); + return QmlListProperty(this, 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 2b4b0fd..50ea15b 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(QList* pathElements READ pathElements) + Q_PROPERTY(QmlListProperty 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(); - QList* pathElements(); + QmlListProperty 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 4f4c1cf..b8c2179 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(QList *stops READ stops) + Q_PROPERTY(QmlListProperty stops READ stops) Q_CLASSINFO("DefaultProperty", "stops") public: QmlGraphicsGradient(QObject *parent=0) : QObject(parent), m_gradient(0) {} ~QmlGraphicsGradient() { delete m_gradient; } - QList *stops() { return &m_stops; } + QmlListProperty stops() { return QmlListProperty(this, m_stops); } const QGradient *gradient() const; diff --git a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp index 2fc143d..4f5b53c 100644 --- a/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp +++ b/src/declarative/graphicsitems/qmlgraphicsvisualitemmodel.cpp @@ -463,7 +463,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::QListPtr) { + || model->m_listAccessor->type() == QmlListAccessor::ListProperty) { model->ensureRoles(); QObject *object = model->m_listAccessor->at(data->m_index).value(); if (object && object->property(name).isValid()) @@ -725,7 +725,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::QListPtr) + if (d->m_listAccessor->type() != QmlListAccessor::QmlList && d->m_listAccessor->type() != QmlListAccessor::ListProperty) 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 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 *) \ + Q_DECLARE_METATYPE(QmlListProperty) \ Q_DECLARE_METATYPE(QmlList *) #define QML_DECLARE_TYPE_HASMETATYPE(TYPE) \ - Q_DECLARE_METATYPE(QList *) \ + Q_DECLARE_METATYPE(QmlListProperty) \ Q_DECLARE_METATYPE(QmlList *) #define QML_DECLARE_INTERFACE(INTERFACE) \ 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 \ friend class Qml_ProxyList_ ##ListName ; \ Qml_ProxyList_##ListName ListName; +template +struct QmlListProperty { + typedef void (*AppendFunction)(QmlListProperty *, T*); + typedef int (*CountFunction)(QmlListProperty *); + typedef T *(*AtFunction)(QmlListProperty *, int); + typedef void (*ClearFunction)(QmlListProperty *); + typedef void (*InsertFunction)(QmlListProperty *, int, T *); + typedef void (*RemoveAtFunction)(QmlListProperty *, int); + + QmlListProperty() + : version(1), object(0), data(0), append(0), count(0), at(0), clear(0), insert(0), removeAt(0) {} + QmlListProperty(QObject *o, QList &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 *)p->data)->append(v); + } + static int qlist_count(QmlListProperty *p) { + return ((QList *)p->data)->count(); + } + static T *qlist_at(QmlListProperty *p, int idx) { + return ((QList *)p->data)->at(idx); + } + static void qlist_clear(QmlListProperty *p) { + return ((QList *)p->data)->clear(); + } + static void qlist_insert(QmlListProperty *p, int idx, T *v) { + return ((QList *)p->data)->insert(idx, v); + } + static void qlist_removeAt(QmlListProperty *p, int idx) { + return ((QList *)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 list; + void *args[] = { &list, 0 }; - if (!list) - return Value(); - - if (data->type == QListPtr) { - const QList &qlist = *((QList*)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 &qmllist = *((QmlList*)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 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 *l = (QmlListProperty *)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 *l = (QmlListProperty *)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 *l = (QmlListProperty *)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 *l = (QmlListProperty *)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..e7f7b6d 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 #include @@ -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); @@ -152,8 +153,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 +166,11 @@ int qmlRegisterType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), QmlPrivate::attachedPropertiesMetaObject(), @@ -186,11 +187,11 @@ int qmlRegisterType(const char *uri, int version_maj, int version_min, const cha QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), @@ -208,8 +209,8 @@ int qmlRegisterExtendedType(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; QmlAttachedPropertiesFunc attached = @@ -221,7 +222,7 @@ int qmlRegisterExtendedType(const char *typeName) attachedMo = QmlPrivate::attachedPropertiesMetaObject(); } - return QmlMetaType::registerType(ids, QmlPrivate::list_nocreate_op, 0, 0, 0, 0, + return QmlMetaType::registerType(ids, 0, 0, 0, 0, 0, &T::staticMetaObject, attached, attachedMo, QmlPrivate::StaticCastSelector::cast(), QmlPrivate::StaticCastSelector::cast(), @@ -236,8 +237,8 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; QmlAttachedPropertiesFunc attached = @@ -249,7 +250,7 @@ int qmlRegisterExtendedType(const char *uri, int version_maj, int version_min, c attachedMo = QmlPrivate::attachedPropertiesMetaObject(); } - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, attached, attachedMo, @@ -267,13 +268,11 @@ int qmlRegisterInterface(const char *typeName) QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerInterface(ids, - QmlPrivate::list_interface_op, - qobject_interface_iid()); + return QmlMetaType::registerInterface(ids, qobject_interface_iid()); } template @@ -282,11 +281,11 @@ int qmlRegisterCustomType(const char *uri, int version_maj, int version_min, con QByteArray name(typeName); QmlPrivate::MetaTypeIds ids = { qRegisterMetaType(QByteArray(name + '*').constData()), - qRegisterMetaType(QByteArray("QList<" + name + "*>*").constData()), - qRegisterMetaType(QByteArray("QmlList<" + name + "*>*").constData()) + qRegisterMetaType >(QByteArray("QmlListProperty<" + name + ">").constData()), + qRegisterMetaType*>(QByteArray("QmlList<" + name + "*>*").constData()) }; - return QmlMetaType::registerType(ids, QmlPrivate::list_op, + return QmlMetaType::registerType(ids, QmlPrivate::create, uri, version_maj, version_min, qmlName, &T::staticMetaObject, QmlPrivate::attachedPropertiesFunc(), 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 - int list_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); - template - int list_nocreate_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); - - template - int list_interface_op(ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out); + QObject *create() { return new T; } template 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 @@ -237,148 +218,6 @@ namespace QmlPrivate }; } -template -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(new T); - *((QObject **)out) = obj; - return 0; - } - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - 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(value.value()); - break; - case QmlPrivate::FromObject: - { - QObject *fromObj = value.value(); - T *me = qobject_cast(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 -int QmlPrivate::list_nocreate_op(QmlPrivate::ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out) -{ - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - 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(value.value()); - break; - case QmlPrivate::FromObject: - { - QObject *fromObj = value.value(); - T *me = qobject_cast(fromObj); - if (me) { - *((QVariant *)*out) = QVariant::fromValue(me); - } - } - break; - case QmlPrivate::Value: - *((QVariant *)*out) = QVariant::fromValue(list->at(val)); - break; - } - return 0; -} - -template -int QmlPrivate::list_interface_op(QmlPrivate::ListOp op, int val, - const QVariant &vlist, - const QVariant &value, - void **out) -{ - QList *list = vlist.value *>(); - switch(op) { - case QmlPrivate::Append: - list->append(value.value()); - break; - case QmlPrivate::Set: - (*list)[val] = value.value(); - break; - case QmlPrivate::Insert: - list->insert(val, value.value()); - break; - case QmlPrivate::Prepend: - list->prepend(value.value()); - 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 *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 *qListInterface; + QmlListProperty qListProperty; QmlPrivate::ListInterface *qmlListInterface; }; @@ -669,7 +670,7 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, QObject *assign = stack.pop(); const ListInstance &list = qliststack.top(); - list.qListInterface->append((void *)assign); + list.qListProperty.append((QmlListProperty*)&list.qListProperty, assign); } break; @@ -694,7 +695,7 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, void *d = (void *)&ptr; list.qmlListInterface->append(d); } else { - list.qListInterface->append(ptr); + list.qListProperty.append((QmlListProperty*)&list.qListProperty, ptr); } } break; @@ -772,17 +773,12 @@ QObject *QmlVME::run(QmlVMEStack &stack, QmlContext *ctxt, { QObject *target = stack.top(); + qliststack.push(ListInstance(instr.fetchQmlList.type)); + void *a[1]; - // We know that QList* can be converted to - // QList* - QList *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; diff --git a/src/declarative/util/qmlanimation.cpp b/src/declarative/util/qmlanimation.cpp index ba096b3..2d1d3b9 100644 --- a/src/declarative/util/qmlanimation.cpp +++ b/src/declarative/util/qmlanimation.cpp @@ -939,10 +939,10 @@ void QmlPropertyAction::setProperties(const QString &p) \sa exclude matchProperties PropertyAnimation::matchTargets */ -QList *QmlPropertyAction::targets() +QmlListProperty QmlPropertyAction::targets() { Q_D(QmlPropertyAction); - return &d->targets; + return QmlListProperty(this, d->targets); } /*! @@ -950,10 +950,10 @@ QList *QmlPropertyAction::targets() This property holds the objects not to be affected by this animation. \sa matchTargets */ -QList *QmlPropertyAction::exclude() +QmlListProperty QmlPropertyAction::exclude() { Q_D(QmlPropertyAction); - return &d->exclude; + return QmlListProperty(this, d->exclude); } /*! @@ -2089,10 +2089,10 @@ void QmlPropertyAnimation::setProperties(const QString &prop) \sa exclude matchProperties */ -QList *QmlPropertyAnimation::targets() +QmlListProperty QmlPropertyAnimation::targets() { Q_D(QmlPropertyAnimation); - return &d->targets; + return QmlListProperty(this, d->targets); } /*! @@ -2100,10 +2100,10 @@ QList *QmlPropertyAnimation::targets() This property holds the items not to be affected by this animation. \sa matchTargets */ -QList *QmlPropertyAnimation::exclude() +QmlListProperty QmlPropertyAnimation::exclude() { Q_D(QmlPropertyAnimation); - return &d->exclude; + return QmlListProperty(this, d->exclude); } void QmlPropertyAnimationPrivate::valueChanged(qreal r) diff --git a/src/declarative/util/qmlanimation_p.h b/src/declarative/util/qmlanimation_p.h index 6a69e4d..a566074 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(QList* matchTargets READ targets) - Q_PROPERTY(QList* exclude READ exclude) + Q_PROPERTY(QmlListProperty matchTargets READ targets) + Q_PROPERTY(QmlListProperty 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 &); - QList *targets(); - QList *exclude(); + QmlListProperty targets(); + QmlListProperty 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(QList* matchTargets READ targets) - Q_PROPERTY(QList* exclude READ exclude) + Q_PROPERTY(QmlListProperty matchTargets READ targets) + Q_PROPERTY(QmlListProperty exclude READ exclude) public: QmlPropertyAnimation(QObject *parent=0); @@ -295,8 +295,8 @@ public: QString properties() const; void setProperties(const QString &); - QList *targets(); - QList *exclude(); + QmlListProperty targets(); + QmlListProperty exclude(); protected: virtual void transition(QmlStateActions &actions, diff --git a/src/declarative/util/qmllistaccessor.cpp b/src/declarative/util/qmllistaccessor.cpp index 00b8220..e060097 100644 --- a/src/declarative/util/qmllistaccessor.cpp +++ b/src/declarative/util/qmllistaccessor.cpp @@ -89,7 +89,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 = QListPtr; + m_type = ListProperty; } else { m_type = Instance; } @@ -107,10 +107,11 @@ int QmlListAccessor::count() const QmlPrivate::ListInterface *li = *(QmlPrivate::ListInterface **)d.constData(); return li->count(); } - case QListPtr: + case ListProperty: { - QList *li = *(QList **)d.constData(); - return li->count(); + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->count) return li->count(li); + else return 0; } case Instance: return 1; @@ -137,11 +138,11 @@ QVariant QmlListAccessor::at(int idx) const li->at(idx, ptr); return QVariant::fromValue((QObject*)ptr[0]); } - case QListPtr: + case ListProperty: { - QList *li = *(QList **)d.constData(); - void *ptr = li->at(idx); - return QVariant::fromValue((QObject*)ptr); + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->at) return QVariant::fromValue((QObject *)li->at(li, idx)); + else return QVariant(); } case Instance: return d; @@ -162,10 +163,10 @@ bool QmlListAccessor::append(const QVariant &value) li->append(const_cast(value.constData())); //XXX Typesafety return true; } - case QListPtr: + case ListProperty: { - QList *li = *(QList **)d.constData(); - li->append(*reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->append) li->append(li, *(void **)value.constData()); // XXX Typesafety return true; } case StringList: @@ -187,10 +188,10 @@ bool QmlListAccessor::insert(int index, const QVariant &value) li->insert(index, const_cast(value.constData())); //XXX Typesafety return true; } - case QListPtr: + case ListProperty: { - QList *li = *(QList**)d.constData(); - li->insert(index, *reinterpret_cast(const_cast(value.constData()))); //XXX Typesafety + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->insert) li->insert(li, index, *(void **)value.constData()); // XXX Typesafety return true; } case StringList: @@ -212,10 +213,10 @@ bool QmlListAccessor::removeAt(int index) li->removeAt(index); return true; } - case QListPtr: + case ListProperty: { - QList *li = *(QList**)d.constData(); - li->removeAt(index); + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->removeAt) li->removeAt(li, index); return true; } case StringList: @@ -237,10 +238,10 @@ bool QmlListAccessor::clear() li->clear(); return true; } - case QListPtr: + case ListProperty: { - QList *li = *(QList**)d.constData(); - li->clear(); + QmlListProperty *li = (QmlListProperty*)d.constData(); + if (li->clear) li->clear(li); return true; } case StringList: diff --git a/src/declarative/util/qmllistaccessor_p.h b/src/declarative/util/qmllistaccessor_p.h index 3c67e3a..6866150 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, QListPtr, Instance, Integer }; + enum Type { Invalid, StringList, VariantList, QmlList, ListProperty, Instance, Integer }; Type type() const { return m_type; } private: diff --git a/tests/auto/declarative/qmlecmascript/testtypes.h b/tests/auto/declarative/qmlecmascript/testtypes.h index 09c850d..b307d9c 100644 --- a/tests/auto/declarative/qmlecmascript/testtypes.h +++ b/tests/auto/declarative/qmlecmascript/testtypes.h @@ -78,7 +78,7 @@ class MyQmlObject : public QObject Q_PROPERTY(QString stringProperty READ stringProperty WRITE setStringProperty NOTIFY stringChanged) Q_PROPERTY(QObject *objectProperty READ objectProperty WRITE setObjectProperty NOTIFY objectChanged) Q_PROPERTY(QmlList *objectQmlListProperty READ objectQmlListProperty CONSTANT) - Q_PROPERTY(QList *objectListProperty READ objectListProperty CONSTANT) + Q_PROPERTY(QmlListProperty objectListProperty READ objectListProperty CONSTANT) Q_PROPERTY(int resettableProperty READ resettableProperty WRITE setResettableProperty RESET resetProperty) public: @@ -108,7 +108,7 @@ public: } QmlList *objectQmlListProperty() { return &m_objectQmlList; } - QList *objectListProperty() { return &m_objectQList; } + QmlListProperty objectListProperty() { return QmlListProperty(this, m_objectQList); } bool methodCalled() const { return m_methodCalled; } bool methodIntCalled() const { return m_methodIntCalled; } @@ -162,11 +162,11 @@ QML_DECLARE_TYPE(MyQmlObject); class MyQmlContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList* children READ children CONSTANT) + Q_PROPERTY(QmlListProperty children READ children CONSTANT) public: MyQmlContainer() {} - QList *children() { return &m_children; } + QmlListProperty children() { return QmlListProperty(this, m_children); } private: QList m_children; diff --git a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp index 1ba9a52..cc5d7f2 100644 --- a/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp +++ b/tests/auto/declarative/qmlecmascript/tst_qmlecmascript.cpp @@ -1608,7 +1608,7 @@ void tst_qmlecmascript::listToVariant() QObject *object = component.create(&context); QVERIFY(object != 0); - QCOMPARE(object->property("test"), QVariant::fromValue(container.children())); + QVERIFY(qvariant_cast >(object->property("test")) == container.children()); delete object; } diff --git a/tests/auto/declarative/qmllanguage/testtypes.h b/tests/auto/declarative/qmllanguage/testtypes.h index d6ca898..6cd4cb5 100644 --- a/tests/auto/declarative/qmllanguage/testtypes.h +++ b/tests/auto/declarative/qmllanguage/testtypes.h @@ -447,19 +447,20 @@ QML_DECLARE_TYPE(MyTypeObject); class MyContainer : public QObject { Q_OBJECT - Q_PROPERTY(QList* children READ children) - Q_PROPERTY(QList* qlistInterfaces READ qlistInterfaces) + Q_PROPERTY(QmlListProperty children READ children) + Q_PROPERTY(QmlListProperty qlistInterfaces READ qlistInterfaces) Q_PROPERTY(QmlList* qmllistInterfaces READ qmllistInterfaces) Q_CLASSINFO("DefaultProperty", "children"); public: MyContainer() {} - QList *children() { return &m_children; } - QList *qlistInterfaces() { return &m_interfaces; } + QmlListProperty children() { return QmlListProperty(this, m_children); } + QList *getChildren() { return &m_children; } + QmlListProperty qlistInterfaces() { return QmlListProperty(this, m_interfaces); } + QList *getQListInterfaces() { return &m_interfaces; } QmlList *qmllistInterfaces() { return &m_qmlinterfaces; } const QmlConcreteList &qmllistAccessor() const { return m_qmlinterfaces; } -private: QList m_children; QList m_interfaces; QmlConcreteList m_qmlinterfaces; diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 357fc5f..7ccdd3d 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -351,7 +351,7 @@ void tst_qmllanguage::simpleContainer() VERIFY_ERRORS(0); MyContainer *container= qobject_cast(component.create()); QVERIFY(container != 0); - QCOMPARE(container->children()->count(),2); + QCOMPARE(container->getChildren()->count(),2); } void tst_qmllanguage::interfaceProperty() @@ -381,9 +381,9 @@ void tst_qmllanguage::interfaceQList() VERIFY_ERRORS(0); MyContainer *container= qobject_cast(component.create()); QVERIFY(container != 0); - QVERIFY(container->qlistInterfaces()->count() == 2); + QVERIFY(container->getQListInterfaces()->count() == 2); for(int ii = 0; ii < 2; ++ii) - QVERIFY(container->qlistInterfaces()->at(ii)->id == 913); + QVERIFY(container->getQListInterfaces()->at(ii)->id == 913); } void tst_qmllanguage::assignObjectToSignal() @@ -422,8 +422,8 @@ void tst_qmllanguage::assignQmlComponent() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QVERIFY(object->children()->count() == 1); - QObject *child = object->children()->at(0); + QVERIFY(object->getChildren()->count() == 1); + QObject *child = object->getChildren()->at(0); QCOMPARE(child->property("x"), QVariant(10)); QCOMPARE(child->property("y"), QVariant(11)); } @@ -501,7 +501,7 @@ void tst_qmllanguage::rootAsQmlComponent() MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); QCOMPARE(object->property("x"), QVariant(11)); - QCOMPARE(object->children()->count(), 2); + QCOMPARE(object->getChildren()->count(), 2); } // Tests that components can be specified inline @@ -511,8 +511,8 @@ void tst_qmllanguage::inlineQmlComponents() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QCOMPARE(object->children()->count(), 1); - QmlComponent *comp = qobject_cast(object->children()->at(0)); + QCOMPARE(object->getChildren()->count(), 1); + QmlComponent *comp = qobject_cast(object->getChildren()->at(0)); QVERIFY(comp != 0); MyQmlObject *compObject = qobject_cast(comp->create()); QVERIFY(compObject != 0); @@ -526,9 +526,9 @@ void tst_qmllanguage::idProperty() VERIFY_ERRORS(0); MyContainer *object = qobject_cast(component.create()); QVERIFY(object != 0); - QCOMPARE(object->children()->count(), 1); + QCOMPARE(object->getChildren()->count(), 1); MyTypeObject *child = - qobject_cast(object->children()->at(0)); + qobject_cast(object->getChildren()->at(0)); QVERIFY(child != 0); QCOMPARE(child->id(), QString("myObjectId")); QCOMPARE(object->property("object"), QVariant::fromValue((QObject *)child)); @@ -1031,13 +1031,13 @@ void tst_qmllanguage::defaultPropertyListOrder() MyContainer *container = qobject_cast(component.create()); QVERIFY(container != 0); - QCOMPARE(container->children()->count(), 6); - QCOMPARE(container->children()->at(0)->property("index"), QVariant(0)); - QCOMPARE(container->children()->at(1)->property("index"), QVariant(1)); - QCOMPARE(container->children()->at(2)->property("index"), QVariant(2)); - QCOMPARE(container->children()->at(3)->property("index"), QVariant(3)); - QCOMPARE(container->children()->at(4)->property("index"), QVariant(4)); - QCOMPARE(container->children()->at(5)->property("index"), QVariant(5)); + QCOMPARE(container->getChildren()->count(), 6); + QCOMPARE(container->getChildren()->at(0)->property("index"), QVariant(0)); + QCOMPARE(container->getChildren()->at(1)->property("index"), QVariant(1)); + QCOMPARE(container->getChildren()->at(2)->property("index"), QVariant(2)); + QCOMPARE(container->getChildren()->at(3)->property("index"), QVariant(3)); + QCOMPARE(container->getChildren()->at(4)->property("index"), QVariant(4)); + QCOMPARE(container->getChildren()->at(5)->property("index"), QVariant(5)); } void tst_qmllanguage::declaredPropertyValues() diff --git a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp index ddf9a07..9bf47b6 100644 --- a/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp +++ b/tests/auto/declarative/qmllistaccessor/tst_qmllistaccessor.cpp @@ -52,7 +52,7 @@ public: private slots: void invalid(); void qmllist(); - void qlist(); + void listproperty(); void qstringlist(); void qvariantlist(); void qobject(); @@ -149,7 +149,7 @@ void tst_QmlListAccessor::qmllist() QCOMPARE(list.count(), 0); } -void tst_QmlListAccessor::qlist() +void tst_QmlListAccessor::listproperty() { QList list; QObject *obj = new QObject(this); @@ -161,11 +161,11 @@ void tst_QmlListAccessor::qlist() QCOMPARE(list.at(0), obj); QmlListAccessor accessor; - accessor.setList(qVariantFromValue((QList*)&list)); - QCOMPARE(accessor.list(), qVariantFromValue((QList*)&list)); + accessor.setList(qVariantFromValue(QmlListProperty(this, list))); + QVERIFY(qvariant_cast >(accessor.list()) == QmlListProperty(this, list)); // type - QCOMPARE(accessor.type(), QmlListAccessor::QListPtr); + QCOMPARE(accessor.type(), QmlListAccessor::ListProperty); // isValid QVERIFY(accessor.isValid()); -- cgit v0.12 From 0286ecdb8fc87b2c42d215aaabcbbffb5c508f01 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Tue, 9 Feb 2010 18:38:27 +1000 Subject: Compile --- tools/qmldebugger/standalone/engine.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tools/qmldebugger/standalone/engine.cpp b/tools/qmldebugger/standalone/engine.cpp index 6cfd82b..38782fd 100644 --- a/tools/qmldebugger/standalone/engine.cpp +++ b/tools/qmldebugger/standalone/engine.cpp @@ -88,7 +88,7 @@ EnginePane::EnginePane(QmlDebugConnection *conn, QWidget *parent) Q_ASSERT(enginesFile.isOpen()); m_engineView = new QmlView(this); - m_engineView->rootContext()->setContextProperty("engines", qVariantFromValue(&m_engineItems)); + m_engineView->rootContext()->setContextProperty("engines", qVariantFromValue(QmlListProperty(this, m_engineItems))); m_engineView->setContentResizable(true); m_engineView->setQml(enginesFile.readAll()); m_engineView->execute(); @@ -205,7 +205,7 @@ void EnginePane::enginesChanged() m_engineItems << new DebuggerEngineItem(engines.at(ii).name(), engines.at(ii).debugId()); - m_engineView->rootContext()->setContextProperty("engines", qVariantFromValue(&m_engineItems)); + m_engineView->rootContext()->setContextProperty("engines", qVariantFromValue(QmlListProperty(this, m_engineItems))); m_engineView->setVisible(m_engineItems.count() > 1); if (m_engineItems.count() == 1) -- cgit v0.12