diff options
author | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-09-19 20:02:50 +0200 |
---|---|---|
committer | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-10-11 18:11:27 +0200 |
commit | f7754f2bb3db666e4bfb2b82af079828e0086b84 (patch) | |
tree | db1120cab3fb234b0c4d9f55f626a93968ac3fa1 /src/core/kconfiggroup.cpp | |
parent | 13b79463dd80c84c7cf1c817c363e7747e4da034 (diff) | |
download | kconfig-f7754f2bb3db666e4bfb2b82af079828e0086b84.tar.gz kconfig-f7754f2bb3db666e4bfb2b82af079828e0086b84.tar.bz2 |
Create utility method for moving entries from one group to another
This will become especially useful when moving state data from the config file
to a dedicated state data file.
Task: https://phabricator.kde.org/T12549
Diffstat (limited to 'src/core/kconfiggroup.cpp')
-rw-r--r-- | src/core/kconfiggroup.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/core/kconfiggroup.cpp b/src/core/kconfiggroup.cpp index a15c45eb..be1f2b0e 100644 --- a/src/core/kconfiggroup.cpp +++ b/src/core/kconfiggroup.cpp @@ -1257,3 +1257,29 @@ void KConfigGroup::reparent(KConfigBase *parent, WriteConfigFlags pFlags) oldGroup.copyTo(this, pFlags); oldGroup.deleteGroup(); // so that the entries with the old group name are deleted on sync } + +void KConfigGroup::moveValuesTo(const QList<const char *> &keys, KConfigGroup &other, WriteConfigFlags pFlags) +{ + Q_ASSERT(isValid()); + Q_ASSERT(other.isValid()); + + for (const auto key : keys) { + const QByteArray groupName = name().toLocal8Bit(); + const auto entry = config()->d_ptr->lookupInternalEntry(groupName, key, KEntryMap::SearchLocalized); + + // Only write the entry if it is not null, if it is a global enry there is no point in moving it + if (!entry.mValue.isNull() && !entry.bGlobal) { + deleteEntry(key, pFlags); + KEntryMap::EntryOptions options = KEntryMap::EntryOption::EntryDirty; + if (entry.bDeleted) { + options |= KEntryMap::EntryDeleted; + } + + if (entry.bExpand) { + options |= KEntryMap::EntryExpansion; + } + + other.config()->d_ptr->setEntryData(other.name().toLocal8Bit(), key, entry.mValue, options); + } + } +} |