From 8232ca626c6ea6a6adc15f1329420f93c7c28d4b Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 29 Oct 2019 16:21:26 +0100 Subject: [PATCH] [users] Refactor constants --- src/modules/users/UsersPage.cpp | 12 ++++++++---- src/modules/users/UsersPage.h | 6 ------ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/modules/users/UsersPage.cpp b/src/modules/users/UsersPage.cpp index 579162675..a60532022 100644 --- a/src/modules/users/UsersPage.cpp +++ b/src/modules/users/UsersPage.cpp @@ -45,6 +45,12 @@ #include #include +static const QRegExp USERNAME_RX( "^[a-z_][a-z0-9_-]*[$]?$" ); +static const QRegExp HOSTNAME_RX( "^[a-zA-Z0-9][-a-zA-Z0-9_]*$" ); +static constexpr const int USERNAME_MAX_LENGTH = 31; +static constexpr const int HOSTNAME_MIN_LENGTH = 2; +static constexpr const int HOSTNAME_MAX_LENGTH = 63; + /** Add an error message and pixmap to a label. */ static inline void labelError( QLabel* pix, QLabel* label, const QString& message ) @@ -299,8 +305,7 @@ void UsersPage::validateUsernameText( const QString& textRef ) { QString text( textRef ); - QRegExp rx( USERNAME_RX ); - QRegExpValidator val( rx ); + QRegExpValidator val( USERNAME_RX ); int pos = -1; if ( text.isEmpty() ) @@ -344,8 +349,7 @@ void UsersPage::validateHostnameText( const QString& textRef ) { QString text = textRef; - QRegExp rx( HOSTNAME_RX ); - QRegExpValidator val( rx ); + QRegExpValidator val( HOSTNAME_RX ); int pos = -1; if ( text.isEmpty() ) diff --git a/src/modules/users/UsersPage.h b/src/modules/users/UsersPage.h index 9deb1d253..d8aed07fc 100644 --- a/src/modules/users/UsersPage.h +++ b/src/modules/users/UsersPage.h @@ -79,12 +79,6 @@ private: PasswordCheckList m_passwordChecks; - const QRegExp USERNAME_RX = QRegExp( "^[a-z_][a-z0-9_-]*[$]?$" ); - const QRegExp HOSTNAME_RX = QRegExp( "^[a-zA-Z0-9][-a-zA-Z0-9_]*$" ); - const int USERNAME_MAX_LENGTH = 31; - const int HOSTNAME_MIN_LENGTH = 2; - const int HOSTNAME_MAX_LENGTH = 63; - bool m_readyFullName; bool m_readyUsername; bool m_customUsername;