diff --git a/src/kdeclarative/configpropertymap.h b/src/kdeclarative/configpropertymap.h --- a/src/kdeclarative/configpropertymap.h +++ b/src/kdeclarative/configpropertymap.h @@ -43,6 +43,22 @@ ConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent = nullptr); ~ConfigPropertyMap() override; + /** + * Indicates if the map calls save() on the config object on each write or not + * + * @return true if the map automatically saves (the default), false otherwise + * @since 5.65 + */ + bool isAutosave() const; + + /** + * Allows to set the map into autosave mode or not + * + * @param autosave the new value for autosaving + * @since 5.65 + */ + void setAutosave(bool autosave); + /** * @brief Whether the value at the given key is immutable * diff --git a/src/kdeclarative/configpropertymap.cpp b/src/kdeclarative/configpropertymap.cpp --- a/src/kdeclarative/configpropertymap.cpp +++ b/src/kdeclarative/configpropertymap.cpp @@ -46,6 +46,7 @@ ConfigPropertyMap *q; QPointer config; bool updatingConfigValue = false; + bool autosave = true; }; ConfigPropertyMap::ConfigPropertyMap(KCoreConfigSkeleton *config, QObject *parent) @@ -68,10 +69,22 @@ ConfigPropertyMap::~ConfigPropertyMap() { - d->writeConfig(); + if (d->autosave) { + d->writeConfig(); + } delete d; } +bool KDeclarative::ConfigPropertyMap::isAutosave() const +{ + return d->autosave; +} + +void ConfigPropertyMap::setAutosave(bool autosave) +{ + d->autosave = autosave; +} + QVariant ConfigPropertyMap::updateValue(const QString &key, const QVariant &input) { Q_UNUSED(key); @@ -117,21 +130,25 @@ item->setProperty(q->value(item->key())); } - updatingConfigValue = true; - config.data()->save(); - updatingConfigValue = false; + if (autosave) { + updatingConfigValue = true; + config.data()->save(); + updatingConfigValue = false; + } } void ConfigPropertyMapPrivate::writeConfigValue(const QString &key, const QVariant &value) { KConfigSkeletonItem *item = config.data()->findItem(key); if (item) { updatingConfigValue = true; item->setProperty(value); - config.data()->save(); - //why read? read will update KConfigSkeletonItem::mLoadedValue, - //allowing a write operation to be performed next time - config.data()->read(); + if (autosave) { + config.data()->save(); + //why read? read will update KConfigSkeletonItem::mLoadedValue, + //allowing a write operation to be performed next time + config.data()->read(); + } updatingConfigValue = false; } }