summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-12-17 03:48:16 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-12-17 03:50:25 (GMT)
commitdc77d8217ab7f727a4360ebe953901ec4bade3b0 (patch)
tree4c0934ee01674998076f27c451383fb35d1e056c
parent4d6001bd1d75b80c53fcc716b5a51043713ff6f9 (diff)
downloadQt-dc77d8217ab7f727a4360ebe953901ec4bade3b0.zip
Qt-dc77d8217ab7f727a4360ebe953901ec4bade3b0.tar.gz
Qt-dc77d8217ab7f727a4360ebe953901ec4bade3b0.tar.bz2
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.
-rw-r--r--src/declarative/qml/qmlcompiler.cpp15
-rw-r--r--tests/auto/declarative/qmllanguage/data/Alias3.qml12
-rw-r--r--tests/auto/declarative/qmllanguage/data/Alias4.qml5
-rw-r--r--tests/auto/declarative/qmllanguage/data/alias.8.qml9
-rw-r--r--tests/auto/declarative/qmllanguage/data/alias.9.qml9
-rw-r--r--tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp24
6 files changed, 74 insertions, 0 deletions
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