Skip to content
Permalink
Browse files
Merge pull request #44152 from nirvn/application_regexp
Migrate away from QRegExp in the core application class
  • Loading branch information
nirvn committed Jul 14, 2021
2 parents 186d9d2 + f55fe4e commit 3a07af0ef1f747d6a0628a09abe013efb1502aac
@@ -16,6 +16,16 @@ with too big impact should be deferred to a major version release.

This page tries to maintain a list with incompatible changes that happened in previous releases.

QGIS 3.22 {#qgis_api_break_3_22}
=========

QgsApplication {#qgis_api_break_3_22_qgsapplication}
--------------

- QgsApplication::shortNameRegExp function was removed as part of a general code migration away from deprecated
QRegExp class. It has been replaced with QgsApplication::shortNameRegularExpression which returns a
QRegularExpression object.

QGIS 3.20 {#qgis_api_break_3_20}
=========

@@ -380,9 +380,15 @@ colors are specified then the ``size`` argument also must be set.
Returns the path to user's style.
%End

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

.. note::

This functionality was previously available as `shortNameRegExp` for QGIS <= 3.20

.. versionadded:: 3.22
%End

static QString userLoginName();
@@ -81,6 +81,7 @@
#include <QDesktopServices>
#include <QAbstractListModel>
#include <QList>
#include <QRegularExpressionValidator>

const char *QgsProjectProperties::GEO_NONE_DESC = QT_TRANSLATE_NOOP( "QgsOptions", "None / Planimetric" );

@@ -467,7 +468,7 @@ QgsProjectProperties::QgsProjectProperties( QgsMapCanvas *mapCanvas, QWidget *pa
mWMSOnlineResourceExpressionButton->setToProperty( QgsProject::instance()->dataDefinedServerProperties().property( QgsProject::DataDefinedServerProperty::WMSOnlineResource ) );

// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
QValidator *shortNameValidator = new QRegularExpressionValidator( QgsApplication::shortNameRegularExpression(), this );
mWMSName->setValidator( shortNameValidator );

// WMS Contact Position
@@ -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,9 +1178,9 @@ QString QgsApplication::userStylePath()
return qgisSettingsDirPath() + QStringLiteral( "symbology-style.db" );
}

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

@@ -404,8 +404,12 @@ 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();
/**
* Returns the short name regular expression for line edit validator
* \note This functionality was previously available as `shortNameRegExp` for QGIS <= 3.20
* \since QGIS 3.22
*/
static QRegularExpression shortNameRegularExpression();

/**
* Returns the user's operating system login account name.
@@ -16,14 +16,14 @@
#include "qgsapplication.h"
#include "qgsgroupwmsdatadialog.h"

#include <QRegExpValidator>
#include <QRegularExpressionValidator>

QgsGroupWmsDataDialog::QgsGroupWmsDataDialog( QWidget *parent, Qt::WindowFlags fl )
: QDialog( parent, fl )
{
setupUi( this );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
QValidator *shortNameValidator = new QRegularExpressionValidator( QgsApplication::shortNameRegularExpression(), this );
mShortNameLineEdit->setValidator( shortNameValidator );
}

@@ -87,6 +87,7 @@
#include <QUrl>
#include <QMenu>
#include <QScreen>
#include <QRegularExpressionValidator>

QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanvas *canvas, QWidget *parent, Qt::WindowFlags fl )
: QgsOptionsDialogBase( QStringLiteral( "RasterLayerProperties" ), parent, fl )
@@ -869,7 +870,7 @@ void QgsRasterLayerProperties::sync()
// WMS Name as layer short name
mLayerShortNameLineEdit->setText( mRasterLayer->shortName() );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
QValidator *shortNameValidator = new QRegularExpressionValidator( QgsApplication::shortNameRegularExpression(), this );
mLayerShortNameLineEdit->setValidator( shortNameValidator );

//layer title and abstract
@@ -87,6 +87,7 @@
#include <QColorDialog>
#include <QMenu>
#include <QUrl>
#include <QRegularExpressionValidator>

#include "qgsrendererpropertiesdialog.h"
#include "qgsstyle.h"
@@ -323,7 +324,7 @@ QgsVectorLayerProperties::QgsVectorLayerProperties(
// WMS Name as layer short name
mLayerShortNameLineEdit->setText( mLayer->shortName() );
// WMS Name validator
QValidator *shortNameValidator = new QRegExpValidator( QgsApplication::shortNameRegExp(), this );
QValidator *shortNameValidator = new QRegularExpressionValidator( QgsApplication::shortNameRegularExpression(), this );
mLayerShortNameLineEdit->setValidator( shortNameValidator );

//layer title and abstract

0 comments on commit 3a07af0

Please sign in to comment.