aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2017-01-30 16:36:46 -0600
committerMichael Brasser <michael.brasser@live.com>2017-02-02 19:23:34 +0000
commit22b03fd6d3efdfa0385ced2450c6c7dfcf555d6e (patch)
tree153a5bfc6d7d0803ae06de684e4f4882ca0b2b6c
parent9a009ccde8bfc522578533a114396a5e762d6d8f (diff)
Enable PropertyChanges to correctly restore binding on alias
Change-Id: I88ffdd1d1224705e980e449b6c799c9f186143b1 Task-number: QTBUG-58271 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/qml/qqmlproperty.cpp4
-rw-r--r--tests/auto/qml/qqmlproperty/data/aliasPropertyBindings2.qml23
-rw-r--r--tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp40
3 files changed, 54 insertions, 13 deletions
diff --git a/src/qml/qml/qqmlproperty.cpp b/src/qml/qml/qqmlproperty.cpp
index 0b8eb677cb..7df8336f51 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -790,12 +790,12 @@ void QQmlPropertyPrivate::removeBinding(const QQmlProperty &that)
QQmlAbstractBinding *
QQmlPropertyPrivate::binding(QObject *object, QQmlPropertyIndex index)
{
+ findAliasTarget(object, index, &object, &index);
+
QQmlData *data = QQmlData::get(object);
if (!data)
return 0;
- findAliasTarget(object, index, &object, &index);
-
const int coreIndex = index.coreIndex();
const int valueTypeIndex = index.valueTypeIndex();
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<QString>("file");
+ QTest::addColumn<QString>("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<QObject*>();
+
+ 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);