aboutsummaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/kcoreconfigskeleton.cpp18
-rw-r--r--src/core/kcoreconfigskeleton.h11
-rw-r--r--src/core/kcoreconfigskeleton_p.h1
3 files changed, 28 insertions, 2 deletions
diff --git a/src/core/kcoreconfigskeleton.cpp b/src/core/kcoreconfigskeleton.cpp
index 5672a850..575ee721 100644
--- a/src/core/kcoreconfigskeleton.cpp
+++ b/src/core/kcoreconfigskeleton.cpp
@@ -590,6 +590,19 @@ void KCoreConfigSkeleton::ItemLongLong::setMaxValue(qint64 v)
mMax = v;
}
+QString KCoreConfigSkeleton::ItemEnum::valueForChoice(const QString &name) const
+{
+ // HACK for BC concerns
+ // TODO KF6: remove KConfigSkeletonItemPrivate::mValues and add a value field to KCoreConfigSkeleton::ItemEnum::Choice
+ const auto inHash = d_ptr->mValues.value(name);
+ return !inHash.isEmpty() ? inHash : name;
+}
+
+void KCoreConfigSkeleton::ItemEnum::setValueForChoice(const QString &name, const QString &value)
+{
+ d_ptr->mValues.insert(name, value);
+}
+
KCoreConfigSkeleton::ItemEnum::ItemEnum(const QString &_group, const QString &_key,
qint32 &reference,
const QList<Choice> &choices,
@@ -609,7 +622,8 @@ void KCoreConfigSkeleton::ItemEnum::readConfig(KConfig *config)
QString tmp = cg.readEntry(mKey, QString()).toLower();
for (QList<Choice>::ConstIterator it = mChoices.constBegin();
it != mChoices.constEnd(); ++it, ++i) {
- if ((*it).name.toLower() == tmp) {
+ QString choiceName = (*it).name;
+ if (valueForChoice(choiceName).toLower() == tmp) {
mReference = i;
break;
}
@@ -630,7 +644,7 @@ void KCoreConfigSkeleton::ItemEnum::writeConfig(KConfig *config)
if ((mDefault == mReference) && !cg.hasDefault(mKey)) {
cg.revertToDefault(mKey, writeFlags());
} else if ((mReference >= 0) && (mReference < mChoices.count())) {
- cg.writeEntry(mKey, mChoices[mReference].name, writeFlags());
+ cg.writeEntry(mKey, valueForChoice(mChoices.at(mReference).name), writeFlags());
} else {
cg.writeEntry(mKey, mReference, writeFlags());
}
diff --git a/src/core/kcoreconfigskeleton.h b/src/core/kcoreconfigskeleton.h
index 02473fb4..9d84583e 100644
--- a/src/core/kcoreconfigskeleton.h
+++ b/src/core/kcoreconfigskeleton.h
@@ -802,9 +802,20 @@ public:
void writeConfig(KConfig *config) override;
// Source compatibility with 4.x
+ // TODO KF6 remove
typedef Choice Choice2;
QList<Choice> choices2() const;
+ /**
+ * Returns the value for for the choice with the given name
+ */
+ QString valueForChoice(const QString &name) const;
+
+ /**
+ * Stores a choice value for name
+ */
+ void setValueForChoice(const QString &name, const QString &valueForChoice);
+
private:
QList<Choice> mChoices;
};
diff --git a/src/core/kcoreconfigskeleton_p.h b/src/core/kcoreconfigskeleton_p.h
index 8ba64db7..fcc9bc13 100644
--- a/src/core/kcoreconfigskeleton_p.h
+++ b/src/core/kcoreconfigskeleton_p.h
@@ -62,6 +62,7 @@ public:
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
+ QHash<QString, QString> mValues; /// The values used for ItemEnum's choices, name -> value (if set)
// HACK: Necessary to avoid introducing new virtuals in KConfigSkeletonItem
std::function<bool()> mIsDefaultImpl;