From 22b03fd6d3efdfa0385ced2450c6c7dfcf555d6e Mon Sep 17 00:00:00 2001 From: Michael Brasser Date: Mon, 30 Jan 2017 16:36:46 -0600 Subject: Enable PropertyChanges to correctly restore binding on alias Change-Id: I88ffdd1d1224705e980e449b6c799c9f186143b1 Task-number: QTBUG-58271 Reviewed-by: Simon Hausmann --- .../qqmlproperty/data/aliasPropertyBindings2.qml | 23 +++++++++++++ tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp | 40 ++++++++++++++++------ 2 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 tests/auto/qml/qqmlproperty/data/aliasPropertyBindings2.qml (limited to 'tests/auto/qml/qqmlproperty') diff --git a/tests/auto/qml/qqmlproperty/data/aliasPropertyBindings2.qml b/tests/auto/qml/qqmlproperty/data/aliasPropertyBindings2.qml new file mode 100644 index 0000000000..60cb088209 --- /dev/null +++ b/tests/auto/qml/qqmlproperty/data/aliasPropertyBindings2.qml @@ -0,0 +1,23 @@ +import QtQuick 2.0 + +Item { + id: root + + property real test: 9 + property real test2: 3 + + property alias aliasProperty: innerObject.realProperty + + property QtObject innerObject: QtObject { + id: innerObject + property real realProperty: test * test + test + } + + states: State { + name: "switch" + PropertyChanges { + target: root + aliasProperty: 32 * test2 + } + } +} diff --git a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp index 385ffc523a..84a1bd9cc5 100644 --- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp +++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp @@ -135,6 +135,7 @@ private slots: // Bugs void crashOnValueProperty(); + void aliasPropertyBindings_data(); void aliasPropertyBindings(); void noContext(); void assignEmptyVariantMap(); @@ -1833,23 +1834,40 @@ void tst_qqmlproperty::crashOnValueProperty() QCOMPARE(p.read(), QVariant(20)); } -// QTBUG-13719 +void tst_qqmlproperty::aliasPropertyBindings_data() +{ + QTest::addColumn("file"); + QTest::addColumn("subObject"); + + QTest::newRow("same object") << "aliasPropertyBindings.qml" << ""; + QTest::newRow("different objects") << "aliasPropertyBindings2.qml" << "innerObject"; +} + +// QTBUG-13719, QTBUG-58271 void tst_qqmlproperty::aliasPropertyBindings() { - QQmlComponent component(&engine, testFileUrl("aliasPropertyBindings.qml")); + QFETCH(QString, file); + QFETCH(QString, subObject); + + QQmlComponent component(&engine, testFileUrl(file)); QObject *object = component.create(); QVERIFY(object != 0); - QCOMPARE(object->property("realProperty").toReal(), 90.); + // the object where realProperty lives + QObject *realPropertyObject = object; + if (!subObject.isEmpty()) + realPropertyObject = object->property(subObject.toLatin1()).value(); + + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 90.); QCOMPARE(object->property("aliasProperty").toReal(), 90.); object->setProperty("test", 10); - QCOMPARE(object->property("realProperty").toReal(), 110.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 110.); QCOMPARE(object->property("aliasProperty").toReal(), 110.); - QQmlProperty realProperty(object, QLatin1String("realProperty")); + QQmlProperty realProperty(realPropertyObject, QLatin1String("realProperty")); QQmlProperty aliasProperty(object, QLatin1String("aliasProperty")); // Check there is a binding on these two properties @@ -1868,18 +1886,18 @@ void tst_qqmlproperty::aliasPropertyBindings() QCOMPARE(QQmlPropertyPrivate::binding(realProperty), QQmlPropertyPrivate::binding(aliasProperty)); - QCOMPARE(object->property("realProperty").toReal(), 96.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 96.); QCOMPARE(object->property("aliasProperty").toReal(), 96.); // Check the old binding really has not effect any more object->setProperty("test", 4); - QCOMPARE(object->property("realProperty").toReal(), 96.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 96.); QCOMPARE(object->property("aliasProperty").toReal(), 96.); object->setProperty("test2", 9); - QCOMPARE(object->property("realProperty").toReal(), 288.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 288.); QCOMPARE(object->property("aliasProperty").toReal(), 288.); // Revert @@ -1890,12 +1908,12 @@ void tst_qqmlproperty::aliasPropertyBindings() QCOMPARE(QQmlPropertyPrivate::binding(realProperty), QQmlPropertyPrivate::binding(aliasProperty)); - QCOMPARE(object->property("realProperty").toReal(), 20.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 20.); QCOMPARE(object->property("aliasProperty").toReal(), 20.); object->setProperty("test2", 3); - QCOMPARE(object->property("realProperty").toReal(), 20.); + QCOMPARE(realPropertyObject->property("realProperty").toReal(), 20.); QCOMPARE(object->property("aliasProperty").toReal(), 20.); delete object; @@ -1996,7 +2014,7 @@ void tst_qqmlproperty::warnOnInvalidBinding() QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData()); // V8 error message for invalid binding to anchor - expectedWarning = testUrl.toString() + QString::fromLatin1(":14:33: Unable to assign QQuickItem_QML_6 to QQuickAnchorLine"); + expectedWarning = testUrl.toString() + QString::fromLatin1(":14:33: Unable to assign QQuickItem_QML_8 to QQuickAnchorLine"); QTest::ignoreMessage(QtWarningMsg, expectedWarning.toLatin1().constData()); QQmlComponent component(&engine, testUrl); -- cgit v1.2.3