aboutsummaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2021-01-13 11:50:07 +0100
committerUlf Hermann <ulf.hermann@qt.io>2021-01-13 14:32:11 +0100
commitb64f8dacae36fca948933cf56498d5e4ad3e2a07 (patch)
tree3c41c0270d6b4ab13b104581b0f1024e0e3cddab /tests
parent315261a809778a8ac37c523741e021d6431ab85e (diff)
QQmlPropertyMap: Add a method to insert multiple values at once
This avoid re-building the metaobject for every property added. As rebuilding the metaobject is an effort linear in the number of properties, the runtime when adding multiple properties via singular insert() is quadratic in the number of properties. The plural insert() rebuilds the metaobject only once. Task-number: QTBUG-57792 Change-Id: I9513c4de047724e4141dab72aacfbdd840a3e465 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tests')
-rw-r--r--tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp60
1 files changed, 59 insertions, 1 deletions
diff --git a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
index 39af59d0b0..82930b3f4a 100644
--- a/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
+++ b/tests/auto/qml/qqmlpropertymap/tst_qqmlpropertymap.cpp
@@ -45,6 +45,7 @@ private slots:
void initTestCase();
void insert();
+ void insertMany();
void operatorInsert();
void operatorValue();
void clear();
@@ -153,6 +154,63 @@ void tst_QQmlPropertyMap::insert()
QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1));
}
+void tst_QQmlPropertyMap::insertMany()
+{
+ QHash<QString, QVariant> values;
+ values.insert(QLatin1String("key2"), 200);
+ values.insert(QLatin1String("key1"), "Hello World");
+ values.insert(QLatin1String("valueChange"), 1);
+ values.insert(QLatin1String("valueCHANGED"), 1);
+
+ QQmlPropertyMap map;
+ map.insert(values);
+ QCOMPARE(map.keys().count(), 4);
+ QVERIFY(map.contains(QLatin1String("key1")));
+ QCOMPARE(map.value(QLatin1String("key2")), QVariant(200));
+ QCOMPARE(map.value(QLatin1String("key1")), QVariant("Hello World"));
+ //but 'valueChange' should be ok
+ QVERIFY(map.contains(QLatin1String("valueChange")));
+ QCOMPARE(map.value(QLatin1String("valueChange")), QVariant(1));
+ //'valueCHANGED' should be ok, too
+ QVERIFY(map.contains(QLatin1String("valueCHANGED")));
+ QCOMPARE(map.value(QLatin1String("valueCHANGED")), QVariant(1));
+
+ values.insert(QLatin1String("keys"), 1);
+ values.insert(QStringLiteral("foobar"), 12);
+ values[QStringLiteral("key1")] = 100;
+ //inserting property names same with existing method(signal, slot, method) names is not allowed
+ //QQmlPropertyMap has an invokable keys() method
+ QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"keys\" is not permitted, conflicts with internal symbols.");
+ map.insert(values);
+ QCOMPARE(map.keys().count(), 4);
+ QVERIFY(!map.contains(QLatin1String("keys")));
+ QVERIFY(map.value(QLatin1String("keys")).isNull());
+
+ values.remove(QStringLiteral("keys"));
+ values.insert(QLatin1String("deleteLater"), 1);
+ //QQmlPropertyMap has a deleteLater() slot
+ QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"deleteLater\" is not permitted, conflicts with internal symbols.");
+ map.insert(values);
+ QCOMPARE(map.keys().count(), 4);
+ QVERIFY(!map.contains(QLatin1String("deleteLater")));
+ QVERIFY(map.value(QLatin1String("deleteLater")).isNull());
+
+ values.remove(QStringLiteral("deleteLater"));
+ values.insert(QLatin1String("valueChanged"), 1);
+ //QQmlPropertyMap has an valueChanged() signal
+ QTest::ignoreMessage(QtWarningMsg, "Creating property with name \"valueChanged\" is not permitted, conflicts with internal symbols.");
+ map.insert(values);
+ QCOMPARE(map.keys().count(), 4);
+ QVERIFY(!map.contains(QLatin1String("valueChanged")));
+ QVERIFY(map.value(QLatin1String("valueChanged")).isNull());
+
+ values.remove(QStringLiteral("valueChanged"));
+ map.insert(values); // Adds "foobar" and changes "key1"
+ QCOMPARE(map.keys().count(), 5);
+ QCOMPARE(map.value(QStringLiteral("foobar")).toInt(), 12);
+ QCOMPARE(map.value(QStringLiteral("key1")).toInt(), 100);
+}
+
void tst_QQmlPropertyMap::operatorInsert()
{
QQmlPropertyMap map;
@@ -216,7 +274,7 @@ void tst_QQmlPropertyMap::changed()
component.setData("import QtQuick 2.0\nText { text: { testdata.key1 = 'Hello World'; 'X' } }",
QUrl::fromLocalFile(""));
QVERIFY(component.isReady());
- QQuickText *txt = qobject_cast<QQuickText*>(component.create());
+ QScopedPointer<QQuickText> txt(qobject_cast<QQuickText*>(component.create()));
QVERIFY(txt);
QCOMPARE(txt->text(), QString('X'));
QCOMPARE(spy.count(), 1);