From f4d222c9c447dfdf3e33c52aef3bbd7f207b2e8a Mon Sep 17 00:00:00 2001 From: Marco Martin Date: Wed, 11 Sep 2013 18:51:27 +0200 Subject: [PATCH] very crude support for a string default in choices still a long way to real enums --- examples/applets/config/contents/config/main.xml | 16 ++++++++-------- src/plasma/configloader.cpp | 15 ++++++++++++++- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/examples/applets/config/contents/config/main.xml b/examples/applets/config/contents/config/main.xml index 889f44149..f90376590 100644 --- a/examples/applets/config/contents/config/main.xml +++ b/examples/applets/config/contents/config/main.xml @@ -26,15 +26,15 @@ test2 - 0 + Value2 - - - - - - - + + + + + + + diff --git a/src/plasma/configloader.cpp b/src/plasma/configloader.cpp index 91d60a619..6db1b864b 100644 --- a/src/plasma/configloader.cpp +++ b/src/plasma/configloader.cpp @@ -223,11 +223,24 @@ void ConfigLoaderHandler::addItem() QDateTime::fromString(m_default), m_key); } else if (m_type == "enum") { m_key = (m_key.isEmpty()) ? m_name : m_key; + bool ok; + int value = m_default.toUInt(&ok); + //if is not an integer, try to find the string value among the registered choices + if (!ok) { + int i = 0; + foreach (const KConfigSkeleton::ItemEnum::Choice &choice, m_enumChoices) { + if (choice.name == m_default) { + value = i; + break; + } + ++i; + } + } KConfigSkeleton::ItemEnum *enumItem = new KConfigSkeleton::ItemEnum(m_config->currentGroup(), m_key, *d->newInt(), m_enumChoices, - m_default.toUInt()); + value); m_config->addItem(enumItem, m_name); item = enumItem; } else if (m_type == "font") {