Commit f09a87e5 authored by Tobias Hunger's avatar Tobias Hunger
Browse files

JsonWizard: Add helper to deal with string lists



Change-Id: I5d30f22367b365a71417c473cba3ce7125567a77
Reviewed-by: default avatarAlessandro Portale <alessandro.portale@theqtcompany.com>
parent b70d6395
......@@ -133,12 +133,9 @@ QString JsonWizard::stringValue(const QString &n) const
if (v.type() == QVariant::String)
return m_expander.expand(v.toString());
if (v.type() == QVariant::StringList) {
QStringList tmp = Utils::transform(v.toStringList(), [this](const QString &i) -> QString {
return m_expander.expand(i).replace(QLatin1Char('\''), QLatin1String("\\'"));
});
return QString(QString(QLatin1Char('\'')) + tmp.join(QLatin1String("', '")) + QString(QLatin1Char('\'')));
}
if (v.type() == QVariant::StringList)
return stringListToArrayString(v.toStringList(), &m_expander);
return v.toString();
}
......@@ -166,6 +163,24 @@ bool JsonWizard::boolFromVariant(const QVariant &v, Utils::MacroExpander *expand
return v.toBool();
}
QString JsonWizard::stringListToArrayString(const QStringList &list, const Utils::MacroExpander *expander)
{
// Todo: Handle ' embedded in the strings better.
if (list.isEmpty())
return QString();
QStringList tmp = Utils::transform(list, [expander](const QString &i) {
return expander->expand(i).replace(QLatin1Char('\''), QLatin1String("\\'"));
});
QString result;
result.append(QLatin1Char('\''));
result.append(tmp.join(QLatin1String("', '")));
result.append(QLatin1Char('\''));
return result;
}
void JsonWizard::removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a)
{
for (int i = 0; i < m_files.count(); ++i) {
......
......@@ -79,6 +79,8 @@ public:
void setValue(const QString &key, const QVariant &value);
static bool boolFromVariant(const QVariant &v, Utils::MacroExpander *expander);
static QString stringListToArrayString(const QStringList &list,
const Utils::MacroExpander *expander);
void removeAttributeFromAllFiles(Core::GeneratedFile::Attribute a);
......
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