forked from qt-creator/qt-creator
JsonWizard: Add separate method to get stringified values
Have value(...) return a QVariant that is never mangeled and add a stringValue(...) method to retrieve stringified values. It is way easier to see who needs what now. Use this consistently in the JsonWizard and fix one place where a QVariant was expected but a stringified version was returned. Task-number: QTCREATORBUG-13486 Change-Id: I2c4e9188280940e529f0f60bcc18b9b7330865d1 Reviewed-by: Daniel Teske <daniel.teske@theqtcompany.com>
This commit is contained in:
@@ -48,9 +48,9 @@ void JsonFilePage::initializePage()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (fileName().isEmpty())
|
if (fileName().isEmpty())
|
||||||
setFileName(wiz->value(QLatin1String("InitialFileName")).toString());
|
setFileName(wiz->stringValue(QLatin1String("InitialFileName")));
|
||||||
if (path().isEmpty())
|
if (path().isEmpty())
|
||||||
setPath(wiz->value(QLatin1String("InitialPath")).toString());
|
setPath(wiz->stringValue(QLatin1String("InitialPath")));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool JsonFilePage::validatePage()
|
bool JsonFilePage::validatePage()
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ void JsonKitsPage::initializePage()
|
|||||||
|
|
||||||
connect(wiz, &JsonWizard::filesReady, this, &JsonKitsPage::setupProjectFiles);
|
connect(wiz, &JsonWizard::filesReady, this, &JsonKitsPage::setupProjectFiles);
|
||||||
|
|
||||||
const QString platform = wiz->value(QLatin1String("Platform")).toString();
|
const QString platform = wiz->stringValue(QLatin1String("Platform"));
|
||||||
const Core::FeatureSet preferred = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("PreferredFeatures")).toStringList());
|
const Core::FeatureSet preferred = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("PreferredFeatures")).toStringList());
|
||||||
const Core::FeatureSet required = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("RequiredFeatures")).toStringList());
|
const Core::FeatureSet required = Core::FeatureSet::fromStringList(wiz->value(QLatin1String("RequiredFeatures")).toStringList());
|
||||||
|
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ void JsonProjectPage::initializePage()
|
|||||||
{
|
{
|
||||||
JsonWizard *wiz = qobject_cast<JsonWizard *>(wizard());
|
JsonWizard *wiz = qobject_cast<JsonWizard *>(wizard());
|
||||||
QTC_ASSERT(wiz, return);
|
QTC_ASSERT(wiz, return);
|
||||||
setPath(wiz->value(QLatin1String("InitialPath")).toString());
|
setPath(wiz->stringValue(QLatin1String("InitialPath")));
|
||||||
|
|
||||||
setProjectName(uniqueProjectName(path()));
|
setProjectName(uniqueProjectName(path()));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ static QString generatedProjectFilePath(const QList<JsonWizard::GeneratorFile> &
|
|||||||
static IWizardFactory::WizardKind wizardKind(JsonWizard *wiz)
|
static IWizardFactory::WizardKind wizardKind(JsonWizard *wiz)
|
||||||
{
|
{
|
||||||
IWizardFactory::WizardKind kind = IWizardFactory::ProjectWizard;
|
IWizardFactory::WizardKind kind = IWizardFactory::ProjectWizard;
|
||||||
const QString kindStr = wiz->value(QLatin1String("kind")).toString();
|
const QString kindStr = wiz->stringValue(QLatin1String("kind"));
|
||||||
if (kindStr == QLatin1String(Core::Constants::WIZARD_KIND_PROJECT))
|
if (kindStr == QLatin1String(Core::Constants::WIZARD_KIND_PROJECT))
|
||||||
kind = IWizardFactory::ProjectWizard;
|
kind = IWizardFactory::ProjectWizard;
|
||||||
else if (kindStr == QLatin1String(Core::Constants::WIZARD_KIND_CLASS))
|
else if (kindStr == QLatin1String(Core::Constants::WIZARD_KIND_CLASS))
|
||||||
|
|||||||
@@ -46,14 +46,8 @@ JsonWizard::JsonWizard(QWidget *parent) :
|
|||||||
{
|
{
|
||||||
setMinimumSize(800, 500);
|
setMinimumSize(800, 500);
|
||||||
m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool {
|
m_expander.registerExtraResolver([this](const QString &name, QString *ret) -> bool {
|
||||||
QVariant v = value(name);
|
*ret = stringValue(name);
|
||||||
if (v.isValid()) {
|
return !ret->isNull();
|
||||||
if (v.type() == QVariant::Bool)
|
|
||||||
*ret = v.toBool() ? QLatin1String("true") : QString();
|
|
||||||
else
|
|
||||||
*ret = v.toString();
|
|
||||||
}
|
|
||||||
return v.isValid();
|
|
||||||
});
|
});
|
||||||
m_expander.registerPrefix("Exists", tr("Check whether a variable exists. Returns \"true\" if it does and an empty string if not."),
|
m_expander.registerPrefix("Exists", tr("Check whether a variable exists. Returns \"true\" if it does and an empty string if not."),
|
||||||
[this](const QString &value) -> QString
|
[this](const QString &value) -> QString
|
||||||
@@ -87,14 +81,14 @@ JsonWizard::GeneratorFiles JsonWizard::generateFileList()
|
|||||||
QString errorMessage;
|
QString errorMessage;
|
||||||
GeneratorFiles list;
|
GeneratorFiles list;
|
||||||
|
|
||||||
QString targetPath = value(QLatin1String("TargetPath")).toString();
|
QString targetPath = stringValue(QLatin1String("TargetPath"));
|
||||||
if (targetPath.isEmpty())
|
if (targetPath.isEmpty())
|
||||||
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
|
errorMessage = tr("Could not determine target path. \"TargetPath\" was not set on any page.");
|
||||||
|
|
||||||
if (m_files.isEmpty() && errorMessage.isEmpty()) {
|
if (m_files.isEmpty() && errorMessage.isEmpty()) {
|
||||||
emit preGenerateFiles();
|
emit preGenerateFiles();
|
||||||
foreach (JsonWizardGenerator *gen, m_generators) {
|
foreach (JsonWizardGenerator *gen, m_generators) {
|
||||||
Core::GeneratedFiles tmp = gen->fileList(&m_expander, value(QStringLiteral("WizardDir")).toString(),
|
Core::GeneratedFiles tmp = gen->fileList(&m_expander, stringValue(QStringLiteral("WizardDir")),
|
||||||
targetPath, &errorMessage);
|
targetPath, &errorMessage);
|
||||||
if (!errorMessage.isEmpty())
|
if (!errorMessage.isEmpty())
|
||||||
break;
|
break;
|
||||||
@@ -120,24 +114,25 @@ void JsonWizard::commitToFileList(const JsonWizard::GeneratorFiles &list)
|
|||||||
emit postGenerateFiles(m_files);
|
emit postGenerateFiles(m_files);
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant JsonWizard::value(const QString &n) const
|
QString JsonWizard::stringValue(const QString &n) const
|
||||||
{
|
{
|
||||||
QVariant v = property(n.toUtf8());
|
QVariant v = value(n);
|
||||||
if (v.isValid()) {
|
if (!v.isValid())
|
||||||
if (v.type() == QVariant::String) {
|
return QString();
|
||||||
|
|
||||||
|
if (v.type() == QVariant::Bool)
|
||||||
|
return v.toBool() ? QString::fromLatin1("true") : QString();
|
||||||
|
|
||||||
|
if (v.type() == QVariant::String)
|
||||||
return m_expander.expand(v.toString());
|
return m_expander.expand(v.toString());
|
||||||
} if (v.type() == QVariant::StringList) {
|
|
||||||
|
if (v.type() == QVariant::StringList) {
|
||||||
QStringList tmp = Utils::transform(v.toStringList(), [this](const QString &i) -> QString {
|
QStringList tmp = Utils::transform(v.toStringList(), [this](const QString &i) -> QString {
|
||||||
return m_expander.expand(i).replace(QLatin1Char('\''), QLatin1String("\\'"));
|
return m_expander.expand(i).replace(QLatin1Char('\''), QLatin1String("\\'"));
|
||||||
});
|
});
|
||||||
return QString(QString(QLatin1Char('\'')) + tmp.join(QLatin1String("', '")) + QString(QLatin1Char('\'')));
|
return QString(QString(QLatin1Char('\'')) + tmp.join(QLatin1String("', '")) + QString(QLatin1Char('\'')));
|
||||||
} else {
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
}
|
return v.toString();
|
||||||
if (hasField(n))
|
|
||||||
return field(n); // Can not contain macros!
|
|
||||||
return QVariant();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void JsonWizard::setValue(const QString &key, const QVariant &value)
|
void JsonWizard::setValue(const QString &key, const QVariant &value)
|
||||||
@@ -145,6 +140,16 @@ void JsonWizard::setValue(const QString &key, const QVariant &value)
|
|||||||
setProperty(key.toUtf8(), value);
|
setProperty(key.toUtf8(), value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QVariant JsonWizard::value(const QString &n) const
|
||||||
|
{
|
||||||
|
QVariant v = property(n.toUtf8());
|
||||||
|
if (v.isValid())
|
||||||
|
return v;
|
||||||
|
if (hasField(n))
|
||||||
|
return field(n); // Can not contain macros!
|
||||||
|
return QVariant();
|
||||||
|
}
|
||||||
|
|
||||||
bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expander)
|
bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expander)
|
||||||
{
|
{
|
||||||
if (v.type() == QVariant::String)
|
if (v.type() == QVariant::String)
|
||||||
|
|||||||
@@ -73,6 +73,8 @@ public:
|
|||||||
GeneratorFiles generateFileList();
|
GeneratorFiles generateFileList();
|
||||||
void commitToFileList(const GeneratorFiles &list);
|
void commitToFileList(const GeneratorFiles &list);
|
||||||
|
|
||||||
|
QString stringValue(const QString &n) const;
|
||||||
|
|
||||||
QVariant value(const QString &n) const;
|
QVariant value(const QString &n) const;
|
||||||
void setValue(const QString &key, const QVariant &value);
|
void setValue(const QString &key, const QVariant &value);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user