aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2017-01-30 16:36:46 -0600
committerSimon Hausmann <simon.hausmann@qt.io>2017-02-03 07:41:36 +0000
commit89f8c55b6f89c26578b7be9f4db35d0b2ef75a67 (patch)
treeadb2abc4e74fe3c0da20325f263a1ce8e01b2c40
parent533f9591595c3933ac56a3b3f4422a8aa821cb00 (diff)
Enable PropertyChanges to correctly restore binding on alias
Change-Id: I88ffdd1d1224705e980e449b6c799c9f186143b1 Task-number: QTBUG-58271 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io> (cherry picked from commit 22b03fd6d3efdfa0385ced2450c6c7dfcf555d6e) Reviewed-by: Robin Burchell <robin.burchell@crimson.no>
-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 1eaff6b600..8818b95f0a 100644
--- a/src/qml/qml/qqmlproperty.cpp
+++ b/src/qml/qml/qqmlproperty.cpp
@@ -791,12 +791,12 @@ void QQmlPropertyPrivate::removeBinding(const QQmlProperty &that)
QQmlAbstractBinding *
QQmlPropertyPrivate::binding(QObject *object, int index)
{
+ findAliasTarget(object, index, &object, &index);
+
QQmlData *data = QQmlData::get(object);
if (!data)
return 0;
- findAliasTarget(object, index, &object, &index);
-
int coreIndex;
int valueTypeIndex = QQmlPropertyData::decodeValueTypePropertyIndex(index, &coreIndex);
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 86c13065fa..3fed0fac7b 100644
--- a/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
+++ b/tests/auto/qml/qqmlproperty/tst_qqmlproperty.cpp
@@ -140,6 +140,7 @@ private slots:
// Bugs
void crashOnValueProperty();
+ void aliasPropertyBindings_data();
void aliasPropertyBindings();
void noContext();
void assignEmptyVariantMap();
@@ -1823,23 +1824,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
@@ -1858,18 +1876,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
@@ -1880,12 +1898,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;
@@ -1986,7 +2004,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);