From 5249c88dfd0ddb19c8b608a895b0b0b676aff27e Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Mon, 25 Jul 2011 13:52:49 +1000 Subject: [PATCH] Allow static alias to composite type Task-number: QTBUG-20200 Change-Id: I2a118dfc9ce1956e038f70049c905ec38396fe5e Reviewed-on: http://codereview.qt.nokia.com/2062 Reviewed-by: Qt Sanity Bot Reviewed-by: Aaron Kennedy --- src/declarative/qml/qdeclarativecompiler.cpp | 20 ++++++-------------- .../data/AliasToCompositeElementType1.qml | 6 ++++++ .../data/AliasToCompositeElementType2.qml | 5 +++++ .../data/aliasToCompositeElement.qml | 6 ++++++ .../tst_qdeclarativeecmascript.cpp | 13 +++++++++++++ 5 files changed, 36 insertions(+), 14 deletions(-) create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType1.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType2.qml create mode 100644 tests/auto/declarative/qdeclarativeecmascript/data/aliasToCompositeElement.qml diff --git a/src/declarative/qml/qdeclarativecompiler.cpp b/src/declarative/qml/qdeclarativecompiler.cpp index 581a538..0f0acba 100644 --- a/src/declarative/qml/qdeclarativecompiler.cpp +++ b/src/declarative/qml/qdeclarativecompiler.cpp @@ -2774,21 +2774,13 @@ bool QDeclarativeCompiler::compileAlias(QMetaObjectBuilder &builder, else typeName = aliasProperty.typeName(); } else { - typeName = idObject->metaObject()->className(); + Q_ASSERT(idObject->type != -1); // How else did it get an id? - //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(); - } - } + const QDeclarativeCompiledData::TypeReference &ref = output->types.at(idObject->type); + if (ref.type) + typeName = ref.type->typeName(); + else + typeName = ref.component->root->className(); typeName += '*'; } diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType1.qml b/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType1.qml new file mode 100644 index 0000000..723b9c3 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType1.qml @@ -0,0 +1,6 @@ +import QtQuick 1.0 + +QtObject { + property alias group: obj + property variant foo: AliasToCompositeElementType2 { id: obj } +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType2.qml b/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType2.qml new file mode 100644 index 0000000..4127ca4 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/AliasToCompositeElementType2.qml @@ -0,0 +1,5 @@ +import QtQuick 1.0 + +QtObject { + property int value +} diff --git a/tests/auto/declarative/qdeclarativeecmascript/data/aliasToCompositeElement.qml b/tests/auto/declarative/qdeclarativeecmascript/data/aliasToCompositeElement.qml new file mode 100644 index 0000000..612c599 --- /dev/null +++ b/tests/auto/declarative/qdeclarativeecmascript/data/aliasToCompositeElement.qml @@ -0,0 +1,6 @@ +import QtQuick 1.0 + +AliasToCompositeElementType1 { + group.value: 13 +} + diff --git a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp index d73da28..2b02ad2 100644 --- a/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp +++ b/tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp @@ -182,6 +182,7 @@ private slots: void aliasBindingsAssignCorrectly(); void aliasBindingsOverrideTarget(); void aliasWritesOverrideBindings(); + void aliasToCompositeElement(); void realToInt(); void include(); @@ -3526,6 +3527,18 @@ void tst_qdeclarativeecmascript::aliasWritesOverrideBindings() } } +// Allow an alais to a composite element +// QTBUG-20200 +void tst_qdeclarativeecmascript::aliasToCompositeElement() +{ + QDeclarativeComponent component(&engine, TEST_FILE("aliasToCompositeElement.qml")); + + QObject *object = component.create(); + QVERIFY(object != 0); + + delete object; +} + void tst_qdeclarativeecmascript::revisionErrors() { { -- 2.7.4