aboutsummaryrefslogtreecommitdiff
path: root/src/core/kcoreconfigskeleton.h
diff options
context:
space:
mode:
authorCyril Rossi <cyril.rossi@enioka.com>2020-01-24 17:14:51 +0100
committerCyril Rossi <cyril.rossi@enioka.com>2020-02-24 13:23:24 +0100
commitc8bf5e96cf2f25bb85330cf2587e2e365e6f0f71 (patch)
tree7a9866f61e7b7caf4f67f555f80d5ce852cdb775 /src/core/kcoreconfigskeleton.h
parent55aaa712b75b1401331e29aef08123556b0257f3 (diff)
downloadkconfig-c8bf5e96cf2f25bb85330cf2587e2e365e6f0f71.tar.gz
kconfig-c8bf5e96cf2f25bb85330cf2587e2e365e6f0f71.tar.bz2
KConfigSkeletonItem : allow to set a KconfigGroup to read and write items in nested groups
Summary: Currently KConfgiSkeleton cannot manage item entry in subgroup, like ``` [General][Colors] MyItem=foo ``` Example of use ``` // Generated Class with KConfig compiler, inherits KConfigSkeleton KConfigGroup generalGroup( &config, "General" ); KConfigGroup colorsGroup = config.group( "Colors" ) myItem->setGroup(cg); // Now can take a KConfigGroup addItem(myItem, "MyItem"); ``` Evolution of kconfig compiler will follow to consider this. Reviewers: ervin, dfaure, #frameworks, mdawson Reviewed By: ervin, dfaure Subscribers: kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D27059
Diffstat (limited to 'src/core/kcoreconfigskeleton.h')
-rw-r--r--src/core/kcoreconfigskeleton.h28
1 files changed, 26 insertions, 2 deletions
diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h
index 7abc4052..02473fb4 100644
--- a/src/core/kcoreconfigskeleton.h
+++ b/src/core/kcoreconfigskeleton.h
@@ -34,6 +34,7 @@
#include <QStringList>
#include <QVariant>
#include <QUrl>
+
class KCoreConfigSkeletonPrivate;
class KConfigSkeletonItemPrivate;
@@ -82,6 +83,22 @@ public:
QString group() const;
/**
+ * Set config file group but giving the KConfigGroup.
+ * Allow the item to be in nested groups.
+ * @since 5.68
+ */
+ void setGroup(const KConfigGroup &cg);
+
+ /**
+ * Return a KConfigGroup, the one provided by setGroup(KConfigGroup) if it's valid,
+ * or make one from @param config and item's group
+ * @sa setGroup(const QString &_group)
+ * @sa setGroup(KConfigGroup cg)
+ * @since 5.68
+ */
+ KConfigGroup configGroup(KConfig *config) const;
+
+ /**
* Set config file key.
*/
void setKey(const QString &_key);
@@ -366,7 +383,7 @@ public:
void writeConfig(KConfig *config) override
{
if (mReference != mLoadedValue) { // Is this needed?
- KConfigGroup cg(config, mGroup);
+ KConfigGroup cg = configGroup(config);
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
cg.revertToDefault(mKey, writeFlags());
} else {
@@ -436,10 +453,17 @@ public:
QVariant property() const override;
void setDefault() override;
void swapDefault() override;
- // shadow the method in KConfigSkeletonItem, which should be fine for autogenerated code
// KF6 TODO - fix this
+ // Ideally we would do this in an overload of KConfigSkeletonItem, but
+ // given we can't, I've shadowed the method. This isn't pretty, but given
+ // the docs say it should generally only be used from auto generated code,
+ // should be fine.
void setWriteFlags(KConfigBase::WriteConfigFlags flags);
KConfigBase::WriteConfigFlags writeFlags() const;
+ void setGroup(const KConfigGroup &cg);
+ KConfigGroup configGroup(KConfig *config) const;
+ // END TODO
+
private:
inline void invokeNotifyFunction()
{