forked from qt-creator/qt-creator
Class name validation line edit can now force for capital letters
Qml components should be upper case. Makes the regular expression static. Change-Id: I46650df9b9ae10ceaf3bfb7f888db075f572735b Reviewed-by: Alessandro Portale <alessandro.portale@nokia.com>
This commit is contained in:
@@ -53,16 +53,16 @@ struct ClassNameValidatingLineEditPrivate {
|
||||
const QString m_namespaceDelimiter;
|
||||
bool m_namespacesEnabled;
|
||||
bool m_lowerCaseFileName;
|
||||
bool m_forceFirstCapitalLetter;
|
||||
};
|
||||
|
||||
// Match something like "Namespace1::Namespace2::ClassName".
|
||||
ClassNameValidatingLineEditPrivate:: ClassNameValidatingLineEditPrivate() :
|
||||
m_nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*")),
|
||||
m_namespaceDelimiter(QLatin1String("::")),
|
||||
m_namespacesEnabled(false),
|
||||
m_lowerCaseFileName(true)
|
||||
m_lowerCaseFileName(true),
|
||||
m_forceFirstCapitalLetter(false)
|
||||
{
|
||||
QTC_ASSERT(m_nameRegexp.isValid(), return);
|
||||
}
|
||||
|
||||
// --------------------- ClassNameValidatingLineEdit
|
||||
@@ -89,6 +89,8 @@ void ClassNameValidatingLineEdit::setNamespacesEnabled(bool b)
|
||||
|
||||
bool ClassNameValidatingLineEdit::validate(const QString &value, QString *errorMessage) const
|
||||
{
|
||||
static QRegExp nameRegexp(QLatin1String("[a-zA-Z_][a-zA-Z0-9_]*(::[a-zA-Z_][a-zA-Z0-9_]*)*"));
|
||||
QTC_ASSERT(nameRegexp.isValid(), return false);
|
||||
if (!d->m_namespacesEnabled && value.contains(QLatin1Char(':'))) {
|
||||
if (errorMessage)
|
||||
*errorMessage = tr("The class name must not contain namespace delimiters.");
|
||||
@@ -97,7 +99,7 @@ bool ClassNameValidatingLineEdit::validate(const QString &value, QString *errorM
|
||||
if (errorMessage)
|
||||
*errorMessage = tr("Please enter a class name.");
|
||||
return false;
|
||||
} else if (!d->m_nameRegexp.exactMatch(value)) {
|
||||
} else if (!nameRegexp.exactMatch(value)) {
|
||||
if (errorMessage)
|
||||
*errorMessage = tr("The class name contains invalid characters.");
|
||||
return false;
|
||||
@@ -120,6 +122,18 @@ void ClassNameValidatingLineEdit::slotChanged(const QString &t)
|
||||
}
|
||||
}
|
||||
|
||||
QString ClassNameValidatingLineEdit::fixInputString(const QString &string)
|
||||
{
|
||||
if (!forceFirstCapitalLetter())
|
||||
return string;
|
||||
|
||||
QString fixedString = string;
|
||||
if (!string.isEmpty() && string.at(0).isLower())
|
||||
fixedString[0] = string.at(0).toUpper();
|
||||
|
||||
return fixedString;
|
||||
}
|
||||
|
||||
QString ClassNameValidatingLineEdit::createClassName(const QString &name)
|
||||
{
|
||||
// Remove spaces and convert the adjacent characters to uppercase
|
||||
@@ -156,4 +170,14 @@ void ClassNameValidatingLineEdit::setLowerCaseFileName(bool v)
|
||||
d->m_lowerCaseFileName = v;
|
||||
}
|
||||
|
||||
bool ClassNameValidatingLineEdit::forceFirstCapitalLetter() const
|
||||
{
|
||||
return d->m_forceFirstCapitalLetter;
|
||||
}
|
||||
|
||||
void ClassNameValidatingLineEdit::setForceFirstCapitalLetter(bool b)
|
||||
{
|
||||
d->m_forceFirstCapitalLetter = b;
|
||||
}
|
||||
|
||||
} // namespace Utils
|
||||
|
||||
Reference in New Issue
Block a user