Skip to content
Permalink
Browse files
[qt6][gdal][ogr] Migrate away from QRegExp
  • Loading branch information
nirvn committed Jul 14, 2021
1 parent 5762fe3 commit 90a5f369263ce40b5e0eade9e3778226c36a7380
@@ -30,10 +30,12 @@
#include "qgsprovidersublayerdetails.h"

#include <QFileInfo>
#include <mutex>
#include <QRegularExpression>
#include <QUrlQuery>
#include <QUrl>

#include <mutex>

// defined in qgsgdalprovider.cpp
void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QStringList &extensions, QStringList &wildcards );

@@ -225,8 +227,8 @@ QgsDataItem *QgsGdalDataItemProvider::createDataItem( const QString &pathIn, Qgs
const auto constSWildcards = sWildcards;
for ( const QString &wildcard : constSWildcards )
{
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( rx.exactMatch( info.fileName() ) )
const QRegularExpression rx( QRegularExpression::wildcardToRegularExpression( wildcard ), QRegularExpression::CaseInsensitiveOption );
if ( rx.match( info.fileName() ).hasMatch() )
{
matches = true;
break;
@@ -2455,7 +2455,7 @@ void buildSupportedRasterFileFilterAndExtensions( QString &fileFiltersString, QS
QString myGdalDriverLongName = GDALGetMetadataItem( myGdalDriver, GDAL_DMD_LONGNAME, "" );
// remove any superfluous (.*) strings at the end as
// they'll confuse QFileDialog::getOpenFileNames()
myGdalDriverLongName.remove( QRegExp( "\\(.*\\)$" ) );
myGdalDriverLongName.remove( QRegularExpression( "\\(.*\\)$" ) );

// if we have both the file name extension and the long name,
// then we've all the information we need for the current
@@ -630,8 +630,8 @@ QgsDataItem *QgsOgrDataItemProvider::createDataItem( const QString &pathIn, QgsD
const auto constWildcards = QgsOgrProviderUtils::wildcards();
for ( const QString &wildcard : constWildcards )
{
QRegExp rx( wildcard, Qt::CaseInsensitive, QRegExp::Wildcard );
if ( rx.exactMatch( info.fileName() ) )
const QRegularExpression rx( QRegularExpression::wildcardToRegularExpression( wildcard ), QRegularExpression::CaseInsensitiveOption );
if ( rx.match( info.fileName() ).hasMatch() )
{
matches = true;
break;
@@ -18,10 +18,6 @@

#include "qgsproviderregistry.h"

#include <QString>
#include <QDir>
#include <QLibrary>

#include "qgis.h"
#include "qgsdataprovider.h"
#include "qgsdataitemprovider.h"
@@ -51,6 +47,11 @@
#include "qgspostgresprovider.h"
#endif

#include <QString>
#include <QDir>
#include <QLibrary>
#include <QRegularExpression>

static QgsProviderRegistry *sInstance = nullptr;

QgsProviderRegistry *QgsProviderRegistry::instance( const QString &pluginPath )
@@ -218,7 +219,7 @@ void QgsProviderRegistry::init()

// provider file regex pattern, only files matching the pattern are loaded if the variable is defined
QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
QRegExp fileRegexp;
QRegularExpression fileRegexp;
if ( !filePattern.isEmpty() )
{
fileRegexp.setPattern( filePattern );
@@ -229,9 +230,9 @@ void QgsProviderRegistry::init()
const auto constEntryInfoList = mLibraryDirectory.entryInfoList();
for ( const QFileInfo &fi : constEntryInfoList )
{
if ( !fileRegexp.isEmpty() )
if ( !filePattern.isEmpty() )
{
if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
if ( fi.fileName().indexOf( fileRegexp ) == -1 )
{
QgsDebugMsg( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern );
continue;

0 comments on commit 90a5f36

Please sign in to comment.