Skip to content

Commit

Permalink
[qt6][gdal][ogr] Migrate away from QRegExp
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 14, 2021
1 parent 5762fe3 commit 90a5f36
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 5 additions & 3 deletions src/core/providers/gdal/qgsgdaldataitems.cpp
Expand Up @@ -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 );

Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/core/providers/gdal/qgsgdalprovider.cpp
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/core/providers/ogr/qgsogrdataitems.cpp
Expand Up @@ -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;
Expand Down
15 changes: 8 additions & 7 deletions src/core/providers/qgsproviderregistry.cpp
Expand Up @@ -18,10 +18,6 @@

#include "qgsproviderregistry.h"

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

#include "qgis.h"
#include "qgsdataprovider.h"
#include "qgsdataitemprovider.h"
Expand Down Expand Up @@ -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 )
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
Expand Down

0 comments on commit 90a5f36

Please sign in to comment.