Skip to content
Permalink
Browse files
Migrate away from QRegExp in the core application class
  • Loading branch information
nirvn committed Jul 14, 2021
1 parent 5762fe3 commit 03d99a42026a7ec543c0802136858c2d6bc873b9
@@ -380,9 +380,19 @@ colors are specified then the ``size`` argument also must be set.
Returns the path to user's style.
%End

static QRegExp shortNameRegExp();

static QRegExp shortNameRegExp() /Deprecated/;
%Docstring
Returns the short name regular expression for line edit validator

.. deprecated:: QGIS 3.22
%End

static QRegularExpression shortNameRegularExpression();
%Docstring
Returns the short name regular expression for line edit validator

.. versionadded:: 3.22
%End

static QString userLoginName();
@@ -21,6 +21,7 @@
#include "qgsprojectservervalidator.h"
#include "qgsvectorlayer.h"

#include <QRegularExpression>

QString QgsProjectServerValidator::displayValidationError( QgsProjectServerValidator::ValidationError error )
{
@@ -94,11 +95,11 @@ bool QgsProjectServerValidator::validate( QgsProject *project, QList<QgsProjectS
browseLayerTree( project->layerTreeRoot(), owsNames, encodingMessages );

QStringList duplicateNames, regExpMessages;
QRegExp snRegExp = QgsApplication::shortNameRegExp();
const QRegularExpression snRegExp = QgsApplication::shortNameRegularExpression();
const auto constOwsNames = owsNames;
for ( const QString &name : constOwsNames )
{
if ( !snRegExp.exactMatch( name ) )
if ( !snRegExp.match( name ).hasMatch() )
{
regExpMessages << name;
}
@@ -146,7 +147,7 @@ bool QgsProjectServerValidator::validate( QgsProject *project, QList<QgsProjectS
results << ValidationResult( QgsProjectServerValidator::ProjectRootNameConflict, rootLayerName );
}

if ( !snRegExp.exactMatch( rootLayerName ) )
if ( !snRegExp.match( rootLayerName ).hasMatch() )
{
result = false;
results << ValidationResult( QgsProjectServerValidator::ProjectShortName, rootLayerName );
@@ -1178,11 +1178,19 @@ QString QgsApplication::userStylePath()
return qgisSettingsDirPath() + QStringLiteral( "symbology-style.db" );
}

#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QRegExp QgsApplication::shortNameRegExp()
{
const thread_local QRegExp regexp( QStringLiteral( "^[A-Za-z][A-Za-z0-9\\._-]*" ) );
return regexp;
}
#endif

QRegularExpression QgsApplication::shortNameRegularExpression()
{
const thread_local QRegularExpression regexp( QRegularExpression::anchoredPattern( QStringLiteral( "^[A-Za-z][A-Za-z0-9\\._-]*" ) ) );
return regexp;
}

QString QgsApplication::userLoginName()
{
@@ -404,8 +404,20 @@ class CORE_EXPORT QgsApplication : public QApplication
//! Returns the path to user's style.
static QString userStylePath();

//! Returns the short name regular expression for line edit validator
static QRegExp shortNameRegExp();
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)

/**
* Returns the short name regular expression for line edit validator
* \deprecated since QGIS 3.22
*/
static QRegExp shortNameRegExp() SIP_DEPRECATED;
#endif

/**
* Returns the short name regular expression for line edit validator
* \since QGIS 3.22
*/
static QRegularExpression shortNameRegularExpression();

/**
* Returns the user's operating system login account name.

0 comments on commit 03d99a4

Please sign in to comment.