From dc77d8217ab7f727a4360ebe953901ec4bade3b0 Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 17 Dec 2009 13:48:16 +1000 Subject: Support aliasing of composite types. Composite types haven't been registered with the metatype system, so we use the base type as the property type instead. --- src/declarative/qml/qmlcompiler.cpp | 15 ++++++++++++++ tests/auto/declarative/qmllanguage/data/Alias3.qml | 12 +++++++++++ tests/auto/declarative/qmllanguage/data/Alias4.qml | 5 +++++ .../auto/declarative/qmllanguage/data/alias.8.qml | 9 ++++++++ .../auto/declarative/qmllanguage/data/alias.9.qml | 9 ++++++++ .../declarative/qmllanguage/tst_qmllanguage.cpp | 24 ++++++++++++++++++++++ 6 files changed, 74 insertions(+) create mode 100644 tests/auto/declarative/qmllanguage/data/Alias3.qml create mode 100644 tests/auto/declarative/qmllanguage/data/Alias4.qml create mode 100644 tests/auto/declarative/qmllanguage/data/alias.8.qml create mode 100644 tests/auto/declarative/qmllanguage/data/alias.9.qml diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp index bd46bbe..9147c4a 100644 --- a/src/declarative/qml/qmlcompiler.cpp +++ b/src/declarative/qml/qmlcompiler.cpp @@ -2440,6 +2440,21 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder, typeName = aliasProperty.typeName(); } else { typeName = idObject->metaObject()->className(); + + //use the base type since it has been registered with metatype system + int index = typeName.indexOf("_QML_"); + if (index != -1) { + typeName = typeName.left(index); + } else { + index = typeName.indexOf("_QMLTYPE_"); + const QMetaObject *mo = idObject->metaObject(); + while (index != -1 && mo) { + typeName = mo->superClass()->className(); + index = typeName.indexOf("_QMLTYPE_"); + mo = mo->superClass(); + } + } + typeName += '*'; } diff --git a/tests/auto/declarative/qmllanguage/data/Alias3.qml b/tests/auto/declarative/qmllanguage/data/Alias3.qml new file mode 100644 index 0000000..d1e78f8 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/Alias3.qml @@ -0,0 +1,12 @@ +import Test 1.0 +import Qt 4.6 + +QtObject { + property alias obj : otherObj + property var child + child: QtObject { + id: otherObj + property int myValue: 10 + } +} + diff --git a/tests/auto/declarative/qmllanguage/data/Alias4.qml b/tests/auto/declarative/qmllanguage/data/Alias4.qml new file mode 100644 index 0000000..573674c --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/Alias4.qml @@ -0,0 +1,5 @@ +import Test 1.0 +import Qt 4.6 + +Alias3 {} + diff --git a/tests/auto/declarative/qmllanguage/data/alias.8.qml b/tests/auto/declarative/qmllanguage/data/alias.8.qml new file mode 100644 index 0000000..38dc10f --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/alias.8.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property var other + other: Alias3 { id: MyAliasObject } + + property int value: MyAliasObject.obj.myValue +} + diff --git a/tests/auto/declarative/qmllanguage/data/alias.9.qml b/tests/auto/declarative/qmllanguage/data/alias.9.qml new file mode 100644 index 0000000..8061f99 --- /dev/null +++ b/tests/auto/declarative/qmllanguage/data/alias.9.qml @@ -0,0 +1,9 @@ +import Qt 4.6 + +QtObject { + property var other + other: Alias4 { id: MyAliasObject } + + property int value: MyAliasObject.obj.myValue +} + diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp index 160998f..56c500c 100644 --- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp +++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp @@ -889,6 +889,30 @@ void tst_qmllanguage::aliasProperties() object->metaObject()->indexOfProperty("aliasedObject"), a); QVERIFY(alias2 == 0); } + + // Simple composite type + { + QmlComponent component(&engine, TEST_FILE("alias.8.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 10); + + delete object; + } + + // Complex composite type + { + QmlComponent component(&engine, TEST_FILE("alias.9.qml")); + VERIFY_ERRORS(0); + QObject *object = component.create(); + QVERIFY(object != 0); + + QCOMPARE(object->property("value").toInt(), 10); + + delete object; + } } // Test that the root element in a composite type can be a Component -- cgit v0.12 From e65add386385365f3ee5d3161198101afe2459a3 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 17 Dec 2009 14:06:42 +1000 Subject: Add -parent option --- tests/benchmarks/declarative/qmltime/qmltime.cpp | 40 ++++++++++++++++++++++-- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp index f065444..8da0f17 100644 --- a/tests/benchmarks/declarative/qmltime/qmltime.cpp +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -4,6 +4,8 @@ #include #include #include +#include +#include class Timer : public QObject { @@ -20,11 +22,18 @@ public: void run(uint); + bool willParent() const; + void setWillParent(bool p); + private: void runTest(QmlContext *, uint); QmlComponent *m_component; static Timer *m_timer; + + bool m_willparent; + QGraphicsScene m_scene; + QGraphicsRectItem m_item; }; QML_DECLARE_TYPE(Timer); QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer); @@ -32,11 +41,13 @@ QML_DEFINE_TYPE(QmlTime, 1, 0, Timer, Timer); Timer *Timer::m_timer = 0; Timer::Timer() -: m_component(0) +: m_component(0), m_willparent(false) { if (m_timer) qWarning("Timer: Timer already registered"); m_timer = this; + + m_scene.addItem(&m_item); } QmlComponent *Timer::component() const @@ -59,18 +70,33 @@ void Timer::run(uint iterations) QmlContext context(qmlContext(this)); QObject *o = m_component->create(&context); + QGraphicsObject *go = qobject_cast(o); + if (m_willparent && go) + go->setParentItem(&m_item); delete o; - runTest(&context, iterations); } +bool Timer::willParent() const +{ + return m_willparent; +} + +void Timer::setWillParent(bool p) +{ + m_willparent = p; +} + void Timer::runTest(QmlContext *context, uint iterations) { QTime t; t.start(); for (uint ii = 0; ii < iterations; ++ii) { QObject *o = m_component->create(context); + QGraphicsObject *go = qobject_cast(o); + if (m_willparent && go) + go->setParentItem(&m_item); delete o; } @@ -82,7 +108,7 @@ void Timer::runTest(QmlContext *context, uint iterations) void usage(const char *name) { - qWarning("Usage: %s [-iterations ] ", name); + qWarning("Usage: %s [-iterations ] [-parent] ", name); exit(-1); } @@ -92,6 +118,7 @@ int main(int argc, char ** argv) uint iterations = 1024; QString filename; + bool willParent = false; for (int ii = 1; ii < argc; ++ii) { QByteArray arg(argv[ii]); @@ -107,11 +134,16 @@ int main(int argc, char ** argv) } else { usage(argv[0]); } + } else if (arg == "-parent") { + willParent = true; } else { filename = QLatin1String(argv[ii]); } } + if (filename.isEmpty()) + usage(argv[0]); + QmlEngine engine; QmlComponent component(&engine, filename); if (component.isError()) { @@ -131,6 +163,8 @@ int main(int argc, char ** argv) return -1; } + timer->setWillParent(willParent); + if (!timer->component()) { qWarning() << "The timer has no component"; return -1; -- cgit v0.12 From d169873541ca6f6725e9ce5bfbbf9941f1823a1f Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Thu, 17 Dec 2009 16:18:56 +1000 Subject: Set correct property flags for custom property types. If a property type was a composite object pointer (e.g. property MyObject obj), it was not being correctly identified as an object type. Task-number: QTBUG-6335 Reviewed-by: Aaron Kennedy --- src/declarative/qml/qmlengine.cpp | 10 ++++++++++ src/declarative/qml/qmlengine_p.h | 1 + src/declarative/qml/qmlpropertycache.cpp | 7 ++++--- src/declarative/qml/qmlpropertycache_p.h | 2 +- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 6b66095..f541631 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -1527,6 +1527,16 @@ int QmlEnginePrivate::qmlListType(int t) const return QmlMetaType::qmlListType(t); } +QmlMetaType::TypeCategory QmlEnginePrivate::typeCategory(int t) const +{ + if (m_compositeTypes.contains(t)) + return QmlMetaType::Object; + else if (m_qmlLists.contains(t)) + return QmlMetaType::QmlList; + else + return QmlMetaType::typeCategory(t); +} + const QMetaObject *QmlEnginePrivate::rawMetaObjectForType(int t) const { QHash::ConstIterator iter = m_compositeTypes.find(t); diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index c3db6cf..96297ea 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -263,6 +263,7 @@ public: bool isQmlList(int) const; bool isObject(int); int qmlListType(int) const; + QmlMetaType::TypeCategory typeCategory(int) const; const QMetaObject *rawMetaObjectForType(int) const; const QMetaObject *metaObjectForType(int) const; QHash m_qmlLists; diff --git a/src/declarative/qml/qmlpropertycache.cpp b/src/declarative/qml/qmlpropertycache.cpp index 6ba6028..bc7d7de 100644 --- a/src/declarative/qml/qmlpropertycache.cpp +++ b/src/declarative/qml/qmlpropertycache.cpp @@ -49,7 +49,7 @@ QT_BEGIN_NAMESPACE Q_DECLARE_METATYPE(QScriptValue); -void QmlPropertyCache::Data::load(const QMetaProperty &p) +void QmlPropertyCache::Data::load(const QMetaProperty &p, QmlEngine *engine) { propType = p.userType(); if (QVariant::Type(propType) == QVariant::LastType) @@ -69,7 +69,8 @@ void QmlPropertyCache::Data::load(const QMetaProperty &p) } else if (p.isEnumType()) { flags |= Data::IsEnumType; } else { - QmlMetaType::TypeCategory cat = QmlMetaType::typeCategory(propType); + QmlMetaType::TypeCategory cat = engine ? QmlEnginePrivate::get(engine)->typeCategory(propType) + : QmlMetaType::typeCategory(propType); if (cat == QmlMetaType::Object) flags |= Data::IsQObjectDerived; else if (cat == QmlMetaType::List) @@ -174,7 +175,7 @@ void QmlPropertyCache::update(QmlEngine *engine, const QMetaObject *metaObject) RData *data = new RData; data->identifier = enginePriv->objectClass->createPersistentIdentifier(propName); - data->load(p); + data->load(p, engine); indexCache[ii] = data; diff --git a/src/declarative/qml/qmlpropertycache_p.h b/src/declarative/qml/qmlpropertycache_p.h index 613f4dd..50b4cf2 100644 --- a/src/declarative/qml/qmlpropertycache_p.h +++ b/src/declarative/qml/qmlpropertycache_p.h @@ -97,7 +97,7 @@ public: int coreIndex; int notifyIndex; - void load(const QMetaProperty &); + void load(const QMetaProperty &, QmlEngine *engine = 0); void load(const QMetaMethod &); QString name(QObject *); QString name(const QMetaObject *); -- cgit v0.12 From 21aa1d1c5341edf2b2d50998f5cedc16094b75e1 Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Thu, 17 Dec 2009 17:31:57 +1000 Subject: Disable indexing --- tests/benchmarks/declarative/qmltime/qmltime.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/benchmarks/declarative/qmltime/qmltime.cpp b/tests/benchmarks/declarative/qmltime/qmltime.cpp index 8da0f17..7f41c07 100644 --- a/tests/benchmarks/declarative/qmltime/qmltime.cpp +++ b/tests/benchmarks/declarative/qmltime/qmltime.cpp @@ -47,6 +47,7 @@ Timer::Timer() qWarning("Timer: Timer already registered"); m_timer = this; + m_scene.setItemIndexMethod(QGraphicsScene::NoIndex); m_scene.addItem(&m_item); } -- cgit v0.12