aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas McGuire <thomas.mcguire@kdab.com>2016-07-25 13:23:34 +0200
committerSimon Hausmann <simon.hausmann@qt.io>2016-07-25 16:14:18 +0000
commit16b680b734101db0cb4fa3f313ac563a509ddff4 (patch)
treed4c389b36649a3e86dd8ec79fc8c7c57dedbe104
parentf32d0f724ff2010bfb69f8b1772a62b5a2141823 (diff)
QQmlPropertyMap: Don't spuriously emit valueChanged() signal
The valueChanged() signal was emitted when the property was written with the same value. This increased the potential for binding loops in user code. Change-Id: Ifeb8f6f23e2022aa35cb6cac7cf1a3dbc0e8ca2f Task-number: QTBUG-48136 Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r--src/qml/qml/qqmlopenmetaobject.cpp2
-rw-r--r--tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp35
2 files changed, 36 insertions, 1 deletions
diff --git a/src/qml/qml/qqmlopenmetaobject.cpp b/src/qml/qml/qqmlopenmetaobject.cpp
index 9188ba6174..0e60cae92f 100644
--- a/src/qml/qml/qqmlopenmetaobject.cpp
+++ b/src/qml/qml/qqmlopenmetaobject.cpp
@@ -272,7 +272,7 @@ int QQmlOpenMetaObject::metaCall(QObject *o, QMetaObject::Call c, int id, void *
propertyRead(propId);
*reinterpret_cast<QVariant *>(a[0]) = d->getData(propId);
} else if (c == QMetaObject::WriteProperty) {
- if (propId <= d->data.count() || d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
+ if (propId >= d->data.count() || d->data[propId].first != *reinterpret_cast<QVariant *>(a[0])) {
propertyWrite(propId);
QPair<QVariant, bool> &prop = d->getDataRef(propId);
prop.first = propertyWriteValue(propId, *reinterpret_cast<QVariant *>(a[0]));
diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
index 2f3754e42d..1649cde4ce 100644
--- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
+++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
@@ -65,6 +65,7 @@ private slots:
void QTBUG_35233();
void disallowExtending();
void QTBUG_35906();
+ void QTBUG_48136();
};
class LazyPropertyMap : public QQmlPropertyMap, public QQmlParserStatus
@@ -467,6 +468,40 @@ void tst_QQmlPropertyMap::QTBUG_35906()
QCOMPARE(value.toInt(), 42);
}
+void tst_QQmlPropertyMap::QTBUG_48136()
+{
+ static const char key[] = "mykey";
+ QQmlPropertyMap map;
+
+ //
+ // Test that the notify signal is emitted correctly
+ //
+
+ const int propIndex = map.metaObject()->indexOfProperty(key);
+ const QMetaProperty prop = map.metaObject()->property(propIndex);
+ QSignalSpy notifySpy(&map, QByteArray::number(QSIGNAL_CODE) + prop.notifySignal().methodSignature());
+
+ map.insert(key, 42);
+ QCOMPARE(notifySpy.count(), 1);
+ map.insert(key, 43);
+ QCOMPARE(notifySpy.count(), 2);
+ map.insert(key, 43);
+ QCOMPARE(notifySpy.count(), 2);
+ map.insert(key, 44);
+ QCOMPARE(notifySpy.count(), 3);
+
+ //
+ // Test that the valueChanged signal is emitted correctly
+ //
+ QSignalSpy valueChangedSpy(&map, &QQmlPropertyMap::valueChanged);
+ map.setProperty(key, 44);
+ QCOMPARE(valueChangedSpy.count(), 0);
+ map.setProperty(key, 45);
+ QCOMPARE(valueChangedSpy.count(), 1);
+ map.setProperty(key, 45);
+ QCOMPARE(valueChangedSpy.count(), 1);
+}
+
QTEST_MAIN(tst_QQmlPropertyMap)
#include "tst_qqmlpropertymap.moc"