From 00d186ce10ee5c3f09a5ec4c224f444abe76ec22 Mon Sep 17 00:00:00 2001 From: Samuel Ghinet Date: Mon, 15 Nov 2021 16:56:52 +0200 Subject: [PATCH] QDS NewProject dialog: use friendly error message when regex does not match Instead of telling the user that the project name does not match a complex regular expression, we can tell him in English words what the rules are. Also, updates the icon of the status message so that, when the status is multiline, the icon appears at the top, rather than vertical center, on the left side of the text. Change-Id: I848b3858f5f92a09588b9646c56cbf743b06ea09 Reviewed-by: Qt CI Bot Reviewed-by: Eike Ziller --- .../imports/NewProjectDialog/Details.qml | 1 + src/libs/utils/projectintropage.cpp | 10 +++++++--- src/libs/utils/projectintropage.h | 2 +- .../jsonwizard/jsonwizardpagefactory_p.cpp | 6 +++++- src/plugins/studiowelcome/qdsnewdialog.cpp | 2 +- 5 files changed, 15 insertions(+), 6 deletions(-) diff --git a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml index 87a63dcefe8..786f17db064 100644 --- a/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml +++ b/share/qtcreator/qmldesigner/newprojectdialog/imports/NewProjectDialog/Details.qml @@ -127,6 +127,7 @@ Item { Image { id: statusIcon + Layout.alignment: Qt.AlignTop asynchronous: false } diff --git a/src/libs/utils/projectintropage.cpp b/src/libs/utils/projectintropage.cpp index 6e180496375..e5189759b03 100644 --- a/src/libs/utils/projectintropage.cpp +++ b/src/libs/utils/projectintropage.cpp @@ -61,6 +61,7 @@ public: Ui::ProjectIntroPage m_ui; bool m_complete = false; QRegularExpressionValidator m_projectNameValidator; + QString m_projectNameValidatorUserMessage; bool m_forceSubProject = false; FilePaths m_projectDirectories; }; @@ -124,10 +125,11 @@ void ProjectIntroPage::setFilePath(const FilePath &path) d->m_ui.pathChooser->setFilePath(path); } -void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression ®Ex) +void ProjectIntroPage::setProjectNameRegularExpression(const QRegularExpression ®Ex, const QString &userErrorMessage) { Q_ASSERT_X(regEx.isValid(), Q_FUNC_INFO, qPrintable(regEx.errorString())); d->m_projectNameValidator.setRegularExpression(regEx); + d->m_projectNameValidatorUserMessage = userErrorMessage; } void ProjectIntroPage::setProjectName(const QString &name) @@ -263,8 +265,10 @@ bool ProjectIntroPage::validateProjectName(const QString &name, QString *errorMe // a more detailed error message if (validatorState != QValidator::Acceptable && (pos == -1 || pos >= name.count())) { if (errorMessage) { - *errorMessage = tr("Name does not match \"%1\".").arg( - d->m_projectNameValidator.regularExpression().pattern()); + if (d->m_projectNameValidatorUserMessage.isEmpty()) + *errorMessage = tr("Project name is invalid."); + else + *errorMessage = d->m_projectNameValidatorUserMessage; } return false; } diff --git a/src/libs/utils/projectintropage.h b/src/libs/utils/projectintropage.h index 0bccd91f2b1..ea755d671ed 100644 --- a/src/libs/utils/projectintropage.h +++ b/src/libs/utils/projectintropage.h @@ -80,7 +80,7 @@ public slots: void setProjectName(const QString &name); void setDescription(const QString &description); void setUseAsDefaultPath(bool u); - void setProjectNameRegularExpression(const QRegularExpression ®Ex); + void setProjectNameRegularExpression(const QRegularExpression ®Ex, const QString &userErrorMessage); private: void slotChanged(); diff --git a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp index dad6e9539e9..c0349814e0a 100644 --- a/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp +++ b/src/plugins/projectexplorer/jsonwizard/jsonwizardpagefactory_p.cpp @@ -195,6 +195,7 @@ bool KitsPageFactory::validateData(Utils::Id typeId, const QVariant &data, QStri // -------------------------------------------------------------------- static const char KEY_PROJECT_NAME_VALIDATOR[] = "projectNameValidator"; +static const char KEY_PROJECT_NAME_VALIDATOR_USER_MESSAGE[] = "trProjectNameValidatorUserMessage"; ProjectPageFactory::ProjectPageFactory() { @@ -215,10 +216,13 @@ Utils::WizardPage *ProjectPageFactory::create(JsonWizard *wizard, Utils::Id type page->setDescription(wizard->expander()->expand(description)); QString projectNameValidator = tmp.value(QLatin1String(KEY_PROJECT_NAME_VALIDATOR)).toString(); + QString projectNameValidatorUserMessage + = JsonWizardFactory::localizedString(tmp.value(QLatin1String(KEY_PROJECT_NAME_VALIDATOR_USER_MESSAGE))); + if (!projectNameValidator.isEmpty()) { QRegularExpression regularExpression(projectNameValidator); if (regularExpression.isValid()) - page->setProjectNameRegularExpression(regularExpression); + page->setProjectNameRegularExpression(regularExpression, projectNameValidatorUserMessage); } return page; diff --git a/src/plugins/studiowelcome/qdsnewdialog.cpp b/src/plugins/studiowelcome/qdsnewdialog.cpp index b031a083bcf..9afca814dda 100644 --- a/src/plugins/studiowelcome/qdsnewdialog.cpp +++ b/src/plugins/studiowelcome/qdsnewdialog.cpp @@ -101,7 +101,7 @@ QdsNewDialog::QdsNewDialog(QWidget *parent) QObject::connect(&m_wizard, &WizardHandler::projectCanBeCreated, this, &QdsNewDialog::onProjectCanBeCreatedChanged); QObject::connect(&m_wizard, &WizardHandler::wizardCreationFailed, this, [this]() { - QMessageBox::critical(m_dialog, "New project", "Failed to initialize data"); + QMessageBox::critical(m_dialog, tr("New project"), tr("Failed to initialize data")); reject(); delete this; });