forked from qt-creator/qt-creator
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 <qt_ci_bot@qt-project.org> Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
@@ -127,6 +127,7 @@ Item {
|
|||||||
|
|
||||||
Image {
|
Image {
|
||||||
id: statusIcon
|
id: statusIcon
|
||||||
|
Layout.alignment: Qt.AlignTop
|
||||||
asynchronous: false
|
asynchronous: false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -61,6 +61,7 @@ public:
|
|||||||
Ui::ProjectIntroPage m_ui;
|
Ui::ProjectIntroPage m_ui;
|
||||||
bool m_complete = false;
|
bool m_complete = false;
|
||||||
QRegularExpressionValidator m_projectNameValidator;
|
QRegularExpressionValidator m_projectNameValidator;
|
||||||
|
QString m_projectNameValidatorUserMessage;
|
||||||
bool m_forceSubProject = false;
|
bool m_forceSubProject = false;
|
||||||
FilePaths m_projectDirectories;
|
FilePaths m_projectDirectories;
|
||||||
};
|
};
|
||||||
@@ -124,10 +125,11 @@ void ProjectIntroPage::setFilePath(const FilePath &path)
|
|||||||
d->m_ui.pathChooser->setFilePath(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()));
|
Q_ASSERT_X(regEx.isValid(), Q_FUNC_INFO, qPrintable(regEx.errorString()));
|
||||||
d->m_projectNameValidator.setRegularExpression(regEx);
|
d->m_projectNameValidator.setRegularExpression(regEx);
|
||||||
|
d->m_projectNameValidatorUserMessage = userErrorMessage;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProjectIntroPage::setProjectName(const QString &name)
|
void ProjectIntroPage::setProjectName(const QString &name)
|
||||||
@@ -263,8 +265,10 @@ bool ProjectIntroPage::validateProjectName(const QString &name, QString *errorMe
|
|||||||
// a more detailed error message
|
// a more detailed error message
|
||||||
if (validatorState != QValidator::Acceptable && (pos == -1 || pos >= name.count())) {
|
if (validatorState != QValidator::Acceptable && (pos == -1 || pos >= name.count())) {
|
||||||
if (errorMessage) {
|
if (errorMessage) {
|
||||||
*errorMessage = tr("Name does not match \"%1\".").arg(
|
if (d->m_projectNameValidatorUserMessage.isEmpty())
|
||||||
d->m_projectNameValidator.regularExpression().pattern());
|
*errorMessage = tr("Project name is invalid.");
|
||||||
|
else
|
||||||
|
*errorMessage = d->m_projectNameValidatorUserMessage;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -80,7 +80,7 @@ public slots:
|
|||||||
void setProjectName(const QString &name);
|
void setProjectName(const QString &name);
|
||||||
void setDescription(const QString &description);
|
void setDescription(const QString &description);
|
||||||
void setUseAsDefaultPath(bool u);
|
void setUseAsDefaultPath(bool u);
|
||||||
void setProjectNameRegularExpression(const QRegularExpression ®Ex);
|
void setProjectNameRegularExpression(const QRegularExpression ®Ex, const QString &userErrorMessage);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void slotChanged();
|
void slotChanged();
|
||||||
|
@@ -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[] = "projectNameValidator";
|
||||||
|
static const char KEY_PROJECT_NAME_VALIDATOR_USER_MESSAGE[] = "trProjectNameValidatorUserMessage";
|
||||||
|
|
||||||
ProjectPageFactory::ProjectPageFactory()
|
ProjectPageFactory::ProjectPageFactory()
|
||||||
{
|
{
|
||||||
@@ -215,10 +216,13 @@ Utils::WizardPage *ProjectPageFactory::create(JsonWizard *wizard, Utils::Id type
|
|||||||
page->setDescription(wizard->expander()->expand(description));
|
page->setDescription(wizard->expander()->expand(description));
|
||||||
QString projectNameValidator
|
QString projectNameValidator
|
||||||
= tmp.value(QLatin1String(KEY_PROJECT_NAME_VALIDATOR)).toString();
|
= tmp.value(QLatin1String(KEY_PROJECT_NAME_VALIDATOR)).toString();
|
||||||
|
QString projectNameValidatorUserMessage
|
||||||
|
= JsonWizardFactory::localizedString(tmp.value(QLatin1String(KEY_PROJECT_NAME_VALIDATOR_USER_MESSAGE)));
|
||||||
|
|
||||||
if (!projectNameValidator.isEmpty()) {
|
if (!projectNameValidator.isEmpty()) {
|
||||||
QRegularExpression regularExpression(projectNameValidator);
|
QRegularExpression regularExpression(projectNameValidator);
|
||||||
if (regularExpression.isValid())
|
if (regularExpression.isValid())
|
||||||
page->setProjectNameRegularExpression(regularExpression);
|
page->setProjectNameRegularExpression(regularExpression, projectNameValidatorUserMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
return page;
|
return page;
|
||||||
|
@@ -101,7 +101,7 @@ QdsNewDialog::QdsNewDialog(QWidget *parent)
|
|||||||
QObject::connect(&m_wizard, &WizardHandler::projectCanBeCreated, this, &QdsNewDialog::onProjectCanBeCreatedChanged);
|
QObject::connect(&m_wizard, &WizardHandler::projectCanBeCreated, this, &QdsNewDialog::onProjectCanBeCreatedChanged);
|
||||||
|
|
||||||
QObject::connect(&m_wizard, &WizardHandler::wizardCreationFailed, this, [this]() {
|
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();
|
reject();
|
||||||
delete this;
|
delete this;
|
||||||
});
|
});
|
||||||
|
Reference in New Issue
Block a user