From c8bf5e96cf2f25bb85330cf2587e2e365e6f0f71 Mon Sep 17 00:00:00 2001 From: Cyril Rossi Date: Fri, 24 Jan 2020 17:14:51 +0100 Subject: 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 --- src/core/kcoreconfigskeleton.h | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'src/core/kcoreconfigskeleton.h') 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 #include #include + class KCoreConfigSkeletonPrivate; class KConfigSkeletonItemPrivate; @@ -81,6 +82,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. */ @@ -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() { -- cgit v1.2.1