diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-01-10 15:59:07 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2018-01-12 07:03:29 +0000 |
commit | 4d6830546619d16275b01f1f049fdcb0b6489f7a (patch) | |
tree | feee3a660e22affd2ad4f6d5858478edecdac4df /tests/auto/qml/qqmlcontext | |
parent | 6318a43ffc473ba101c955d96b39bc1b93ef7e61 (diff) |
Add setContextProperties()
Setting all properties in one batch avoids unnecessary
refreshing of expressions and is therefore a lot
faster if there are many expressions in the context.
In an example I created it takes 500ms to set 10 context properties
using setContextProperty() and it takes about 150ms to set the
context properties using setContextProperties.
Change-Id: Ic7cf03cda292b316198f37f963b61a2388a288c9
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto/qml/qqmlcontext')
-rw-r--r-- | tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp index 5f57b9ebb0..5dfbd2e522 100644 --- a/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp +++ b/tests/auto/qml/qqmlcontext/tst_qqmlcontext.cpp @@ -47,6 +47,7 @@ private slots: void engineMethod(); void parentContext(); void setContextProperty(); + void setContextProperties(); void setContextObject(); void destruction(); void idAsContextProperty(); @@ -363,6 +364,32 @@ void tst_qqmlcontext::setContextProperty() } } +void tst_qqmlcontext::setContextProperties() +{ + QQmlContext ctxt(&engine); + + TestObject obj1; + obj1.setA(3345); + TestObject obj2; + obj2.setA(-19); + + QVector<QQmlContext::PropertyPair> properties; + + properties.append({QString("a"), QVariant(10)}); + properties.append({QString("b"), QVariant(19)}); + properties.append({QString("d"), QVariant::fromValue<TestObject*>(&obj2)}); + properties.append({QString("c"), QVariant(QString("Hello World!"))}); + properties.append({QString("e"), QVariant::fromValue<TestObject*>(&obj1)}); + + ctxt.setContextProperties(properties); + + TEST_CONTEXT_PROPERTY(&ctxt, a, QVariant(10)); + TEST_CONTEXT_PROPERTY(&ctxt, b, QVariant(19)); + TEST_CONTEXT_PROPERTY(&ctxt, c, QVariant(QString("Hello World!"))); + TEST_CONTEXT_PROPERTY(&ctxt, d.a, QVariant(-19)); + TEST_CONTEXT_PROPERTY(&ctxt, e.a, QVariant(3345)); +} + void tst_qqmlcontext::setContextObject() { QQmlContext ctxt(&engine); |