diff options
Diffstat (limited to 'src/qml/util')
-rw-r--r-- | src/qml/util/qqmlpropertymap.cpp | 30 | ||||
-rw-r--r-- | src/qml/util/qqmlpropertymap.h | 1 |
2 files changed, 31 insertions, 0 deletions
diff --git a/src/qml/util/qqmlpropertymap.cpp b/src/qml/util/qqmlpropertymap.cpp index e5fa66aded..e38cf3a2a9 100644 --- a/src/qml/util/qqmlpropertymap.cpp +++ b/src/qml/util/qqmlpropertymap.cpp @@ -234,6 +234,36 @@ void QQmlPropertyMap::insert(const QString &key, const QVariant &value) } /*! + \since 6.1 + + Inserts the \a values into the QQmlPropertyMap. + + Keys that don't exist are automatically created. + + This method is substantially faster than calling \c{insert(key, value)} + many times in a row. +*/ +void QQmlPropertyMap::insert(const QVariantHash &values) +{ + Q_D(QQmlPropertyMap); + + QHash<QByteArray, QVariant> checkedValues; + for (auto it = values.begin(), end = values.end(); it != end; ++it) { + const QString &key = it.key(); + if (!d->validKeyName(key)) { + qWarning() << "Creating property with name" + << key + << "is not permitted, conflicts with internal symbols."; + return; + } + + checkedValues.insert(key.toUtf8(), it.value()); + } + d->mo->setValues(checkedValues); + +} + +/*! Returns the list of keys. Keys that have been cleared will still appear in this list, even though their diff --git a/src/qml/util/qqmlpropertymap.h b/src/qml/util/qqmlpropertymap.h index d948989833..556754c021 100644 --- a/src/qml/util/qqmlpropertymap.h +++ b/src/qml/util/qqmlpropertymap.h @@ -60,6 +60,7 @@ public: QVariant value(const QString &key) const; void insert(const QString &key, const QVariant &value); + void insert(const QVariantHash &values); void clear(const QString &key); Q_INVOKABLE QStringList keys() const; |