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 <orgads@gmail.com>
This commit is contained in:
Tobias Hunger
2015-09-15 11:30:47 +02:00
parent ed74b03d1a
commit 9324ef6eb1

View File

@@ -625,9 +625,12 @@ 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())
return false;
foreach (const QVariant &v, optionList) {
if (v.type() != QVariant::Map) { if (v.type() != QVariant::Map) {
*errorMessage = tr("List element of \"options\" is not an object."); *errorMessage = tr("List element of \"options\" is not an object.");
return false; return false;
@@ -645,10 +648,6 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
} }
m_options.insert(key, value); m_options.insert(key, value);
} }
} else if (optionValue.isValid()) {
*errorMessage = tr("Value for \"options\" is not a list.");
return false;
}
return true; return true;
} }