QGIS API Documentation 4.3.0-Master (bf28115e945)
Loading...
Searching...
No Matches
qgsproviderregistry.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsproviderregistry.cpp - Singleton class for
3 registering data providers.
4 -------------------
5 begin : Sat Jan 10 2004
6 copyright : (C) 2004 by Gary E.Sherman
7 email : sherman at mrcc.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#include "qgsproviderregistry.h"
20
21#include "providers/gdal/qgsgdalprovider.h"
23#include "providers/meshmemory/qgsmeshmemorydataprovider.h"
24#include "providers/ogr/qgsogrprovider.h"
25#include "providers/ogr/qgsogrprovidermetadata.h"
27#include "qgis.h"
30#include "qgsdataitemprovider.h"
31#include "qgsdataprovider.h"
33#include "qgslogger.h"
35#include "qgsmessagelog.h"
36#include "qgsproject.h"
37#include "qgsprovidermetadata.h"
44
45#include <QString>
46
47using namespace Qt::StringLiterals;
48
49#ifdef HAVE_EPT
50#include "providers/ept/qgseptprovider.h"
51#endif
52
53#ifdef HAVE_COPC
54#include "providers/copc/qgscopcprovider.h"
55#include "providers/vpc/qgsvirtualpointcloudprovider.h"
56#endif
57
58#include "qgsruntimeprofiler.h"
59#include "qgsfileutils.h"
60
61#ifdef HAVE_STATIC_PROVIDERS
62#include "qgswmsprovider.h"
63#include "qgswcsprovider.h"
64#include "qgsdelimitedtextprovider.h"
65#include "qgsafsprovider.h"
66#include "qgsamsprovider.h"
67#ifdef HAVE_SPATIALITE
68#include "qgsspatialiteprovider.h"
69#include "qgswfsprovider.h"
70#include "qgswfsprovidermetadata.h"
71#include "qgsoapifprovider.h"
72#include "qgsvirtuallayerprovider.h"
73#endif
74#ifdef HAVE_POSTGRESQL
75#include "qgspostgresprovider.h"
76#endif
77#endif
78
79#include <QString>
80#include <QDir>
81#include <QLibrary>
82#include <QRegularExpression>
83
84static QgsProviderRegistry *sInstance = nullptr;
85
86QgsProviderRegistry *QgsProviderRegistry::instance( const QString &pluginPath )
87{
88 if ( !sInstance )
89 {
90 static QMutex sMutex;
91 const QMutexLocker locker( &sMutex );
92 if ( !sInstance )
93 {
94 sInstance = new QgsProviderRegistry( pluginPath );
95 }
96 }
97 return sInstance;
98} // QgsProviderRegistry::instance
99
100
109static QgsProviderMetadata *findMetadata_( const QgsProviderRegistry::Providers &metaData, const QString &providerKey )
110{
111 // first do case-sensitive match
112 const QgsProviderRegistry::Providers::const_iterator i = metaData.find( providerKey );
113
114 if ( i != metaData.end() )
115 {
116 return i->second;
117 }
118
119 // fallback to case-insensitive match
120 for ( auto it = metaData.begin(); it != metaData.end(); ++it )
121 {
122 if ( providerKey.compare( it->first, Qt::CaseInsensitive ) == 0 )
123 return it->second;
124 }
125
126 return nullptr;
127}
128
129QgsProviderRegistry::QgsProviderRegistry( const QString &pluginPath )
130{
131 // At startup, examine the libs in the qgis/lib dir and store those that
132 // are a provider shared lib
133 // check all libs in the current plugin directory and get name and descriptions
134 //TODO figure out how to register and identify data source plugin for a specific
135 //TODO layer type
136#if 0
137 char **argv = qApp->argv();
138 QString appDir = argv[0];
139 int bin = appDir.findRev( "/bin", -1, false );
140 QString baseDir = appDir.left( bin );
141 QString mLibraryDirectory = baseDir + "/lib";
142#endif
143
144 const QgsScopedRuntimeProfile profile( QObject::tr( "Initialize data providers" ) );
145 mLibraryDirectory.setPath( pluginPath );
146 init();
147}
148
150class PdalUnusableUriHandlerInterface : public QgsProviderRegistry::UnusableUriHandlerInterface
151{
152 public:
153 bool matchesUri( const QString &uri ) const override
154 {
155 const QFileInfo fi( uri );
156 if ( fi.suffix().compare( "las"_L1, Qt::CaseInsensitive ) == 0 || fi.suffix().compare( "laz"_L1, Qt::CaseInsensitive ) == 0 )
157 return true;
158
159 return false;
160 }
161
162 QgsProviderRegistry::UnusableUriDetails details( const QString &uri ) const override
163 {
164 QgsProviderRegistry::UnusableUriDetails res
165 = QgsProviderRegistry::UnusableUriDetails( uri, QObject::tr( "LAS and LAZ files cannot be opened by this QGIS install." ), QList<Qgis::LayerType>() << Qgis::LayerType::PointCloud );
166
167#ifdef Q_OS_WIN
168 res.detailedWarning = QObject::tr(
169 "The installer used to install this version of QGIS does "
170 "not include the PDAL library required for opening LAS and LAZ point clouds. Please "
171 "obtain one of the alternative installers from https://qgis.org which has point "
172 "cloud support enabled."
173 );
174#else
175 res.detailedWarning = QObject::tr( "This QGIS build does not include the PDAL library dependency required for opening LAS or LAZ point clouds." );
176#endif
177 return res;
178 }
179};
181
182void QgsProviderRegistry::init()
183{
184 // add static providers
185 {
186 const QgsScopedRuntimeProfile profile( QObject::tr( "Create memory layer provider" ) );
187 mProviders[QgsMemoryProvider::providerKey()] = new QgsMemoryProviderMetadata();
188 }
189 {
190 const QgsScopedRuntimeProfile profile( QObject::tr( "Create mesh memory layer provider" ) );
191 mProviders[QgsMeshMemoryDataProvider::providerKey()] = new QgsMeshMemoryProviderMetadata();
192 }
193 {
194 const QgsScopedRuntimeProfile profile( QObject::tr( "Create GDAL provider" ) );
195 mProviders[QgsGdalProvider::providerKey()] = new QgsGdalProviderMetadata();
196 }
197 {
198 const QgsScopedRuntimeProfile profile( QObject::tr( "Create OGR provider" ) );
199 mProviders[QgsOgrProvider::providerKey()] = new QgsOgrProviderMetadata();
200 }
201 {
202 const QgsScopedRuntimeProfile profile( QObject::tr( "Create OGC SensorThings API provider" ) );
203 mProviders[QgsSensorThingsProvider::providerKey()] = new QgsSensorThingsProviderMetadata();
204 }
205 {
206 const QgsScopedRuntimeProfile profile( QObject::tr( "Create vector tile providers" ) );
207 QgsProviderMetadata *vt = new QgsVectorTileProviderMetadata();
208 mProviders[vt->key()] = vt;
209 vt = new QgsXyzVectorTileDataProviderMetadata();
210 mProviders[vt->key()] = vt;
211 vt = new QgsVtpkVectorTileDataProviderMetadata();
212 mProviders[vt->key()] = vt;
213 vt = new QgsArcGisVectorTileServiceDataProviderMetadata();
214 mProviders[vt->key()] = vt;
215 vt = new QgsMbTilesVectorTileDataProviderMetadata();
216 mProviders[vt->key()] = vt;
217 }
218#ifdef HAVE_EPT
219 {
220 const QgsScopedRuntimeProfile profile( QObject::tr( "Create EPT point cloud provider" ) );
221 QgsProviderMetadata *pc = new QgsEptProviderMetadata();
222 mProviders[pc->key()] = pc;
223 }
224#endif
225#ifdef HAVE_COPC
226 {
227 const QgsScopedRuntimeProfile profile( QObject::tr( "Create COPC point cloud provider" ) );
228 QgsProviderMetadata *pc = new QgsCopcProviderMetadata();
229 mProviders[pc->key()] = pc;
230 }
231 {
232 const QgsScopedRuntimeProfile profile( QObject::tr( "Create Virtual point cloud provider" ) );
233 QgsProviderMetadata *pc = new QgsVirtualPointCloudProviderMetadata();
234 mProviders[pc->key()] = pc;
235 }
236#endif
237 registerUnusableUriHandler( new PdalUnusableUriHandlerInterface() );
238
239 {
240 const QgsScopedRuntimeProfile profile( QObject::tr( "Create tiled scene providers" ) );
241 QgsProviderMetadata *metadata = new QgsTiledSceneProviderMetadata();
242 mProviders[metadata->key()] = metadata;
243
244 metadata = new QgsCesiumTilesProviderMetadata();
245 mProviders[metadata->key()] = metadata;
246
247 metadata = new QgsQuantizedMeshProviderMetadata();
248 mProviders[metadata->key()] = metadata;
249
250 metadata = new QgsEsriI3SProviderMetadata();
251 mProviders[metadata->key()] = metadata;
252 }
253
254#ifdef HAVE_STATIC_PROVIDERS
255 mProviders[QgsWmsProvider::providerKey()] = new QgsWmsProviderMetadata();
256 mProviders[QgsWcsProvider::providerKey()] = new QgsWcsProviderMetadata();
257 mProviders[QgsDelimitedTextProvider::providerKey()] = new QgsDelimitedTextProviderMetadata();
258 mProviders[QgsAfsProvider::providerKey()] = new QgsAfsProviderMetadata();
259 mProviders[QgsAmsProvider::providerKey()] = new QgsAmsProviderMetadata();
260#ifdef HAVE_SPATIALITE
261 mProviders[QgsSpatiaLiteProvider::providerKey()] = new QgsSpatiaLiteProviderMetadata();
262 mProviders[QgsWFSProvider::providerKey()] = new QgsWfsProviderMetadata();
263 mProviders[QgsOapifProvider::providerKey()] = new QgsOapifProviderMetadata();
264 mProviders[QgsVirtualLayerProvider::providerKey()] = new QgsVirtualLayerProviderMetadata();
265#endif
266#ifdef HAVE_POSTGRESQL
267 mProviders[QgsPostgresProvider::providerKey()] = new QgsPostgresProviderMetadata();
268#endif
269#endif
270
271 // add dynamic providers
272#ifdef HAVE_STATIC_PROVIDERS
273 QgsDebugMsgLevel( u"Forced only static providers"_s, 2 );
274#else
275 typedef QgsProviderMetadata *factory_function();
276
277 mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
278 mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
279
280#if defined( Q_OS_WIN ) || defined( __CYGWIN__ )
281 mLibraryDirectory.setNameFilters( QStringList( "*.dll" ) );
282#elif defined( ANDROID )
283 mLibraryDirectory.setNameFilters( QStringList( "*provider_*.so" ) );
284#else
285 mLibraryDirectory.setNameFilters( QStringList( u"*.so"_s ) );
286#endif
287
288 QgsDebugMsgLevel( u"Checking %1 for provider plugins"_s.arg( mLibraryDirectory.path() ), 2 );
289
290 if ( mLibraryDirectory.count() == 0 )
291 {
292 QgsDebugError( u"No dynamic QGIS data provider plugins found in:\n%1\n"_s.arg( mLibraryDirectory.path() ) );
293 }
294
295 // provider file regex pattern, only files matching the pattern are loaded if the variable is defined
296 const QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
297 QRegularExpression fileRegexp;
298 if ( !filePattern.isEmpty() )
299 {
300 fileRegexp.setPattern( filePattern );
301 }
302
303 typedef std::vector<QgsProviderMetadata *> *multiple_factory_function();
304
305 const auto constEntryInfoList = mLibraryDirectory.entryInfoList();
306 for ( const QFileInfo &fi : constEntryInfoList )
307 {
308 if ( !filePattern.isEmpty() )
309 {
310 if ( fi.fileName().indexOf( fileRegexp ) == -1 )
311 {
312 QgsDebugMsgLevel( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern, 2 );
313 continue;
314 }
315 }
316
317 // Always skip authentication methods
318 if ( fi.fileName().contains( u"authmethod"_s, Qt::CaseSensitivity::CaseInsensitive ) )
319 {
320 continue;
321 }
322
323 const QgsScopedRuntimeProfile profile( QObject::tr( "Load %1" ).arg( fi.fileName() ) );
324 QLibrary myLib( fi.filePath() );
325 if ( !myLib.load() )
326 {
327 QgsDebugError( u"Checking %1: ...invalid (lib not loadable): %2"_s.arg( myLib.fileName(), myLib.errorString() ) );
328 continue;
329 }
330
331 bool libraryLoaded { false };
332 QFunctionPointer func = myLib.resolve( u"providerMetadataFactory"_s.toLatin1().data() );
333 factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
334 if ( function )
335 {
336 QgsProviderMetadata *meta = function();
337 if ( meta )
338 {
339 if ( findMetadata_( mProviders, meta->key() ) )
340 {
341 QgsDebugError( u"Checking %1: ...invalid (key %2 already registered)"_s.arg( myLib.fileName() ).arg( meta->key() ) );
342 delete meta;
343 continue;
344 }
345 // add this provider to the provider map
346 mProviders[meta->key()] = meta;
347 libraryLoaded = true;
348 }
349 }
350 else
351 {
352 QFunctionPointer multi_func = myLib.resolve( u"multipleProviderMetadataFactory"_s.toLatin1().data() );
353 multiple_factory_function *multi_function = reinterpret_cast< multiple_factory_function * >( cast_to_fptr( multi_func ) );
354 if ( multi_function )
355 {
356 std::vector<QgsProviderMetadata *> *metadatas = multi_function();
357 for ( const auto meta : *metadatas )
358 {
359 if ( findMetadata_( mProviders, meta->key() ) )
360 {
361 QgsDebugError( u"Checking %1: ...invalid (key %2 already registered)"_s.arg( myLib.fileName() ).arg( meta->key() ) );
362 delete meta;
363 continue;
364 }
365 // add this provider to the provider map
366 mProviders[meta->key()] = meta;
367 libraryLoaded = true;
368 }
369 delete metadatas;
370 }
371 }
372
373 if ( !libraryLoaded )
374 {
375 QgsDebugMsgLevel( u"Checking %1: ...invalid (no providerMetadataFactory method)"_s.arg( myLib.fileName() ), 2 );
376 }
377 }
378
379#endif
380 QgsDebugMsgLevel( u"Loaded %1 providers (%2) "_s.arg( mProviders.size() ).arg( providerList().join( ';' ) ), 1 );
381
382 // now initialize all providers
383 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
384 {
385 const QString &key = it->first;
386
387 const QgsScopedRuntimeProfile profile( QObject::tr( "Initialize %1" ).arg( key ) );
388
389 QgsProviderMetadata *meta = it->second;
390
391 // call initProvider() - allows provider to register its services to QGIS
392 meta->initProvider();
393 }
394
395 rebuildFilterStrings();
396
397 // load database drivers (only OGR)
398 mDatabaseDrivers = QgsOgrProviderUtils::databaseDrivers();
399
400 // load directory drivers (only OGR)
401 mDirectoryDrivers = QgsOgrProviderUtils::directoryDrivers();
402
403 // load protocol drivers (only OGR)
404 mProtocolDrivers = QgsOgrProviderUtils::protocolDrivers();
405}
406
407void QgsProviderRegistry::rebuildFilterStrings()
408{
409 mVectorFileFilters.clear();
410 mRasterFileFilters.clear();
411 mMeshFileFilters.clear();
412 mMeshDatasetFileFilters.clear();
413 mPointCloudFileFilters.clear();
414 mVectorTileFileFilters.clear();
415 mTiledSceneFileFilters.clear();
416
417 QStringList pointCloudWildcards;
418 QStringList pointCloudFilters;
419
420 QStringList vectorTileWildcards;
421 QStringList vectorTileFilters;
422
423 QStringList tiledSceneWildcards;
424 QStringList tiledSceneFilters;
425
426 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
427 {
428 QgsProviderMetadata *meta = it->second;
429
430 // now get vector file filters, if any
432 if ( !fileVectorFilters.isEmpty() )
433 {
434 mVectorFileFilters += fileVectorFilters;
435 QgsDebugMsgLevel( u"Checking %1: ...loaded OK (%2 file filters)"_s.arg( it->first ).arg( fileVectorFilters.split( ";;" ).count() ), 2 );
436 }
437
438 // now get raster file filters, if any
440 if ( !fileRasterFilters.isEmpty() )
441 {
442 QgsDebugMsgLevel( "raster filters: " + fileRasterFilters, 2 );
443 mRasterFileFilters += fileRasterFilters;
444 QgsDebugMsgLevel( u"Checking %1: ...loaded OK (%2 file filters)"_s.arg( it->first ).arg( fileRasterFilters.split( ";;" ).count() ), 2 );
445 }
446
447 // now get mesh file filters, if any
448 const QString fileMeshFilters = meta->filters( Qgis::FileFilterType::Mesh );
449 if ( !fileMeshFilters.isEmpty() )
450 {
451 mMeshFileFilters += fileMeshFilters;
452 QgsDebugMsgLevel( u"Checking %1: ...loaded OK (%2 file mesh filters)"_s.arg( it->first ).arg( mMeshFileFilters.split( ";;" ).count() ), 2 );
453 }
454
456 if ( !fileMeshDatasetFilters.isEmpty() )
457 {
458 mMeshDatasetFileFilters += fileMeshDatasetFilters;
459 QgsDebugMsgLevel( u"Checking %1: ...loaded OK (%2 file dataset filters)"_s.arg( it->first ).arg( mMeshDatasetFileFilters.split( ";;" ).count() ), 2 );
460 }
461
462 // now get point cloud file filters, if any
464 if ( !filePointCloudFilters.isEmpty() )
465 {
466 QgsDebugMsgLevel( "point cloud filters: " + filePointCloudFilters, 2 );
467
468 const QStringList filters = filePointCloudFilters.split( u";;"_s, Qt::SkipEmptyParts );
469 for ( const QString &filter : filters )
470 {
471 pointCloudFilters.append( filter );
472 pointCloudWildcards.append( QgsFileUtils::wildcardsFromFilter( filter ).split( ' ' ) );
473 }
474 }
475
476 // now get vector tile file filters, if any
478 if ( !fileVectorTileFilters.isEmpty() )
479 {
480 QgsDebugMsgLevel( "vector tile filters: " + fileVectorTileFilters, 2 );
481
482 const QStringList filters = fileVectorTileFilters.split( u";;"_s, Qt::SkipEmptyParts );
483 for ( const QString &filter : filters )
484 {
485 vectorTileFilters.append( filter );
486 vectorTileWildcards.append( QgsFileUtils::wildcardsFromFilter( filter ).split( ' ' ) );
487 }
488 }
489
490 // now get tiled scene file filters, if any
492 if ( !fileTiledSceneFilters.isEmpty() )
493 {
494 QgsDebugMsgLevel( "tiled scene filters: " + fileTiledSceneFilters, 2 );
495
496 const QStringList filters = fileTiledSceneFilters.split( u";;"_s, Qt::SkipEmptyParts );
497 for ( const QString &filter : filters )
498 {
499 tiledSceneFilters.append( filter );
500 tiledSceneWildcards.append( QgsFileUtils::wildcardsFromFilter( filter ).split( ' ' ) );
501 }
502 }
503 }
504
505 if ( !pointCloudFilters.empty() )
506 {
507 pointCloudFilters.insert( 0, QObject::tr( "All Supported Files" ) + u" (%1)"_s.arg( pointCloudWildcards.join( ' ' ) ) );
508 pointCloudFilters.insert( 1, QObject::tr( "All Files" ) + u" (*.*)"_s );
509 mPointCloudFileFilters = pointCloudFilters.join( ";;"_L1 );
510 }
511
512 if ( !vectorTileFilters.empty() )
513 {
514 vectorTileFilters.insert( 0, QObject::tr( "All Supported Files" ) + u" (%1)"_s.arg( vectorTileWildcards.join( ' ' ) ) );
515 vectorTileFilters.insert( 1, QObject::tr( "All Files" ) + u" (*.*)"_s );
516 mVectorTileFileFilters = vectorTileFilters.join( ";;"_L1 );
517 }
518
519 if ( !tiledSceneFilters.empty() )
520 {
521 tiledSceneFilters.insert( 0, QObject::tr( "All Supported Files" ) + u" (%1)"_s.arg( tiledSceneWildcards.join( ' ' ) ) );
522 tiledSceneFilters.insert( 1, QObject::tr( "All Files" ) + u" (*.*)"_s );
523 mTiledSceneFileFilters = tiledSceneFilters.join( ";;"_L1 );
524 }
525}
526
527// typedef for the unload dataprovider function
529
530void QgsProviderRegistry::clean()
531{
532 // avoid recreating a new project just to clean it
533 if ( QgsProject::sProject )
534 QgsProject::instance()->removeAllMapLayers(); // skip-keyword-check
535
536 Providers::const_iterator it = mProviders.begin();
537
538 while ( it != mProviders.end() )
539 {
540 QgsDebugMsgLevel( u"cleanup:%1"_s.arg( it->first ), 5 );
541 it->second->cleanupProvider();
542 delete it->second;
543 ++it;
544 }
545 mProviders.clear();
546}
547
548bool QgsProviderRegistry::exists()
549{
550 return static_cast< bool >( sInstance );
551}
552
554{
555 qDeleteAll( mUnusableUriHandlers );
556
557 clean();
558 if ( sInstance == this )
559 sInstance = nullptr;
560}
561
562QString QgsProviderRegistry::library( QString const &providerKey ) const
563{
564 QgsProviderMetadata *md = findMetadata_( mProviders, providerKey );
565
566 if ( md )
567 {
569 return md->library();
571 }
572
573 return QString();
574}
575
576QString QgsProviderRegistry::pluginList( bool asHTML ) const
577{
578 Providers::const_iterator it = mProviders.begin();
579
580 if ( mProviders.empty() )
581 return QObject::tr( "No data provider plugins are available. No vector layers can be loaded" );
582
583 QString list;
584
585 if ( asHTML )
586 list += "<ol>"_L1;
587
588 while ( it != mProviders.end() )
589 {
590 if ( asHTML )
591 list += "<li>"_L1;
592
593 list += it->second->description();
594
595 if ( asHTML )
596 list += "<br></li>"_L1;
597 else
598 list += '\n';
599
600 ++it;
601 }
602
603 if ( asHTML )
604 list += "</ol>"_L1;
605
606 return list;
607}
608
610{
611 mLibraryDirectory = path;
612 clean();
613 init();
614}
615
617{
618 return mLibraryDirectory;
619}
620
621
622/* Copied from QgsVectorLayer::setDataProvider
623 * TODO: Make it work in the generic environment
624 *
625 * TODO: Is this class really the best place to put a data provider loader?
626 * It seems more sensible to provide the code in one place rather than
627 * in qgsrasterlayer, qgsvectorlayer, serversourceselect, etc.
628 */
629QgsDataProvider *QgsProviderRegistry::createProvider( QString const &providerKey, QString const &dataSource, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags )
630{
631 // XXX should I check for and possibly delete any pre-existing providers?
632 // XXX How often will that scenario occur?
633
634 QgsProviderMetadata *metadata = findMetadata_( mProviders, providerKey );
635 if ( !metadata )
636 {
637 QgsMessageLog::logMessage( QObject::tr( "Invalid data provider %1" ).arg( providerKey ) );
638 return nullptr;
639 }
640
641 return metadata->createProvider( dataSource, options, flags );
642}
643
645{
646 const QList< QgsDataItemProvider * > itemProviders = dataItemProviders( providerKey );
648 //concat flags
649 for ( const QgsDataItemProvider *itemProvider : itemProviders )
650 {
651 ret |= itemProvider->capabilities();
652 }
653 return ret;
654}
655
656QVariantMap QgsProviderRegistry::decodeUri( const QString &providerKey, const QString &uri )
657{
658 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
659 if ( meta )
660 return meta->decodeUri( uri );
661 else
662 return QVariantMap();
663}
664
665QString QgsProviderRegistry::encodeUri( const QString &providerKey, const QVariantMap &parts )
666{
667 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
668 if ( meta )
669 return meta->encodeUri( parts );
670 else
671 return QString();
672}
673
674QString QgsProviderRegistry::absoluteToRelativeUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const
675{
676 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
677 if ( meta )
678 return meta->absoluteToRelativeUri( uri, context );
679 else
680 return uri;
681}
682
683QString QgsProviderRegistry::relativeToAbsoluteUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const
684{
685 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
686 if ( meta )
687 return meta->relativeToAbsoluteUri( uri, context );
688 else
689 return uri;
690}
691
693 const QString &providerKey, const QString &uri, const QgsFields &fields, Qgis::WkbType wkbType, const QgsCoordinateReferenceSystem &crs, Qgis::CreateLayerActionOnExisting actionOnExisting
694)
695{
696 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
697 if ( meta )
698 return meta->createEmptyLayer( uri, fields, wkbType, crs, actionOnExisting );
699 else
700 {
701 return QgsEmptyLayerCreationResult( Qgis::VectorExportResult::ErrorInvalidProvider, QString(), QObject::tr( "Unable to load %1 provider" ).arg( providerKey ), {} );
702 }
703}
704
706 const QString &providerKey,
707 const QString &uri,
708 const QgsFields &fields,
709 Qgis::WkbType wkbType,
711 bool overwrite,
712 QMap<int, int> &oldToNewAttrIdxMap,
713 QString &errorMessage,
714 const QMap<QString, QVariant> *options,
715 QString &createdLayerName
716)
717{
718 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
719 if ( meta )
720 return meta->createEmptyLayer( uri, fields, wkbType, srs, overwrite, oldToNewAttrIdxMap, errorMessage, options, createdLayerName );
721 else
722 {
723 errorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
725 }
726}
727
729 const QString &providerKey,
730 const QString &uri,
731 const QString &format,
732 int nBands,
733 Qgis::DataType type,
734 int width,
735 int height,
736 double *geoTransform,
738 const QStringList &creationOptions
739)
740{
741 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
742 if ( meta )
743 return meta->createRasterDataProvider( uri, format, nBands, type, width, height, geoTransform, crs, creationOptions );
744 else
745 return nullptr;
746}
747
748QList<QPair<QString, QString> > QgsProviderRegistry::pyramidResamplingMethods( const QString &providerKey )
749{
750 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
751 if ( meta )
752 return meta->pyramidResamplingMethods();
753 else
754 return QList<QPair<QString, QString> >();
755}
756
757QList<QgsDataItemProvider *> QgsProviderRegistry::dataItemProviders( const QString &providerKey ) const
758{
759 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
760 if ( meta )
761 return meta->dataItemProviders();
762 else
763 return QList<QgsDataItemProvider *>();
764}
765
766int QgsProviderRegistry::listStyles( const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause )
767{
768 int res = -1;
769 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
770 if ( meta )
771 {
772 res = meta->listStyles( uri, ids, names, descriptions, errCause );
773 }
774 else
775 {
776 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
777 }
778 return res;
779}
780
781bool QgsProviderRegistry::styleExists( const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause )
782{
783 errorCause.clear();
784
785 if ( QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey ) )
786 {
787 return meta->styleExists( uri, styleId, errorCause );
788 }
789 else
790 {
791 errorCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
792 return false;
793 }
794}
795
796QString QgsProviderRegistry::getStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause )
797{
798 QString ret;
799 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
800 if ( meta )
801 {
802 ret = meta->getStyleById( uri, styleId, errCause );
803 }
804 else
805 {
806 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
807 }
808 return ret;
809}
810
811bool QgsProviderRegistry::deleteStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause )
812{
813 const bool ret( false );
814
815 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
816 if ( meta )
817 return meta->deleteStyleById( uri, styleId, errCause );
818 else
819 {
820 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
821 }
822 return ret;
823}
824
826 const QString &providerKey,
827 const QString &uri,
828 const QString &qmlStyle,
829 const QString &sldStyle,
830 const QString &styleName,
831 const QString &styleDescription,
832 const QString &uiFileContent,
833 bool useAsDefault,
834 QString &errCause
835)
836{
837 bool ret( false );
838 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
839 if ( meta )
840 ret = meta->saveStyle( uri, qmlStyle, sldStyle, styleName, styleDescription, uiFileContent, useAsDefault, errCause );
841 else
842 {
843 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
844 }
845 return ret;
846}
847
848QString QgsProviderRegistry::loadStyle( const QString &providerKey, const QString &uri, QString &errCause )
849{
850 QString ret;
851 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
852 if ( meta )
853 ret = meta->loadStyle( uri, errCause );
854 else
855 {
856 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
857 }
858 return ret;
859}
860
861QString QgsProviderRegistry::loadStoredStyle( const QString &providerKey, const QString &uri, QString &styleName, QString &errCause )
862{
863 QString ret;
864 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
865 if ( meta )
866 ret = meta->loadStoredStyle( uri, styleName, errCause );
867 else
868 {
869 errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
870 }
871 return ret;
872}
873
874bool QgsProviderRegistry::saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage )
875{
876 errorMessage.clear();
877 if ( QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey ) )
878 return meta->saveLayerMetadata( uri, metadata, errorMessage );
879 else
880 {
881 throw QgsNotSupportedException( QObject::tr( "Unable to load %1 provider" ).arg( providerKey ) );
882 }
883}
884
885bool QgsProviderRegistry::createDb( const QString &providerKey, const QString &dbPath, QString &errCause )
886{
887 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
888 if ( meta )
889 return meta->createDb( dbPath, errCause );
890 else
891 {
892 errCause = u"Resolving createDb(...) failed"_s;
893 return false;
894 }
895}
896
897QgsTransaction *QgsProviderRegistry::createTransaction( const QString &providerKey, const QString &connString )
898{
899 QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
900 if ( meta )
901 return meta->createTransaction( connString );
902 else
903 return nullptr;
904}
905
906QWidget *QgsProviderRegistry::createSelectionWidget( const QString &providerKey, QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
907{
908 Q_UNUSED( providerKey );
909 Q_UNUSED( parent );
910 Q_UNUSED( fl );
911 Q_UNUSED( widgetMode );
912 QgsDebugError( "deprecated call - use QgsGui::sourceSelectProviderRegistry()->createDataSourceWidget() instead" );
913 return nullptr;
914}
915
916QFunctionPointer QgsProviderRegistry::function( QString const &providerKey, QString const &functionName ) const
917{
919 const QString lib = library( providerKey );
921 if ( lib.isEmpty() )
922 return nullptr;
923
924 QLibrary myLib( lib );
925
926 QgsDebugMsgLevel( "Library name is " + myLib.fileName(), 2 );
927
928 if ( myLib.load() )
929 {
930 return myLib.resolve( functionName.toLatin1().data() );
931 }
932 else
933 {
934 QgsDebugError( "Cannot load library: " + myLib.errorString() );
935 return nullptr;
936 }
937}
938
939QLibrary *QgsProviderRegistry::createProviderLibrary( QString const &providerKey ) const
940{
942 const QString lib = library( providerKey );
944 if ( lib.isEmpty() )
945 return nullptr;
946
947 auto myLib = std::make_unique<QLibrary>( lib );
948
949 QgsDebugMsgLevel( "Library name is " + myLib->fileName(), 2 );
950
951 if ( myLib->load() )
952 return myLib.release();
953
954 QgsDebugError( "Cannot load library: " + myLib->errorString() );
955
956 return nullptr;
957}
958
960{
961 QgsDebugError( "deprecated - use QgsGui::providerGuiRegistry() instead." );
962}
963
965{
966 if ( providerMetadata )
967 {
968 if ( mProviders.find( providerMetadata->key() ) == mProviders.end() )
969 {
970 mProviders[providerMetadata->key()] = providerMetadata;
971
972 rebuildFilterStrings();
973 return true;
974 }
975 else
976 {
977 QgsDebugMsgLevel( u"Cannot register provider metadata: a provider with the same key (%1) was already registered!"_s.arg( providerMetadata->key() ), 2 );
978 }
979 }
980 else
981 {
982 QgsDebugMsgLevel( u"Trying to register a null metadata provider!"_s, 2 );
983 }
984 return false;
985}
986
988{
989 return mVectorFileFilters;
990}
991
993{
994 return mRasterFileFilters;
995}
996
998{
999 return mMeshFileFilters;
1000}
1001
1003{
1004 return mMeshDatasetFileFilters;
1005}
1006
1008{
1009 return mPointCloudFileFilters;
1010}
1011
1013{
1014 return mVectorTileFileFilters;
1015}
1016
1018{
1019 return mTiledSceneFileFilters;
1020}
1021
1023{
1024 return mDatabaseDrivers;
1025}
1026
1028{
1029 return mDirectoryDrivers;
1030}
1031
1033{
1034 return mProtocolDrivers;
1035}
1036
1038{
1039 QStringList lst;
1040 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
1041 {
1042 lst.append( it->first );
1043 }
1044 return lst;
1045}
1046
1048{
1049 return findMetadata_( mProviders, providerKey );
1050}
1051
1053{
1054 QSet<QString> lst;
1055 for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
1056 {
1057 if ( it->second->supportedLayerTypes().contains( type ) )
1058 lst.insert( it->first );
1059 }
1060 return lst;
1061}
1062
1063QList<QgsProviderRegistry::ProviderCandidateDetails> QgsProviderRegistry::preferredProvidersForUri( const QString &uri ) const
1064{
1065 QList< QgsProviderRegistry::ProviderCandidateDetails > res;
1066 int maxPriority = 0;
1067 for ( auto it = mProviders.begin(); it != mProviders.end(); ++it )
1068 {
1069 if ( !( it->second->capabilities() & QgsProviderMetadata::PriorityForUri ) )
1070 continue;
1071
1072 const int thisProviderPriority = it->second->priorityForUri( uri );
1073 if ( thisProviderPriority == 0 )
1074 continue;
1075
1076 if ( thisProviderPriority > maxPriority )
1077 {
1078 res.clear();
1079 maxPriority = thisProviderPriority;
1080 }
1081 if ( thisProviderPriority == maxPriority )
1082 {
1083 res.append( ProviderCandidateDetails( it->second, it->second->validLayerTypesForUri( uri ) ) );
1084 }
1085 }
1086 return res;
1087}
1088
1090{
1091 mUnusableUriHandlers << handler;
1092 return true;
1093}
1094
1095bool QgsProviderRegistry::handleUnusableUri( const QString &uri, UnusableUriDetails &details ) const
1096{
1097 for ( const QgsProviderRegistry::UnusableUriHandlerInterface *handler : mUnusableUriHandlers )
1098 {
1099 if ( handler->matchesUri( uri ) )
1100 {
1101 details = handler->details( uri );
1102 return true;
1103 }
1104 }
1105 return false;
1106}
1107
1108bool QgsProviderRegistry::shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const
1109{
1110 const QList< ProviderCandidateDetails > providers = preferredProvidersForUri( uri );
1111 if ( providers.empty() )
1112 return false;
1113
1114 for ( const ProviderCandidateDetails &provider : providers )
1115 {
1116 if ( provider.metadata()->key() == providerKey )
1117 return false;
1118 }
1119 return true;
1120}
1121
1122bool QgsProviderRegistry::uriIsBlocklisted( const QString &uri ) const
1123{
1124 for ( auto it = mProviders.begin(); it != mProviders.end(); ++it )
1125 {
1126 if ( it->second->uriIsBlocklisted( uri ) )
1127 return true;
1128 }
1129 return false;
1130}
1131
1132QList<QgsProviderSublayerDetails> QgsProviderRegistry::querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags, QgsFeedback *feedback ) const
1133{
1134 // never query sublayers for blocklisted uris
1135 if ( uriIsBlocklisted( uri ) )
1136 return {};
1137
1138 QList<QgsProviderSublayerDetails> res;
1139 for ( auto it = mProviders.begin(); it != mProviders.end(); ++it )
1140 {
1141 // if we should defer this uri for other providers, do so
1142 if ( shouldDeferUriForOtherProviders( uri, it->first ) )
1143 continue;
1144
1145 res.append( it->second->querySublayers( uri, flags, feedback ) );
1146 if ( feedback && feedback->isCanceled() )
1147 break;
1148 }
1149 return res;
1150}
@ TiledScene
Tiled scene layers.
Definition qgis.h:1481
@ Vector
Vector layers.
Definition qgis.h:1475
@ VectorTile
Vector tile layers.
Definition qgis.h:1480
@ Mesh
Mesh layers.
Definition qgis.h:1477
@ Raster
Raster layers.
Definition qgis.h:1476
@ MeshDataset
Mesh datasets.
Definition qgis.h:1478
@ PointCloud
Point clouds.
Definition qgis.h:1479
VectorExportResult
Vector layer export result codes.
Definition qgis.h:1133
@ ErrorInvalidProvider
Could not find a matching provider key.
Definition qgis.h:1142
QFlags< DataItemProviderCapability > DataItemProviderCapabilities
Capabilities for data item providers.
Definition qgis.h:1073
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
DataType
Raster data types.
Definition qgis.h:393
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1532
LayerType
Types of layers that can be added to a map.
Definition qgis.h:206
@ PointCloud
Point cloud layer. Added in QGIS 3.18.
Definition qgis.h:213
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:294
Represents a coordinate reference system (CRS).
Interface for providers that add custom data items to the browser tree.
Abstract base class for spatial data provider implementations.
Encapsulates the details of a newly created empty layer.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
bool isCanceled() const
Tells whether the operation has been canceled already.
Definition qgsfeedback.h:56
Container of fields for a vector layer.
Definition qgsfields.h:46
static QString wildcardsFromFilter(const QString &filter)
Given a filter string like GeoTIFF Files (*.tiff *.tif), extracts the wildcard portion of this filter...
A structured metadata store for a map layer.
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::MessageLevel::Warning, bool notifyUser=true, const char *file=__builtin_FILE(), const char *function=__builtin_FUNCTION(), int line=__builtin_LINE(), Qgis::StringFormat format=Qgis::StringFormat::PlainText)
Adds a message to the log instance (and creates it if necessary).
Custom exception class which is raised when an operation is not supported.
static QgsProject * instance()
Returns the QgsProject singleton instance.
void removeAllMapLayers()
Removes all registered layers.
Holds data provider key, description, and associated shared library file or function pointer informat...
virtual QgsRasterDataProvider * createRasterDataProvider(const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates a new instance of the raster data provider.
virtual QgsDataProvider * createProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options, Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Class factory to return a pointer to a newly created QgsDataProvider object.
virtual bool deleteStyleById(const QString &uri, const QString &styleId, QString &errCause)
Deletes a layer style defined by styleId.
virtual bool saveStyle(const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
virtual QString encodeUri(const QVariantMap &parts) const
Reassembles a provider data source URI from its component paths (e.g.
virtual QString absoluteToRelativeUri(const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
virtual bool styleExists(const QString &uri, const QString &styleId, QString &errorCause)
Returns true if a layer style with the specified styleId exists in the provider defined by uri.
virtual bool saveLayerMetadata(const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage)
Saves metadata to the layer corresponding to the specified uri.
virtual QString filters(Qgis::FileFilterType type)
Builds the list of file filter strings (supported formats).
QString key() const
This returns the unique key associated with the provider.
virtual QgsTransaction * createTransaction(const QString &connString)
Returns new instance of transaction.
virtual void initProvider()
Initialize the provider.
virtual QString getStyleById(const QString &uri, const QString &styleId, QString &errCause)
Gets a layer style defined by uri.
virtual QString loadStoredStyle(const QString &uri, QString &styleName, QString &errCause)
Loads a layer style from the provider storage, reporting its name.
@ PriorityForUri
Indicates that the metadata can calculate a priority for a URI.
virtual QString relativeToAbsoluteUri(const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
virtual QString loadStyle(const QString &uri, QString &errCause)
Loads a layer style defined by uri.
virtual int listStyles(const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by uri.
virtual QList< QPair< QString, QString > > pyramidResamplingMethods()
Returns pyramid resampling methods available for provider.
virtual QgsEmptyLayerCreationResult createEmptyLayer(const QString &uri, const QgsFields &fields, Qgis::WkbType wkbType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), Qgis::CreateLayerActionOnExisting actionOnExisting=Qgis::CreateLayerActionOnExisting::Abort)
Creates new empty vector layer.
virtual QList< QgsDataItemProvider * > dataItemProviders() const
Returns data item providers.
virtual QVariantMap decodeUri(const QString &uri) const
Breaks a provider data source URI into its component paths (e.g.
Q_DECL_DEPRECATED QString library() const
This returns the library file name.
virtual bool createDb(const QString &dbPath, QString &errCause)
Creates database by the provider on the path.
Contains information pertaining to a candidate provider.
Contains information about unusable URIs which aren't handled by any registered providers.
QString detailedWarning
Contains a longer, user-friendly, translated message advising why the URI is not usable.
An interface used to handle unusable URIs which aren't handled by any registered providers,...
virtual UnusableUriDetails details(const QString &uri) const =0
Returns the details for advising the user why the uri is not usable.
virtual bool matchesUri(const QString &uri) const =0
Returns true if the handle is an unusable URI handler for the specified uri.
A registry / canonical manager of data providers.
QString absoluteToRelativeUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts absolute path(s) to relative path(s) in the given provider-specific URI.
std::map< QString, QgsProviderMetadata * > Providers
Type for data provider metadata associative container.
bool styleExists(const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause)
Returns true if a layer style with the specified styleId exists in the provider defined by providerKe...
QString loadStyle(const QString &providerKey, const QString &uri, QString &errCause)
Loads a layer style defined by uri.
QString getStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Gets a layer style defined by styleId.
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
void setLibraryDirectory(const QDir &path)
Sets library directory where to search for plugins.
QgsEmptyLayerCreationResult createEmptyLayer(const QString &providerKey, const QString &uri, const QgsFields &fields, Qgis::WkbType wkbType=Qgis::WkbType::NoGeometry, const QgsCoordinateReferenceSystem &crs=QgsCoordinateReferenceSystem(), Qgis::CreateLayerActionOnExisting actionOnExisting=Qgis::CreateLayerActionOnExisting::Abort)
Creates new empty vector layer.
QString fileVectorTileFilters() const
Returns a file filter string for supported vector tile files.
QgsTransaction * createTransaction(const QString &providerKey, const QString &connString)
Returns new instance of transaction.
QList< QgsProviderSublayerDetails > querySublayers(const QString &uri, Qgis::SublayerQueryFlags flags=Qgis::SublayerQueryFlags(), QgsFeedback *feedback=nullptr) const
Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be...
Q_DECL_DEPRECATED void registerGuis(QWidget *widget)
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
WidgetMode
Different ways a source select dialog can be used.
Q_DECL_DEPRECATED QWidget * createSelectionWidget(const QString &providerKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::Standalone)
Returns a new widget for selecting layers from a provider.
QString protocolDrivers() const
Returns a string containing the available protocol drivers.
QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri(const QString &uri) const
Returns the details for the preferred provider(s) for opening the specified uri.
Q_DECL_DEPRECATED QString library(const QString &providerKey) const
Returns path for the library of the provider.
QString fileTiledSceneFilters() const
Returns a file filter string for supported tiled scene files.
QString databaseDrivers() const
Returns a string containing the available database drivers.
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
QList< QgsDataItemProvider * > dataItemProviders(const QString &providerKey) const
Returns list of data item providers of the provider.
QgsRasterDataProvider * createRasterDataProvider(const QString &providerKey, const QString &uri, const QString &format, int nBands, Qgis::DataType type, int width, int height, double *geoTransform, const QgsCoordinateReferenceSystem &crs, const QStringList &createOptions=QStringList())
Creates new instance of raster data provider.
QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns list of raster pyramid resampling methods.
bool uriIsBlocklisted(const QString &uri) const
Returns true if the specified uri is known by any registered provider to be something which should be...
Q_DECL_DEPRECATED QLibrary * createProviderLibrary(const QString &providerKey) const
Returns a new QLibrary for the specified providerKey.
bool handleUnusableUri(const QString &uri, UnusableUriDetails &details) const
Returns true if the specified uri can potentially be handled by QGIS, if additional dependencies or b...
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions(), Qgis::DataProviderReadFlags flags=Qgis::DataProviderReadFlags())
Creates a new instance of a provider.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
bool saveLayerMetadata(const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage)
Saves metadata to the layer corresponding to the specified uri.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
QString pluginList(bool asHtml=false) const
Returns list of provider plugins found.
bool shouldDeferUriForOtherProviders(const QString &uri, const QString &providerKey) const
Returns true if the provider with matching providerKey should defer handling of the specified uri to ...
bool deleteStyleById(const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause)
Deletes a layer style defined by styleId.
QStringList providerList() const
Returns list of available providers by their keys.
Q_DECL_DEPRECATED Qgis::DataItemProviderCapabilities providerCapabilities(const QString &providerKey) const
Returns the provider capabilities.
QString fileMeshDatasetFilters() const
Returns a file filter string for supported mesh dataset files.
QString loadStoredStyle(const QString &providerKey, const QString &uri, QString &styleName, QString &errCause)
Loads a layer style from the provider storage, reporting its name.
QDir libraryDirectory() const
Returns the library directory where plugins are found.
QString relativeToAbsoluteUri(const QString &providerKey, const QString &uri, const QgsReadWriteContext &context) const
Converts relative path(s) to absolute path(s) in the given provider-specific URI.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
int listStyles(const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by providerKey and uri.
bool createDb(const QString &providerKey, const QString &dbPath, QString &errCause)
Creates database by the provider on the path.
bool saveStyle(const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle, const QString &styleName, const QString &styleDescription, const QString &uiFileContent, bool useAsDefault, QString &errCause)
Saves a layer style to provider.
QSet< QString > providersForLayerType(Qgis::LayerType type) const
Returns a list of the provider keys for available providers which handle the specified layer type.
bool registerProvider(QgsProviderMetadata *providerMetadata)
register a new vector data provider from its providerMetadata
Q_DECL_DEPRECATED QFunctionPointer function(const QString &providerKey, const QString &functionName) const
Gets pointer to provider function.
QString directoryDrivers() const
Returns a string containing the available directory drivers.
bool registerUnusableUriHandler(UnusableUriHandlerInterface *handler)
Registers an unusable URI handler, used to handle unusable URIs which aren't handled by any registere...
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
Base class for raster data providers.
A container for the context for various read/write operations on objects.
Allows creation of a multi-layer database-side transaction.
CreateLayerActionOnExisting
Actions to take when attempting to create a layer on an existing datasource.
Definition qgis.h:573
#define Q_NOWARN_DEPRECATED_POP
Definition qgis.h:7979
#define Q_NOWARN_DEPRECATED_PUSH
Definition qgis.h:7978
#define cast_to_fptr(f)
Definition qgis.h:7229
#define QgsDebugMsgLevel(str, level)
Definition qgslogger.h:80
#define QgsDebugError(str)
Definition qgslogger.h:71
void cleanupProviderFunction_t()
Setting options for creating vector data providers.