aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qml/qqmlpropertymap
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 /tests/auto/qml/qqmlpropertymap
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>
Diffstat (limited to 'tests/auto/qml/qqmlpropertymap')
-rw-r--r--tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp35
1 files changed, 35 insertions, 0 deletions
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"