Commit 56a9b93a authored by Tobias Hunger's avatar Tobias Hunger
Browse files

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: default avatarTim Jenssen <tim.jenssen@theqtcompany.com>
parent 480f40c0
......@@ -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
......@@ -38,6 +38,8 @@
#include <utils/wizard.h>
#include <utils/macroexpander.h>
#include <QVariant>
namespace ProjectExplorer {
class JsonWizardGenerator;
......@@ -80,9 +82,17 @@ public:
class OptionDefinition {
public:
QString key;
QString value;
QString condition;
QString key() const { return m_key; }
QString value(Utils::MacroExpander &expander) const;
bool condition(Utils::MacroExpander &expander) const;
private:
QString m_key;
QString m_value;
QVariant m_condition;
QVariant m_evaluate;
friend class JsonWizard;
};
static QList<OptionDefinition> parseOptions(const QVariant &v, QString *errorMessage);
......
......@@ -395,8 +395,11 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
wizard->setValue(QStringLiteral("category"), category());
wizard->setValue(QStringLiteral("id"), id().toString());
foreach (const JsonWizard::OptionDefinition &od, m_options)
wizard->setValue(od.key, od.value);
Utils::MacroExpander *expander = wizard->expander();
foreach (const JsonWizard::OptionDefinition &od, m_options) {
if (od.condition(*expander))
wizard->setValue(od.key(), od.value(*expander));
}
bool havePage = false;
foreach (const Page &data, m_pages) {
......
......@@ -122,9 +122,8 @@ Core::GeneratedFile JsonWizardFileGenerator::generateFile(const File &file,
// evaluate file options once:
QHash<QString, QString> options;
foreach (const JsonWizard::OptionDefinition &od, file.options) {
if (!JsonWizard::boolFromVariant(od.condition, expander))
continue;
options.insert(od.key, od.value);
if (od.condition(*expander))
options.insert(od.key(), od.value(*expander));
}
nested.registerExtraResolver([&options](QString n, QString *ret) -> bool {
......
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