diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h --- 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 @@ */ 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 @@ 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 @@ 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() { diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp --- a/src/core/kcoreconfigskeleton.cpp +++ b/src/core/kcoreconfigskeleton.cpp @@ -64,6 +64,21 @@ mGroup = _group; } +void KConfigSkeletonItem::setGroup(const KConfigGroup &cg) +{ + Q_D(KConfigSkeletonItem); + d->mConfigGroup = cg; +} + +KConfigGroup KConfigSkeletonItem::configGroup(KConfig *config) const +{ + Q_D(const KConfigSkeletonItem); + if (d->mConfigGroup.isValid()) { + return d->mConfigGroup; + } + return KConfigGroup(config, mGroup); +} + QString KConfigSkeletonItem::group() const { return mGroup; @@ -276,7 +291,7 @@ void KCoreConfigSkeleton::ItemString::writeConfig(KConfig *config) { if (mReference != mLoadedValue) { // WABA: Is this test needed? - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if ((mDefault == mReference) && !cg.hasDefault(mKey)) { cg.revertToDefault(mKey, writeFlags()); } else if (mType == Path) { @@ -292,7 +307,7 @@ void KCoreConfigSkeleton::ItemString::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (mType == Path) { mReference = cg.readPathEntry(mKey, mDefault); @@ -347,7 +362,7 @@ void KCoreConfigSkeleton::ItemUrl::writeConfig(KConfig *config) { if (mReference != mLoadedValue) { // WABA: Is this test needed? - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if ((mDefault == mReference) && !cg.hasDefault(mKey)) { cg.revertToDefault(mKey, writeFlags()); } else { @@ -359,7 +374,7 @@ void KCoreConfigSkeleton::ItemUrl::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = QUrl(cg.readEntry(mKey, mDefault.toString())); mLoadedValue = mReference; @@ -392,7 +407,7 @@ void KCoreConfigSkeleton::ItemProperty::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -423,7 +438,7 @@ void KCoreConfigSkeleton::ItemBool::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -454,7 +469,7 @@ void KCoreConfigSkeleton::ItemInt::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); if (mHasMin) { mReference = qMax(mReference, mMin); @@ -519,7 +534,7 @@ void KCoreConfigSkeleton::ItemLongLong::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); if (mHasMin) { mReference = qMax(mReference, mMin); @@ -585,7 +600,7 @@ void KCoreConfigSkeleton::ItemEnum::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (!cg.hasKey(mKey)) { mReference = mDefault; } else { @@ -611,7 +626,7 @@ void KCoreConfigSkeleton::ItemEnum::writeConfig(KConfig *config) { if (mReference != mLoadedValue) { // WABA: Is this test needed? - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if ((mDefault == mReference) && !cg.hasDefault(mKey)) { cg.revertToDefault(mKey, writeFlags()); } else if ((mReference >= 0) && (mReference < mChoices.count())) { @@ -643,7 +658,7 @@ void KCoreConfigSkeleton::ItemUInt::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); if (mHasMin) { mReference = qMax(mReference, mMin); @@ -708,7 +723,7 @@ void KCoreConfigSkeleton::ItemULongLong::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); if (mHasMin) { mReference = qMax(mReference, mMin); @@ -773,7 +788,7 @@ void KCoreConfigSkeleton::ItemDouble::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); if (mHasMin) { mReference = qMax(mReference, mMin); @@ -838,7 +853,7 @@ void KCoreConfigSkeleton::ItemRect::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -869,7 +884,7 @@ void KCoreConfigSkeleton::ItemPoint::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -900,7 +915,7 @@ void KCoreConfigSkeleton::ItemSize::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -931,7 +946,7 @@ void KCoreConfigSkeleton::ItemDateTime::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); mReference = cg.readEntry(mKey, mDefault); mLoadedValue = mReference; @@ -962,7 +977,7 @@ void KCoreConfigSkeleton::ItemStringList::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (!cg.hasKey(mKey)) { mReference = mDefault; } else { @@ -997,7 +1012,7 @@ void KCoreConfigSkeleton::ItemPathList::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (!cg.hasKey(mKey)) { mReference = mDefault; } else { @@ -1011,7 +1026,7 @@ void KCoreConfigSkeleton::ItemPathList::writeConfig(KConfig *config) { if (mReference != mLoadedValue) { // WABA: Is this test needed? - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if ((mDefault == mReference) && !cg.hasDefault(mKey)) { cg.revertToDefault(mKey, writeFlags()); } else { @@ -1031,7 +1046,7 @@ void KCoreConfigSkeleton::ItemUrlList::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (!cg.hasKey(mKey)) { mReference = mDefault; } else { @@ -1053,7 +1068,7 @@ void KCoreConfigSkeleton::ItemUrlList::writeConfig(KConfig *config) { if (mReference != mLoadedValue) { // WABA: Is this test needed? - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if ((mDefault == mReference) && !cg.hasDefault(mKey)) { cg.revertToDefault(mKey, writeFlags()); } else { @@ -1091,7 +1106,7 @@ void KCoreConfigSkeleton::ItemIntList::readConfig(KConfig *config) { - KConfigGroup cg(config, mGroup); + KConfigGroup cg = configGroup(config); if (!cg.hasKey(mKey)) { mReference = mDefault; } else { @@ -1560,7 +1575,7 @@ QVariant oldValue = mItem->property(); mItem->readConfig(c); //readConfig() changes mIsImmutable, update it here as well - KConfigGroup cg(c, mGroup ); + KConfigGroup cg = configGroup(c); readImmutability(cg); if (!mItem->isEqual(oldValue)) { invokeNotifyFunction(); @@ -1571,7 +1586,7 @@ { mItem->readDefault(c); //readDefault() changes mIsImmutable, update it here as well - KConfigGroup cg(c, mGroup ); + KConfigGroup cg = configGroup(c); readImmutability(cg); } @@ -1615,3 +1630,13 @@ { return mItem->writeFlags(); } + +void KConfigCompilerSignallingItem::setGroup(const KConfigGroup &cg) +{ + mItem->setGroup(cg); +} + +KConfigGroup KConfigCompilerSignallingItem::configGroup(KConfig *config) const +{ + return mItem->configGroup(config); +} diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h --- a/src/core/kcoreconfigskeleton_p.h +++ b/src/core/kcoreconfigskeleton_p.h @@ -61,6 +61,7 @@ QString mLabel; ///< The label for this item QString mToolTip; ///< The ToolTip text for this item QString mWhatsThis; ///< The What's This text for this item + KConfigGroup mConfigGroup; ///< KConfigGroup, allow to read/write item in nested groups // HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem std::function mIsDefaultImpl;