Commit de34e0e3 authored by Tobias Hunger's avatar Tobias Hunger

FormWizard: Fix newlines being escaped in generated output

Export the form contents as a list of lines and join them when
needed instead of hoping to unescape '\\n' in all places where
it is necessary.

This approach should be a bit saver since it will cause parse
errors in the wizard, which are more visible than broken output
in the generated files.

Task-number: QTCREATORBUG-13456
Change-Id: I434a9227082f92be3c2ce75006f61ac79a2b6fd6
Reviewed-by: default avatarDaniel Teske <daniel.teske@theqtcompany.com>
Reviewed-by: default avatarEike Ziller <eike.ziller@theqtcompany.com>
parent 3382efb7
%{FormContents}\
%{JS: [ %{FormContents} ].join('\n')}\
......@@ -10,7 +10,7 @@
"featuresRequired": [ "Plugin.Designer" ],
"options": [
{ "key": "UiClass", "value": "%{JS: QtSupport.uiClassName('%{FormContents}') }" },
{ "key": "UiClass", "value": "%{JS: QtSupport.uiClassName([ %{FormContents} ].join('\\n'))}" },
{ "key": "Extension", "value": "%{JS: Util.preferredSuffix('application/x-designer')}"},
{ "key": "InitialFileName", "value": "%{JS: Cpp.classToFileName('%{UiClass}', '%{Extension}') }" }
],
......
......@@ -122,7 +122,7 @@ bool FormTemplateWizardPage::validatePage()
QMessageBox::critical(this, tr("%1 - Error").arg(title()), errorMessage);
return false;
}
wizard()->setProperty("FormContents", m_templateContents.replace(QLatin1Char('\n'), QLatin1String("\\n")));
wizard()->setProperty("FormContents", m_templateContents.split(QLatin1Char('\n')));
return true;
}
......
......@@ -124,10 +124,16 @@ QVariant JsonWizard::value(const QString &n) const
{
QVariant v = property(n.toUtf8());
if (v.isValid()) {
if (v.type() == QVariant::String)
if (v.type() == QVariant::String) {
return m_expander.expand(v.toString());
else
} 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('\'')));
} else {
return v;
}
}
if (hasField(n))
return field(n); // Can not contain macros!
......
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