Commit 9324ef6e authored by Tobias Hunger's avatar Tobias Hunger
Browse files

JsonWizard: Allow object or list of objects for "options"



This is compatible with the existing wizards and makes writing a wizard
a tiny bit simpler and more consistent.

Change-Id: I72c6f858f337552fe2495a16beff17cdf0cce66d
Reviewed-by: Orgad Shaneh's avatarOrgad Shaneh <orgads@gmail.com>
parent ed74b03d
...@@ -625,29 +625,28 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir, ...@@ -625,29 +625,28 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
setFlags(flags); setFlags(flags);
// Options: // Options:
QVariant optionValue = data.value(QLatin1String(OPTIONS_KEY)); const QVariant optionValue = data.value(QLatin1String(OPTIONS_KEY));
if (optionValue.type() == QVariant::List) { const QVariantList optionList = objectOrList(optionValue, errorMessage);
foreach (const QVariant &v, optionValue.toList()) { if (optionList.isEmpty())
if (v.type() != QVariant::Map) {
*errorMessage = tr("List element of \"options\" is not an object.");
return false;
}
QVariantMap data = v.toMap();
const QString key = data.value(QStringLiteral("key"), QString()).toString();
const QString value = data.value(QStringLiteral("value"), QString()).toString();
if (key.isEmpty()) {
*errorMessage = tr("No \"key\" given for entry in \"options\".");
return false;
}
if (m_options.contains(key)) {
*errorMessage = tr("When parsing \"options\": Key \"%1\" set more than once.").arg(key);
return false;
}
m_options.insert(key, value);
}
} else if (optionValue.isValid()) {
*errorMessage = tr("Value for \"options\" is not a list.");
return false; return false;
foreach (const QVariant &v, optionList) {
if (v.type() != QVariant::Map) {
*errorMessage = tr("List element of \"options\" is not an object.");
return false;
}
QVariantMap data = v.toMap();
const QString key = data.value(QStringLiteral("key"), QString()).toString();
const QString value = data.value(QStringLiteral("value"), QString()).toString();
if (key.isEmpty()) {
*errorMessage = tr("No \"key\" given for entry in \"options\".");
return false;
}
if (m_options.contains(key)) {
*errorMessage = tr("When parsing \"options\": Key \"%1\" set more than once.").arg(key);
return false;
}
m_options.insert(key, value);
} }
return true; return true;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment