JsonWizard: Add option to put evaluated expressions into options

This is necessary to allow for constants that are not re-evaluated all
the time.

Change-Id: I4aec9d71aeae1a25ffa97eac177dd9c6fc6a90ca
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Tobias Hunger
2015-12-07 11:27:07 +01:00
parent 480f40c038
commit 56a9b93a28
4 changed files with 37 additions and 12 deletions

View File

@@ -157,11 +157,12 @@ QList<JsonWizard::OptionDefinition> JsonWizard::parseOptions(const QVariant &v,
foreach (const QVariant &o, optList) {
QVariantMap optionObject = o.toMap();
JsonWizard::OptionDefinition odef;
odef.key = optionObject.value(QLatin1String("key")).toString();
odef.value = optionObject.value(QLatin1String("value")).toString();
odef.condition = optionObject.value(QLatin1String("condition"), QLatin1String("true")).toString();
odef.m_key = optionObject.value(QLatin1String("key")).toString();
odef.m_value = optionObject.value(QLatin1String("value")).toString();
odef.m_condition = optionObject.value(QLatin1String("condition"), true);
odef.m_evaluate = optionObject.value(QLatin1String("evaluate"), false);
if (odef.key.isEmpty()) {
if (odef.m_key.isEmpty()) {
*errorMessage = QCoreApplication::translate("ProjectExplorer::Internal::JsonWizardFileGenerator",
"No 'key' in options object.");
result.clear();
@@ -383,4 +384,16 @@ void JsonWizard::openFiles(const JsonWizard::GeneratorFiles &files)
}
}
QString JsonWizard::OptionDefinition::value(Utils::MacroExpander &expander) const
{
if (JsonWizard::boolFromVariant(m_evaluate, &expander))
return expander.expand(m_value);
return m_value;
}
bool JsonWizard::OptionDefinition::condition(Utils::MacroExpander &expander) const
{
return JsonWizard::boolFromVariant(m_condition, &expander);
}
} // namespace ProjectExplorer