diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-09-30 08:32:02 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-10-07 21:59:11 +0200 |
commit | e5f3e7149b7e130c375c1419f1f804dfeaf578aa (patch) | |
tree | 540568cb819ddb00766bfdcc7851217b87b7a4fc /tests | |
parent | 00f903f3b4cd46ddf8361876401e5405030f97f1 (diff) |
Add initial support for deep aliases
This patch reuses the existing support for value types to support
aliases of depth 2. This covers the initial use case in QTBUG-48150.
Adding support for "deeper" aliases would require storing the complete
"property path", which in turn would require increasing the size of the
Alias data. This is currently considered out of scope, at least until a
clear use-case appears.
Fixes: QTBUG-48150
Change-Id: Id2ac4dd175003a37eba2919e7604d0a3be54d29f
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/qml/qqmllanguage/data/alias.17.qml | 31 | ||||
-rw-r--r-- | tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp | 63 |
2 files changed, 94 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmllanguage/data/alias.17.qml b/tests/auto/qml/qqmllanguage/data/alias.17.qml new file mode 100644 index 0000000000..a76dd120b6 --- /dev/null +++ b/tests/auto/qml/qqmllanguage/data/alias.17.qml @@ -0,0 +1,31 @@ +import QtQuick 2.12 + +Item { + id: root + anchors.fill: parent + width: 100 + height: 100 + property bool success: checkValue === aliasUser.topMargin + property int checkValue: 42 + Rectangle { + id: myItem + objectName: "myItem" + color: "blue" + anchors.topMargin: root.checkValue + width: 50 + height: 50 + Text {text: "source:\n" + myItem.anchors.topMargin} + } + + Rectangle { + property alias topMargin: myItem.anchors.topMargin + id: aliasUser + objectName: "aliasUser" + color: "red" + anchors.left: myItem.right + width: 50 + height: 50 + Text {objectName: "myText"; text: "alias:\n" + aliasUser.topMargin} + } +} + diff --git a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp index ad96b1438f..ecf87c51d6 100644 --- a/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp +++ b/tests/auto/qml/qqmllanguage/tst_qqmllanguage.cpp @@ -1969,6 +1969,69 @@ void tst_qqmllanguage::aliasProperties() QScopedPointer<QObject> object(component.create()); QVERIFY(!object.isNull()); } + + // Alias to grouped property + { + QQmlComponent component(&engine, testFileUrl("alias.17.qml")); + VERIFY_ERRORS(0); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QVERIFY(object->property("success").toBool()); + } + + // Alias to grouped property updates + { + QQmlComponent component(&engine, testFileUrl("alias.17.qml")); + VERIFY_ERRORS(0); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QObject *aliasUser = object->findChild<QObject*>(QLatin1String("aliasUser")); + QVERIFY(aliasUser); + QQmlProperty checkValueProp(object.get(), "checkValue"); + QVERIFY(checkValueProp.isValid()); + checkValueProp.write(777); + QCOMPARE(object->property("checkValue").toInt(), 777); + QCOMPARE(aliasUser->property("topMargin").toInt(), 777); + } + + // Write to alias to grouped property + { + QQmlComponent component(&engine, testFileUrl("alias.17.qml")); + VERIFY_ERRORS(0); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QObject *aliasUser = object->findChild<QObject*>(QLatin1String("aliasUser")); + QVERIFY(aliasUser); + QQmlProperty topMarginProp {aliasUser, "topMargin"}; + QVERIFY(topMarginProp.isValid()); + topMarginProp.write(777); + QObject *myItem = object->findChild<QObject*>(QLatin1String("myItem")); + QVERIFY(myItem); + auto anchors = myItem->property("anchors").value<QObject*>(); + QVERIFY(anchors); + QCOMPARE(anchors->property("topMargin").toInt(), 777); + } + + // Binding to alias to grouped property gets updated + { + QQmlComponent component(&engine, testFileUrl("alias.17.qml")); + VERIFY_ERRORS(0); + + QScopedPointer<QObject> object(component.create()); + QVERIFY(!object.isNull()); + QObject *aliasUser = object->findChild<QObject*>(QLatin1String("aliasUser")); + QVERIFY(aliasUser); + QQmlProperty topMarginProp {aliasUser, "topMargin"}; + QVERIFY(topMarginProp.isValid()); + topMarginProp.write(20); + QObject *myText = object->findChild<QObject*>(QLatin1String("myText")); + QVERIFY(myText); + auto text = myText->property("text").toString(); + QCOMPARE(text, "alias:\n20"); + } } // QTBUG-13374 Test that alias properties and signals can coexist |