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:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user