diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-13 12:39:44 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-13 14:32:40 +0100 |
commit | f1410debc7905e704b6ed16ae345e43765ef8ef5 (patch) | |
tree | 56c0acf733fff7bc08362b753bd7729421169709 /src/qml/util | |
parent | cfe0b08b5439a27b4fdd14c29620e0492543f506 (diff) |
Add a freeze() method to QQmlPropertyMap
After freezing a QQmlPropertyMap you cannot add any more properties, but
in turn the property access is cached, and therefore faster.
Task-number: QTBUG-57792
Change-Id: I2c6d768039c3b59eb2411194e463ee0de55f8bed
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/qml/util')
-rw-r--r-- | src/qml/util/qqmlpropertymap.cpp | 16 | ||||
-rw-r--r-- | src/qml/util/qqmlpropertymap.h | 1 |
2 files changed, 17 insertions, 0 deletions
diff --git a/src/qml/util/qqmlpropertymap.cpp b/src/qml/util/qqmlpropertymap.cpp index e38cf3a2a9..2bf8ab0190 100644 --- a/src/qml/util/qqmlpropertymap.cpp +++ b/src/qml/util/qqmlpropertymap.cpp @@ -204,6 +204,22 @@ void QQmlPropertyMap::clear(const QString &key) } /*! + \since 6.1 + + Disallows any further properties to be added to this property map. + Existing properties can be modified or cleared. + + In turn, an internal cache is turned on for the existing properties, which + may result in faster access from QML. + */ +void QQmlPropertyMap::freeze() +{ + Q_D(QQmlPropertyMap); + d->mo->setAutoCreatesProperties(false); + d->mo->setCached(true); +} + +/*! Returns the value associated with \a key. If no value has been set for this key (or if the value has been cleared), diff --git a/src/qml/util/qqmlpropertymap.h b/src/qml/util/qqmlpropertymap.h index 556754c021..de070673d7 100644 --- a/src/qml/util/qqmlpropertymap.h +++ b/src/qml/util/qqmlpropertymap.h @@ -62,6 +62,7 @@ public: void insert(const QString &key, const QVariant &value); void insert(const QVariantHash &values); void clear(const QString &key); + void freeze(); Q_INVOKABLE QStringList keys() const; |