summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Kennedy <aaron.kennedy@nokia.com>2009-10-09 08:32:30 (GMT)
committerAaron Kennedy <aaron.kennedy@nokia.com>2009-10-09 08:32:30 (GMT)
commit3b3213679a35cdfb1eedcd5b27e6c40f1eca45fd (patch)
treebb7636c7aa078e346a81b2f317198a320e94fc15
parent3995e86d68b2f9958156da3b51d50609b748d220 (diff)
downloadQt-3b3213679a35cdfb1eedcd5b27e6c40f1eca45fd.zip
Qt-3b3213679a35cdfb1eedcd5b27e6c40f1eca45fd.tar.gz
Qt-3b3213679a35cdfb1eedcd5b27e6c40f1eca45fd.tar.bz2
Support aliases to enum properties
-rw-r--r--src/declarative/qml/qmlcompiler.cpp7
-rw-r--r--tests/auto/declarative/qmllanguage/data/Alias2.qml9
-rw-r--r--tests/auto/declarative/qmllanguage/data/alias.4.qml6
-rw-r--r--tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp9
4 files changed, 29 insertions, 2 deletions
diff --git a/src/declarative/qml/qmlcompiler.cpp b/src/declarative/qml/qmlcompiler.cpp
index 5e6a8aa..8856892 100644
--- a/src/declarative/qml/qmlcompiler.cpp
+++ b/src/declarative/qml/qmlcompiler.cpp
@@ -2253,10 +2253,13 @@ bool QmlCompiler::compileAlias(QMetaObjectBuilder &builder,
data.append((const char *)&idObject->idIndex, sizeof(idObject->idIndex));
data.append((const char *)&propIdx, sizeof(propIdx));
+ const char *typeName = aliasProperty.typeName();
+ if (aliasProperty.isEnumType())
+ typeName = "int"; // Avoid introducing a dependency on the aliased metaobject
+
builder.addSignal(prop.name + "Changed()");
QMetaPropertyBuilder propBuilder =
- builder.addProperty(prop.name, aliasProperty.typeName(),
- builder.methodCount() - 1);
+ builder.addProperty(prop.name, typeName, builder.methodCount() - 1);
propBuilder.setScriptable(true);
return true;
}
diff --git a/tests/auto/declarative/qmllanguage/data/Alias2.qml b/tests/auto/declarative/qmllanguage/data/Alias2.qml
new file mode 100644
index 0000000..b7e81a5
--- /dev/null
+++ b/tests/auto/declarative/qmllanguage/data/Alias2.qml
@@ -0,0 +1,9 @@
+import Test 1.0
+import Qt 4.6
+
+Object {
+ property var other
+ other: MyTypeObject { id: obj }
+ property alias enumAlias: obj.enumProperty;
+}
+
diff --git a/tests/auto/declarative/qmllanguage/data/alias.4.qml b/tests/auto/declarative/qmllanguage/data/alias.4.qml
new file mode 100644
index 0000000..bd6a769
--- /dev/null
+++ b/tests/auto/declarative/qmllanguage/data/alias.4.qml
@@ -0,0 +1,6 @@
+import Test 1.0
+
+Alias2 {
+ enumAlias: MyTypeObject.EnumVal2
+}
+
diff --git a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp
index 3825b62..135a207 100644
--- a/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp
+++ b/tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp
@@ -612,6 +612,15 @@ void tst_qmllanguage::aliasProperties()
delete object;
}
+ // Enum aliases
+ {
+ QmlComponent component(&engine, TEST_FILE("alias.4.qml"));
+ VERIFY_ERRORS(0);
+ QObject *object = component.create();
+ QVERIFY(object != 0);
+
+ QCOMPARE(object->property("enumAlias").toInt(), 1);
+ }
}
class TestType : public QObject {