From de34e0e30b93eb9f245b668e2cf9513a7e6abd50 Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 20 Nov 2014 17:34:31 +0100 Subject: [PATCH] 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: Daniel Teske Reviewed-by: Eike Ziller --- share/qtcreator/templates/wizards/files/form/file.ui | 2 +- .../qtcreator/templates/wizards/files/form/wizard.json | 2 +- src/plugins/designer/formtemplatewizardpage.cpp | 2 +- src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp | 10 ++++++++-- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/share/qtcreator/templates/wizards/files/form/file.ui b/share/qtcreator/templates/wizards/files/form/file.ui index a12c1fffb0..d83113033f 100644 --- a/share/qtcreator/templates/wizards/files/form/file.ui +++ b/share/qtcreator/templates/wizards/files/form/file.ui @@ -1 +1 @@ -%{FormContents}\ +%{JS: [ %{FormContents} ].join('\n')}\ diff --git a/share/qtcreator/templates/wizards/files/form/wizard.json b/share/qtcreator/templates/wizards/files/form/wizard.json index 510f2d0ae1..835ccf8ffb 100644 --- a/share/qtcreator/templates/wizards/files/form/wizard.json +++ b/share/qtcreator/templates/wizards/files/form/wizard.json @@ -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}') }" } ], diff --git a/src/plugins/designer/formtemplatewizardpage.cpp b/src/plugins/designer/formtemplatewizardpage.cpp index 6d5abd5d79..f12c770ffa 100644 --- a/src/plugins/designer/formtemplatewizardpage.cpp +++ b/src/plugins/designer/formtemplatewizardpage.cpp @@ -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; } diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp index d5372b7923..ab9ba1a722 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizard.cpp @@ -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! -- GitLab