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