Skip to content

Commit 3b00dc1

Browse files
committedMay 16, 2015
QGIS_PROVIDER_FILE: provider regexp pattern environment variable
1 parent aaabad2 commit 3b00dc1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed
 

‎src/core/qgsproviderregistry.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,11 +94,28 @@ QgsProviderRegistry::QgsProviderRegistry( QString pluginPath )
9494
return;
9595
}
9696

97+
// provider file regex pattern, only files matching the pattern are loaded if the variable is defined
98+
QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
99+
QRegExp fileRegexp;
100+
if ( !filePattern.isEmpty() )
101+
{
102+
fileRegexp.setPattern( filePattern );
103+
}
104+
97105
QListIterator<QFileInfo> it( mLibraryDirectory.entryInfoList() );
98106
while ( it.hasNext() )
99107
{
100108
QFileInfo fi( it.next() );
101109

110+
if ( !fileRegexp.isEmpty() )
111+
{
112+
if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
113+
{
114+
QgsDebugMsg( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern );
115+
continue;
116+
}
117+
}
118+
102119
QLibrary myLib( fi.filePath() );
103120
if ( !myLib.load() )
104121
{

‎src/core/qgsproviderregistry.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ class QgsCoordinateReferenceSystem;
3636
* A registry / canonical manager of data providers.
3737
3838
This is a Singleton class that manages data provider access.
39+
40+
Loaded providers may be restricted using QGIS_PROVIDER_FILE environment variable.
41+
QGIS_PROVIDER_FILE is regexp pattern applied to provider file name (not provider key).
42+
For example, if the variable is set to gdal|ogr|postgres it will load only providers gdal,
43+
ogr and postgres.
3944
*/
4045
class CORE_EXPORT QgsProviderRegistry
4146
{

0 commit comments

Comments
 (0)
Please sign in to comment.