From ec207330d5bd61799a47092bf555a523ab000f93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9ven=20Car?= Date: Thu, 5 Mar 2020 10:02:46 +0100 Subject: KconfigXT: Add a value attribute to Enum field choices Summary: Allow to write choices such as : ``` ``` Test Plan: ctest Reviewers: ervin, bport, crossi, #frameworks Reviewed By: ervin Subscribers: ngraham, davidre, kde-frameworks-devel Tags: #frameworks Differential Revision: https://phabricator.kde.org/D27463 --- src/kconfig_compiler/KConfigSourceGenerator.cpp | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) (limited to 'src/kconfig_compiler/KConfigSourceGenerator.cpp') diff --git a/src/kconfig_compiler/KConfigSourceGenerator.cpp b/src/kconfig_compiler/KConfigSourceGenerator.cpp index 33e0ed69..3e8a8156 100644 --- a/src/kconfig_compiler/KConfigSourceGenerator.cpp +++ b/src/kconfig_compiler/KConfigSourceGenerator.cpp @@ -313,13 +313,14 @@ void KConfigSourceGenerator::createEnums(const CfgEntry *entry) void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QString &key) { + const QString itemVarStr = itemPath(entry, cfg()); const QString innerItemVarStr = innerItemVar(entry, cfg()); if (!entry->signalList.isEmpty()) { stream() << " " << innerItemVarStr << " = " << newInnerItem(entry, key, entry->defaultValue, cfg()) << '\n'; } - stream() << " " << itemPath(entry, cfg()) << " = " + stream() << " " << itemVarStr << " = " << newItem(entry, key, entry->defaultValue, cfg()) << '\n'; if (!entry->min.isEmpty()) { @@ -335,10 +336,16 @@ void KConfigSourceGenerator::createNormalEntry(const CfgEntry *entry, const QStr } if (cfg().allNotifiers || cfg().notifiers.contains(entry->name)) { - stream() << " " << itemPath(entry, cfg()) << "->setWriteFlags(KConfigBase::Notify);\n"; + stream() << " " << itemVarStr << "->setWriteFlags(KConfigBase::Notify);\n"; } - stream() << " addItem( " << itemPath(entry, cfg()); + for (const CfgEntry::Choice &choice : qAsConst(entry->choices.choices)) { + if (!choice.val.isEmpty()) { + stream() << " " << itemVarStr << "->setValueForChoice(QStringLiteral( \"" << choice.name << "\" ), QStringLiteral( \"" << choice.val << "\" ));\n"; + } + } + + stream() << " addItem( " << itemVarStr; QString quotedName = entry->name; addQuotes(quotedName); if (quotedName != key) { @@ -374,6 +381,12 @@ void KConfigSourceGenerator::createIndexedEntry(const CfgEntry *entry, const QSt stream() << " " << innerItemVarStr << "->setMaxValue(" << entry->max << ");\n"; } + for (const CfgEntry::Choice &choice : qAsConst(entry->choices.choices)) { + if (!choice.val.isEmpty()) { + stream() << " " << itemVarStr << "->setValueForChoice(QStringLiteral( \"" << choice.name << "\" ), QStringLiteral( \"" << choice.val << "\" ));\n"; + } + } + if (cfg().setUserTexts) { stream() << userTextsFunctions(entry, cfg(), itemVarStr, entry->paramName); } -- cgit v1.2.1