From 3b3213679a35cdfb1eedcd5b27e6c40f1eca45fd Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Fri, 9 Oct 2009 18:32:30 +1000 Subject: Support aliases to enum properties --- src/declarative/qml/qmlcompiler.cpp | 7 +++++-- tests/auto/declarative/qmllanguage/data/Alias2.qml | 9 +++++++++ tests/auto/declarative/qmllanguage/data/alias.4.qml | 6 ++++++ tests/auto/declarative/qmllanguage/tst_qmllanguage.cpp | 9 +++++++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 tests/auto/declarative/qmllanguage/data/Alias2.qml create mode 100644 tests/auto/declarative/qmllanguage/data/alias.4.qml 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 { -- cgit v0.12