Wizards: Simplify error message for invalid names

This commit is contained in:
Kai Koehne
2010-03-10 10:51:15 +01:00
parent 5d1463745a
commit d0da52f548
2 changed files with 11 additions and 6 deletions

View File

@@ -92,15 +92,20 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
{ {
if (name.isEmpty()) { if (name.isEmpty()) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The name must not be empty"); *errorMessage = tr("Name is empty.");
return false; return false;
} }
// Characters // Characters
const char *notAllowedChars = allowDirectories ? notAllowedCharsSubDir : notAllowedCharsNoSubDir; const char *notAllowedChars = allowDirectories ? notAllowedCharsSubDir : notAllowedCharsNoSubDir;
for (const char *c = notAllowedChars; *c; c++) for (const char *c = notAllowedChars; *c; c++)
if (name.contains(QLatin1Char(*c))) { if (name.contains(QLatin1Char(*c))) {
if (errorMessage) if (errorMessage) {
*errorMessage = tr("The name must not contain any of the characters '%1'.").arg(QLatin1String(notAllowedChars)); if (QChar(*c).isSpace()) {
*errorMessage = tr("Name contains white space.");
} else {
*errorMessage = tr("Invalid character '%1'.").arg(*c);
}
}
return false; return false;
} }
// Substrings // Substrings
@@ -109,7 +114,7 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
const QLatin1String notAllowedSubString(notAllowedSubStrings[s]); const QLatin1String notAllowedSubString(notAllowedSubStrings[s]);
if (name.contains(notAllowedSubString)) { if (name.contains(notAllowedSubString)) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The name must not contain '%1'.").arg(QString(notAllowedSubString)); *errorMessage = tr("Invalid characters '%1'.").arg(QString(notAllowedSubString));
return false; return false;
} }
} }
@@ -119,7 +124,7 @@ bool FileNameValidatingLineEdit::validateFileName(const QString &name,
matchesWinDevice = windowsDeviceSubDirPattern().exactMatch(name); matchesWinDevice = windowsDeviceSubDirPattern().exactMatch(name);
if (matchesWinDevice) { if (matchesWinDevice) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The name must not match that of a MS Windows device. (%1)."). *errorMessage = tr("Name matches MS Windows device. (%1).").
arg(windowsDeviceNoSubDirPattern().pattern().replace(QLatin1Char('|'), QLatin1Char(','))); arg(windowsDeviceNoSubDirPattern().pattern().replace(QLatin1Char('|'), QLatin1Char(',')));
return false; return false;
} }

View File

@@ -47,7 +47,7 @@ bool ProjectNameValidatingLineEdit::validateProjectName(const QString &name, QSt
// reason. Since we are cross-platform, we generally disallow it. // reason. Since we are cross-platform, we generally disallow it.
if (name.contains(QLatin1Char('.'))) { if (name.contains(QLatin1Char('.'))) {
if (errorMessage) if (errorMessage)
*errorMessage = tr("The name must not contain the '.'-character."); *errorMessage = tr("Invalid character '.'.");
return false; return false;
} }
return true; return true;