QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 <QString>
22 #include <QDir>
23 #include <QLibrary>
24 
25 #include "qgis.h"
26 #include "qgsdataprovider.h"
27 #include "qgsdataitemprovider.h"
28 #include "qgslogger.h"
29 #include "qgsmessageoutput.h"
30 #include "qgsmessagelog.h"
31 #include "qgsprovidermetadata.h"
32 #include "qgsvectorlayer.h"
34 #include "qgsproject.h"
36 #include "providers/gdal/qgsgdalprovider.h"
37 #include "providers/ogr/qgsogrprovider.h"
38 #include "providers/meshmemory/qgsmeshmemorydataprovider.h"
39 #include "qgsruntimeprofiler.h"
40 
41 #ifdef HAVE_STATIC_PROVIDERS
42 #include "qgswmsprovider.h"
43 #include "qgspostgresprovider.h"
44 #endif
45 
46 static QgsProviderRegistry *sInstance = nullptr;
47 
49 {
50  if ( !sInstance )
51  {
52  static QMutex sMutex;
53  QMutexLocker locker( &sMutex );
54  if ( !sInstance )
55  {
56  sInstance = new QgsProviderRegistry( pluginPath );
57  }
58  }
59  return sInstance;
60 } // QgsProviderRegistry::instance
61 
62 
71 static
72 QgsProviderMetadata *findMetadata_( const QgsProviderRegistry::Providers &metaData,
73  const QString &providerKey )
74 {
75  // first do case-sensitive match
76  QgsProviderRegistry::Providers::const_iterator i =
77  metaData.find( providerKey );
78 
79  if ( i != metaData.end() )
80  {
81  return i->second;
82  }
83 
84  // fallback to case-insensitive match
85  for ( auto it = metaData.begin(); it != metaData.end(); ++it )
86  {
87  if ( providerKey.compare( it->first, Qt::CaseInsensitive ) == 0 )
88  return it->second;
89  }
90 
91  return nullptr;
92 }
93 
94 QgsProviderRegistry::QgsProviderRegistry( const QString &pluginPath )
95 {
96  // At startup, examine the libs in the qgis/lib dir and store those that
97  // are a provider shared lib
98  // check all libs in the current plugin directory and get name and descriptions
99  //TODO figure out how to register and identify data source plugin for a specific
100  //TODO layer type
101 #if 0
102  char **argv = qApp->argv();
103  QString appDir = argv[0];
104  int bin = appDir.findRev( "/bin", -1, false );
105  QString baseDir = appDir.left( bin );
106  QString mLibraryDirectory = baseDir + "/lib";
107 #endif
108 
109  QgsScopedRuntimeProfile profile( QObject::tr( "Initialize data providers" ) );
110  mLibraryDirectory.setPath( pluginPath );
111  init();
112 }
113 
114 void QgsProviderRegistry::init()
115 {
116  // add static providers
118  {
119  QgsScopedRuntimeProfile profile( QObject::tr( "Create memory layer provider" ) );
120  mProviders[ QgsMemoryProvider::providerKey() ] = new QgsProviderMetadata( QgsMemoryProvider::providerKey(), QgsMemoryProvider::providerDescription(), &QgsMemoryProvider::createProvider );
121  }
122  {
123  QgsScopedRuntimeProfile profile( QObject::tr( "Create mesh memory layer provider" ) );
124  mProviders[ QgsMeshMemoryDataProvider::providerKey() ] = new QgsProviderMetadata( QgsMeshMemoryDataProvider::providerKey(), QgsMeshMemoryDataProvider::providerDescription(), &QgsMeshMemoryDataProvider::createProvider );
125  }
127  {
128  QgsScopedRuntimeProfile profile( QObject::tr( "Create GDAL provider" ) );
129  mProviders[ QgsGdalProvider::providerKey() ] = new QgsGdalProviderMetadata();
130  }
131  {
132  QgsScopedRuntimeProfile profile( QObject::tr( "Create OGR provider" ) );
133  mProviders[ QgsOgrProvider::providerKey() ] = new QgsOgrProviderMetadata();
134  }
135  {
136  QgsScopedRuntimeProfile profile( QObject::tr( "Create vector tile provider" ) );
137  QgsProviderMetadata *vt = new QgsVectorTileProviderMetadata();
138  mProviders[ vt->key() ] = vt;
139  }
140 #ifdef HAVE_STATIC_PROVIDERS
141  mProviders[ QgsWmsProvider::providerKey() ] = new QgsWmsProviderMetadata();
142  mProviders[ QgsPostgresProvider::providerKey() ] = new QgsPostgresProviderMetadata();
143 #endif
144 
145  // add dynamic providers
146 #ifdef HAVE_STATIC_PROVIDERS
147  QgsDebugMsg( QStringLiteral( "Forced only static providers" ) );
148 #else
149  typedef QgsProviderMetadata *factory_function( );
150 
151  mLibraryDirectory.setSorting( QDir::Name | QDir::IgnoreCase );
152  mLibraryDirectory.setFilter( QDir::Files | QDir::NoSymLinks );
153 
154 #if defined(Q_OS_WIN) || defined(__CYGWIN__)
155  mLibraryDirectory.setNameFilters( QStringList( "*.dll" ) );
156 #elif defined(ANDROID)
157  mLibraryDirectory.setNameFilters( QStringList( "*provider*.so" ) );
158 #else
159  mLibraryDirectory.setNameFilters( QStringList( QStringLiteral( "*.so" ) ) );
160 #endif
161 
162  QgsDebugMsgLevel( QStringLiteral( "Checking %1 for provider plugins" ).arg( mLibraryDirectory.path() ), 2 );
163 
164  if ( mLibraryDirectory.count() == 0 )
165  {
166  QgsDebugMsg( QStringLiteral( "No dynamic QGIS data provider plugins found in:\n%1\n" ).arg( mLibraryDirectory.path() ) );
167  }
168 
169  // provider file regex pattern, only files matching the pattern are loaded if the variable is defined
170  QString filePattern = getenv( "QGIS_PROVIDER_FILE" );
171  QRegExp fileRegexp;
172  if ( !filePattern.isEmpty() )
173  {
174  fileRegexp.setPattern( filePattern );
175  }
176 
177  typedef std::vector<QgsProviderMetadata *> *multiple_factory_function();
178 
179  const auto constEntryInfoList = mLibraryDirectory.entryInfoList();
180  for ( const QFileInfo &fi : constEntryInfoList )
181  {
182  if ( !fileRegexp.isEmpty() )
183  {
184  if ( fileRegexp.indexIn( fi.fileName() ) == -1 )
185  {
186  QgsDebugMsg( "provider " + fi.fileName() + " skipped because doesn't match pattern " + filePattern );
187  continue;
188  }
189  }
190 
191  QgsScopedRuntimeProfile profile( QObject::tr( "Load %1" ).arg( fi.fileName() ) );
192  QLibrary myLib( fi.filePath() );
193  if ( !myLib.load() )
194  {
195  QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (lib not loadable): %2" ).arg( myLib.fileName(), myLib.errorString() ) );
196  continue;
197  }
198 
199  QFunctionPointer multi_func = myLib.resolve( QStringLiteral( "multipleProviderMetadataFactory" ).toLatin1().data() );
200  multiple_factory_function *multi_function = reinterpret_cast< multiple_factory_function * >( cast_to_fptr( multi_func ) );
201  if ( multi_function )
202  {
203  std::vector<QgsProviderMetadata *> *metadatas = multi_function();
204  for ( const auto meta : *metadatas )
205  {
206  if ( findMetadata_( mProviders, meta->key() ) )
207  {
208  QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->key() ) );
209  delete meta;
210  continue;
211  }
212  // add this provider to the provider map
213  mProviders[meta->key()] = meta;
214  }
215  delete metadatas;
216  }
217  else
218  {
219  QFunctionPointer func = myLib.resolve( QStringLiteral( "providerMetadataFactory" ).toLatin1().data() );
220  factory_function *function = reinterpret_cast< factory_function * >( cast_to_fptr( func ) );
221  if ( !function )
222  {
223  QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...invalid (no providerMetadataFactory method)" ).arg( myLib.fileName() ), 2 );
224  continue;
225  }
226 
227  QgsProviderMetadata *meta = function();
228  if ( !meta )
229  {
230  QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (no metadata returned)" ).arg( myLib.fileName() ) );
231  continue;
232  }
233 
234  if ( findMetadata_( mProviders, meta->key() ) )
235  {
236  QgsDebugMsg( QStringLiteral( "Checking %1: ...invalid (key %2 already registered)" ).arg( myLib.fileName() ).arg( meta->key() ) );
237  delete meta;
238  continue;
239  }
240  // add this provider to the provider map
241  mProviders[meta->key()] = meta;
242  }
243  }
244 #endif
245  QgsDebugMsg( QStringLiteral( "Loaded %1 providers (%2) " ).arg( mProviders.size() ).arg( providerList().join( ';' ) ) );
246 
247  // now initialize all providers
248  for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
249  {
250  const QString &key = it->first;
251 
252  QgsScopedRuntimeProfile profile( QObject::tr( "Initialize %1" ).arg( key ) );
253 
254  QgsProviderMetadata *meta = it->second;
255 
256  // now get vector file filters, if any
258  if ( !fileVectorFilters.isEmpty() )
259  {
260  mVectorFileFilters += fileVectorFilters;
261  QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...loaded OK (%2 file filters)" ).arg( key ).arg( fileVectorFilters.split( ";;" ).count() ), 2 );
262  }
263 
264  // now get raster file filters, if any
266  if ( !fileRasterFilters.isEmpty() )
267  {
268  QgsDebugMsgLevel( "raster filters: " + fileRasterFilters, 2 );
269  mRasterFileFilters += fileRasterFilters;
270  QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...loaded OK (%2 file filters)" ).arg( key ).arg( fileRasterFilters.split( ";;" ).count() ), 2 );
271  }
272 
273  // now get mesh file filters, if any
275  if ( !fileMeshFilters.isEmpty() )
276  {
277  mMeshFileFilters += fileMeshFilters;
278  QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...loaded OK (%2 file mesh filters)" ).arg( key ).arg( mMeshFileFilters.split( ";;" ).count() ), 2 );
279 
280  }
281 
283  if ( !fileMeshDatasetFilters.isEmpty() )
284  {
285  mMeshDatasetFileFilters += fileMeshDatasetFilters;
286  QgsDebugMsgLevel( QStringLiteral( "Checking %1: ...loaded OK (%2 file dataset filters)" ).arg( key ).arg( mMeshDatasetFileFilters.split( ";;" ).count() ), 2 );
287  }
288 
289  // call initProvider() - allows provider to register its services to QGIS
290  meta->initProvider();
291  }
292 
293  // load database drivers (only OGR)
294  mDatabaseDrivers = QgsOgrProviderUtils::databaseDrivers();
295 
296  // load directory drivers (only OGR)
297  mDirectoryDrivers = QgsOgrProviderUtils::directoryDrivers();
298 
299  // load protocol drivers (only OGR)
300  mProtocolDrivers = QgsOgrProviderUtils::protocolDrivers();
301 } // QgsProviderRegistry ctor
302 
303 
304 // typedef for the unload dataprovider function
306 
307 void QgsProviderRegistry::clean()
308 {
309  // avoid recreating a new project just to clean it
310  if ( QgsProject::sProject )
312 
313  Providers::const_iterator it = mProviders.begin();
314 
315  while ( it != mProviders.end() )
316  {
317  QgsDebugMsgLevel( QStringLiteral( "cleanup:%1" ).arg( it->first ), 5 );
318  it->second->cleanupProvider();
319  delete it->second;
320  ++it;
321  }
322  mProviders.clear();
323 }
324 
325 bool QgsProviderRegistry::exists()
326 {
327  return static_cast< bool >( sInstance );
328 }
329 
331 {
332  clean();
333  if ( sInstance == this )
334  sInstance = nullptr;
335 }
336 
337 QString QgsProviderRegistry::library( QString const &providerKey ) const
338 {
339  QgsProviderMetadata *md = findMetadata_( mProviders, providerKey );
340 
341  if ( md )
342  {
344  return md->library();
346  }
347 
348  return QString();
349 }
350 
351 QString QgsProviderRegistry::pluginList( bool asHTML ) const
352 {
353  Providers::const_iterator it = mProviders.begin();
354 
355  if ( mProviders.empty() )
356  return QObject::tr( "No data provider plugins are available. No vector layers can be loaded" );
357 
358  QString list;
359 
360  if ( asHTML )
361  list += QLatin1String( "<ol>" );
362 
363  while ( it != mProviders.end() )
364  {
365  if ( asHTML )
366  list += QLatin1String( "<li>" );
367 
368  list += it->second->description();
369 
370  if ( asHTML )
371  list += QLatin1String( "<br></li>" );
372  else
373  list += '\n';
374 
375  ++it;
376  }
377 
378  if ( asHTML )
379  list += QLatin1String( "</ol>" );
380 
381  return list;
382 }
383 
385 {
386  mLibraryDirectory = path;
387  clean();
388  init();
389 }
390 
392 {
393  return mLibraryDirectory;
394 }
395 
396 
397 /* Copied from QgsVectorLayer::setDataProvider
398  * TODO: Make it work in the generic environment
399  *
400  * TODO: Is this class really the best place to put a data provider loader?
401  * It seems more sensible to provide the code in one place rather than
402  * in qgsrasterlayer, qgsvectorlayer, serversourceselect, etc.
403  */
404 QgsDataProvider *QgsProviderRegistry::createProvider( QString const &providerKey, QString const &dataSource,
405  const QgsDataProvider::ProviderOptions &options,
406  QgsDataProvider::ReadFlags flags )
407 {
408  // XXX should I check for and possibly delete any pre-existing providers?
409  // XXX How often will that scenario occur?
410 
411  QgsProviderMetadata *metadata = findMetadata_( mProviders, providerKey );
412  if ( !metadata )
413  {
414  QgsMessageLog::logMessage( QObject::tr( "Invalid data provider %1" ).arg( providerKey ) );
415  return nullptr;
416  }
417 
418  return metadata->createProvider( dataSource, options, flags );
419 }
420 
421 int QgsProviderRegistry::providerCapabilities( const QString &providerKey ) const
422 {
423  const QList< QgsDataItemProvider * > itemProviders = dataItemProviders( providerKey );
425  //concat flags
426  for ( const QgsDataItemProvider *itemProvider : itemProviders )
427  {
428  ret = ret | itemProvider->capabilities();
429  }
430  return ret;
431 }
432 
433 QVariantMap QgsProviderRegistry::decodeUri( const QString &providerKey, const QString &uri )
434 {
435  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
436  if ( meta )
437  return meta->decodeUri( uri );
438  else
439  return QVariantMap();
440 }
441 
442 QString QgsProviderRegistry::encodeUri( const QString &providerKey, const QVariantMap &parts )
443 {
444  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
445  if ( meta )
446  return meta->encodeUri( parts );
447  else
448  return QString();
449 }
450 
452  const QString &uri,
453  const QgsFields &fields,
454  QgsWkbTypes::Type wkbType,
455  const QgsCoordinateReferenceSystem &srs,
456  bool overwrite, QMap<int, int> &oldToNewAttrIdxMap,
457  QString &errorMessage,
458  const QMap<QString, QVariant> *options )
459 {
461 
462  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
463  if ( meta )
464  return meta->createEmptyLayer( uri, fields, wkbType, srs, overwrite, oldToNewAttrIdxMap, errorMessage, options );
465  else
466  {
468  errorMessage = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
469  }
470 
471  return ret;
472 }
473 
474 QgsRasterDataProvider *QgsProviderRegistry::createRasterDataProvider( const QString &providerKey, const QString &uri, const QString &format,
475  int nBands, Qgis::DataType type, int width, int height,
476  double *geoTransform, const QgsCoordinateReferenceSystem &crs,
477  const QStringList &createOptions )
478 {
479  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
480  if ( meta )
481  return meta->createRasterDataProvider( uri, format, nBands, type, width, height, geoTransform, crs, createOptions );
482  else
483  return nullptr;
484 }
485 
486 QList<QPair<QString, QString> > QgsProviderRegistry::pyramidResamplingMethods( const QString &providerKey )
487 {
488  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
489  if ( meta )
490  return meta->pyramidResamplingMethods();
491  else
492  return QList<QPair<QString, QString> >();
493 }
494 
495 QList<QgsDataItemProvider *> QgsProviderRegistry::dataItemProviders( const QString &providerKey ) const
496 {
497  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
498  if ( meta )
499  return meta->dataItemProviders();
500  else
501  return QList<QgsDataItemProvider *>();
502 }
503 
504 int QgsProviderRegistry::listStyles( const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause )
505 {
506  int res = -1;
507  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
508  if ( meta )
509  {
510  res = meta->listStyles( uri, ids, names, descriptions, errCause );
511  }
512  else
513  {
514  errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
515  }
516  return res;
517 }
518 
519 QString QgsProviderRegistry::getStyleById( const QString &providerKey, const QString &uri, QString styleId, QString &errCause )
520 {
521  QString ret;
522  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
523  if ( meta )
524  {
525  ret = meta->getStyleById( uri, styleId, errCause );
526  }
527  else
528  {
529  errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
530  }
531  return ret;
532 }
533 
534 bool QgsProviderRegistry::deleteStyleById( const QString &providerKey, const QString &uri, QString styleId, QString &errCause )
535 {
536  bool ret( false );
537 
538  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
539  if ( meta )
540  return meta->deleteStyleById( uri, styleId, errCause );
541  else
542  {
543  errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
544  }
545  return ret;
546 }
547 
548 bool QgsProviderRegistry::saveStyle( const QString &providerKey, const QString &uri, const QString &qmlStyle,
549  const QString &sldStyle, const QString &styleName, const QString &styleDescription,
550  const QString &uiFileContent, bool useAsDefault, QString &errCause )
551 {
552  bool ret( false );
553  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
554  if ( meta )
555  ret = meta->saveStyle( uri, qmlStyle, sldStyle, styleName, styleDescription,
556  uiFileContent, useAsDefault, errCause );
557  else
558  {
559  errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
560  }
561  return ret;
562 }
563 
564 QString QgsProviderRegistry::loadStyle( const QString &providerKey, const QString &uri, QString &errCause )
565 {
566  QString ret;
567  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
568  if ( meta )
569  ret = meta->loadStyle( uri, errCause );
570  else
571  {
572  errCause = QObject::tr( "Unable to load %1 provider" ).arg( providerKey );
573  }
574  return ret;
575 }
576 
577 bool QgsProviderRegistry::createDb( const QString &providerKey, const QString &dbPath, QString &errCause )
578 {
579  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
580  if ( meta )
581  return meta->createDb( dbPath, errCause );
582  else
583  {
584  errCause = QStringLiteral( "Resolving createDb(...) failed" );
585  return false;
586  }
587 }
588 
589 QgsTransaction *QgsProviderRegistry::createTransaction( const QString &providerKey, const QString &connString )
590 {
591  QgsProviderMetadata *meta = findMetadata_( mProviders, providerKey );
592  if ( meta )
593  return meta->createTransaction( connString );
594  else
595  return nullptr;
596 }
597 
598 QWidget *QgsProviderRegistry::createSelectionWidget( const QString &providerKey,
599  QWidget *parent, Qt::WindowFlags fl, QgsProviderRegistry::WidgetMode widgetMode )
600 {
601  Q_UNUSED( providerKey );
602  Q_UNUSED( parent );
603  Q_UNUSED( fl );
604  Q_UNUSED( widgetMode );
605  QgsDebugMsg( "deprecated call - use QgsGui::sourceSelectProviderRegistry()->createDataSourceWidget() instead" );
606  return nullptr;
607 }
608 
609 QFunctionPointer QgsProviderRegistry::function( QString const &providerKey,
610  QString const &functionName )
611 {
613  QString lib = library( providerKey );
615  if ( lib.isEmpty() )
616  return nullptr;
617 
618  QLibrary myLib( lib );
619 
620  QgsDebugMsg( "Library name is " + myLib.fileName() );
621 
622  if ( myLib.load() )
623  {
624  return myLib.resolve( functionName.toLatin1().data() );
625  }
626  else
627  {
628  QgsDebugMsg( "Cannot load library: " + myLib.errorString() );
629  return nullptr;
630  }
631 }
632 
633 QLibrary *QgsProviderRegistry::createProviderLibrary( QString const &providerKey ) const
634 {
636  QString lib = library( providerKey );
638  if ( lib.isEmpty() )
639  return nullptr;
640 
641  std::unique_ptr< QLibrary > myLib( new QLibrary( lib ) );
642 
643  QgsDebugMsg( "Library name is " + myLib->fileName() );
644 
645  if ( myLib->load() )
646  return myLib.release();
647 
648  QgsDebugMsg( "Cannot load library: " + myLib->errorString() );
649 
650  return nullptr;
651 }
652 
654 {
655  QgsDebugMsg( "deprecated - use QgsGui::providerGuiRegistry() instead." );
656 }
657 
659 {
660  if ( providerMetadata )
661  {
662  if ( mProviders.find( providerMetadata->key() ) == mProviders.end() )
663  {
664  mProviders[ providerMetadata->key() ] = providerMetadata;
665  return true;
666  }
667  else
668  {
669  QgsDebugMsgLevel( QStringLiteral( "Cannot register provider metadata: a provider with the same key (%1) was already registered!" ).arg( providerMetadata->key() ), 2 );
670  }
671  }
672  else
673  {
674  QgsDebugMsgLevel( QStringLiteral( "Trying to register a null metadata provider!" ), 2 );
675  }
676  return false;
677 }
678 
680 {
681  return mVectorFileFilters;
682 }
683 
685 {
686  return mRasterFileFilters;
687 }
688 
690 {
691  return mMeshFileFilters;
692 }
693 
695 {
696  return mMeshDatasetFileFilters;
697 }
698 
700 {
701  return mDatabaseDrivers;
702 }
703 
705 {
706  return mDirectoryDrivers;
707 }
708 
710 {
711  return mProtocolDrivers;
712 }
713 
715 {
716  QStringList lst;
717  for ( Providers::const_iterator it = mProviders.begin(); it != mProviders.end(); ++it )
718  {
719  lst.append( it->first );
720  }
721  return lst;
722 }
723 
724 QgsProviderMetadata *QgsProviderRegistry::providerMetadata( const QString &providerKey ) const
725 {
726  return findMetadata_( mProviders, providerKey );
727 }
cleanupProviderFunction_t
void cleanupProviderFunction_t()
Definition: qgsproviderregistry.cpp:305
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
QgsProviderMetadata::dataItemProviders
virtual QList< QgsDataItemProvider * > dataItemProviders() const
Returns data item providers.
Definition: qgsprovidermetadata.cpp:172
qgsmessageoutput.h
qgsruntimeprofiler.h
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsProviderMetadata::loadStyle
virtual QString loadStyle(const QString &uri, QString &errCause)
Loads a layer style defined by uri.
Definition: qgsprovidermetadata.cpp:203
QgsProviderRegistry::createDb
bool createDb(const QString &providerKey, const QString &dbPath, QString &errCause)
Creates database by the provider on the path.
Definition: qgsproviderregistry.cpp:577
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
QgsDebugMsgLevel
#define QgsDebugMsgLevel(str, level)
Definition: qgslogger.h:39
QgsProviderRegistry
A registry / canonical manager of data providers.
Definition: qgsproviderregistry.h:55
QgsProviderRegistry::createProviderLibrary
Q_DECL_DEPRECATED QLibrary * createProviderLibrary(const QString &providerKey) const
Returns a new QLibrary for the specified providerKey.
Definition: qgsproviderregistry.cpp:633
QgsProviderRegistry::createTransaction
QgsTransaction * createTransaction(const QString &providerKey, const QString &connString)
Returns new instance of transaction.
Definition: qgsproviderregistry.cpp:589
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsProviderRegistry::~QgsProviderRegistry
virtual ~QgsProviderRegistry()
Definition: qgsproviderregistry.cpp:330
QgsProviderRegistry::encodeUri
QString encodeUri(const QString &providerKey, const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
Definition: qgsproviderregistry.cpp:442
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsProviderRegistry::listStyles
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.
Definition: qgsproviderregistry.cpp:504
QgsProviderRegistry::providerList
QStringList providerList() const
Returns list of available providers by their keys.
Definition: qgsproviderregistry.cpp:714
QgsProject::removeAllMapLayers
void removeAllMapLayers()
Removes all registered layers.
Definition: qgsproject.cpp:3420
qgsmemoryprovider.h
qgis.h
QgsProject::instance
static QgsProject * instance()
Returns the QgsProject singleton instance.
Definition: qgsproject.cpp:468
QgsProviderRegistry::fileMeshFilters
virtual QString fileMeshFilters() const
Returns mesh file filter string.
Definition: qgsproviderregistry.cpp:689
QgsProviderRegistry::deleteStyleById
bool deleteStyleById(const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
Deletes a layer style defined by styleId.
Definition: qgsproviderregistry.cpp:534
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsProviderMetadata::createEmptyLayer
virtual QgsVectorLayerExporter::ExportError createEmptyLayer(const QString &uri, const QgsFields &fields, QgsWkbTypes::Type wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, QMap< int, int > &oldToNewAttrIdxMap, QString &errorMessage, const QMap< QString, QVariant > *options)
Creates new empty vector layer.
Definition: qgsprovidermetadata.cpp:138
QgsTransaction
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Definition: qgstransaction.h:57
QgsProviderRegistry::Providers
std::map< QString, QgsProviderMetadata * > Providers
Type for data provider metadata associative container.
Definition: qgsproviderregistry.h:364
QgsDebugMsg
#define QgsDebugMsg(str)
Definition: qgslogger.h:38
QgsProviderMetadata::getStyleById
virtual QString getStyleById(const QString &uri, QString styleId, QString &errCause)
Gets a layer style defined by uri.
Definition: qgsprovidermetadata.cpp:184
QgsProviderRegistry::dataItemProviders
QList< QgsDataItemProvider * > dataItemProviders(const QString &providerKey) const
Returns list of data item providers of the provider.
Definition: qgsproviderregistry.cpp:495
QgsProviderRegistry::pyramidResamplingMethods
QList< QPair< QString, QString > > pyramidResamplingMethods(const QString &providerKey)
Returns list of raster pyramid resampling methods.
Definition: qgsproviderregistry.cpp:486
QgsProviderMetadata::createRasterDataProvider
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.
Definition: qgsprovidermetadata.cpp:148
QgsProviderRegistry::WidgetMode
WidgetMode
Different ways a source select dialog can be used.
Definition: qgsproviderregistry.h:65
QgsProviderRegistry::createEmptyLayer
QgsVectorLayerExporter::ExportError createEmptyLayer(const QString &providerKey, const QString &uri, const QgsFields &fields, QgsWkbTypes::Type wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, QMap< int, int > &oldToNewAttrIdxMap, QString &errorMessage, const QMap< QString, QVariant > *options)
Creates new empty vector layer.
Definition: qgsproviderregistry.cpp:451
Q_NOWARN_DEPRECATED_POP
#define Q_NOWARN_DEPRECATED_POP
Definition: qgis.h:797
QgsProviderRegistry::setLibraryDirectory
void setLibraryDirectory(const QDir &path)
Sets library directory where to search for plugins.
Definition: qgsproviderregistry.cpp:384
QgsProviderRegistry::getStyleById
QString getStyleById(const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
Gets a layer style defined by styleId.
Definition: qgsproviderregistry.cpp:519
qgsprovidermetadata.h
QgsProviderMetadata::encodeUri
virtual QString encodeUri(const QVariantMap &parts)
Reassembles a provider data source URI from its component paths (e.g.
Definition: qgsprovidermetadata.cpp:133
QgsProviderRegistry::pluginList
QString pluginList(bool asHtml=false) const
Returns list of provider plugins found.
Definition: qgsproviderregistry.cpp:351
qgsproviderregistry.h
QgsProviderRegistry::createRasterDataProvider
virtual 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.
Definition: qgsproviderregistry.cpp:474
QgsDataItemProvider
This is the interface for those who want to add custom data items to the browser tree.
Definition: qgsdataitemprovider.h:46
QgsProviderMetadata::key
QString key() const
This returns the unique key associated with the provider.
Definition: qgsprovidermetadata.cpp:43
QgsProviderMetadata::createProvider
virtual QgsDataProvider * createProvider(const QString &uri, const QgsDataProvider::ProviderOptions &options, QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Class factory to return a pointer to a newly created QgsDataProvider object.
Definition: qgsprovidermetadata.cpp:83
QgsProviderMetadata::listStyles
virtual int listStyles(const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause)
Lists stored layer styles in the provider defined by uri.
Definition: qgsprovidermetadata.cpp:177
QgsProviderRegistry::function
Q_DECL_DEPRECATED QFunctionPointer function(const QString &providerKey, const QString &functionName)
Gets pointer to provider function.
Definition: qgsproviderregistry.cpp:609
QgsProviderRegistry::fileRasterFilters
virtual QString fileRasterFilters() const
Returns raster file filter string.
Definition: qgsproviderregistry.cpp:684
QgsProviderRegistry::decodeUri
QVariantMap decodeUri(const QString &providerKey, const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Definition: qgsproviderregistry.cpp:433
QgsProviderRegistry::providerMetadata
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
Definition: qgsproviderregistry.cpp:724
QgsProviderRegistry::providerCapabilities
Q_DECL_DEPRECATED int providerCapabilities(const QString &providerKey) const
Returns the provider capabilities.
Definition: qgsproviderregistry.cpp:421
QgsVectorLayerExporter::ErrInvalidProvider
@ ErrInvalidProvider
Could not find a matching provider key.
Definition: qgsvectorlayerexporter.h:61
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsProviderMetadata::createTransaction
virtual QgsTransaction * createTransaction(const QString &connString)
Returns new instance of transaction.
Definition: qgsprovidermetadata.cpp:215
QgsProviderRegistry::directoryDrivers
virtual QString directoryDrivers() const
Returns a string containing the available directory drivers.
Definition: qgsproviderregistry.cpp:704
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:137
qgsvectorlayer.h
QgsProviderMetadata::saveStyle
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.
Definition: qgsprovidermetadata.cpp:196
qgsvectortileprovidermetadata.h
QgsProviderRegistry::fileMeshDatasetFilters
virtual QString fileMeshDatasetFilters() const
Returns mesh's dataset file filter string.
Definition: qgsproviderregistry.cpp:694
QgsProviderRegistry::loadStyle
QString loadStyle(const QString &providerKey, const QString &uri, QString &errCause)
Loads a layer style defined by uri.
Definition: qgsproviderregistry.cpp:564
QgsProviderMetadata::deleteStyleById
virtual bool deleteStyleById(const QString &uri, QString styleId, QString &errCause)
Deletes a layer style defined by styleId.
Definition: qgsprovidermetadata.cpp:190
qgsdataitemprovider.h
QgsVectorLayerExporter::ExportError
ExportError
Error codes.
Definition: qgsvectorlayerexporter.h:52
QgsProviderRegistry::createProvider
QgsDataProvider * createProvider(const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
Creates a new instance of a provider.
Definition: qgsproviderregistry.cpp:404
QgsProviderRegistry::registerProvider
bool registerProvider(QgsProviderMetadata *providerMetadata)
register a new vector data provider from its providerMetadata
Definition: qgsproviderregistry.cpp:658
QgsProviderRegistry::saveStyle
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.
Definition: qgsproviderregistry.cpp:548
QgsProviderRegistry::databaseDrivers
virtual QString databaseDrivers() const
Returns a string containing the available database drivers.
Definition: qgsproviderregistry.cpp:699
QgsProviderMetadata::FilterType::FilterMesh
@ FilterMesh
QgsProviderMetadata::library
Q_DECL_DEPRECATED QString library() const
This returns the library file name.
Definition: qgsprovidermetadata.cpp:53
QgsScopedRuntimeProfile
Scoped object for logging of the runtime for a single operation or group of operations.
Definition: qgsruntimeprofiler.h:328
QgsMessageLog::logMessage
static void logMessage(const QString &message, const QString &tag=QString(), Qgis::MessageLevel level=Qgis::Warning, bool notifyUser=true)
Adds a message to the log instance (and creates it if necessary).
Definition: qgsmessagelog.cpp:27
QgsDataProvider::NoDataCapabilities
@ NoDataCapabilities
Definition: qgsdataprovider.h:75
qgsdataprovider.h
QgsProviderMetadata::initProvider
virtual void initProvider()
Initialize the provider.
Definition: qgsprovidermetadata.cpp:63
cast_to_fptr
#define cast_to_fptr(f)
Definition: qgis.h:208
QgsProviderRegistry::fileVectorFilters
virtual QString fileVectorFilters() const
Returns vector file filter string.
Definition: qgsproviderregistry.cpp:679
QgsProviderMetadata::FilterType::FilterVector
@ FilterVector
QgsProviderRegistry::protocolDrivers
virtual QString protocolDrivers() const
Returns a string containing the available protocol drivers.
Definition: qgsproviderregistry.cpp:709
qgslogger.h
QgsProviderRegistry::library
Q_DECL_DEPRECATED QString library(const QString &providerKey) const
Returns path for the library of the provider.
Definition: qgsproviderregistry.cpp:337
QgsProviderRegistry::libraryDirectory
QDir libraryDirectory() const
Returns the library directory where plugins are found.
Definition: qgsproviderregistry.cpp:391
QgsProviderRegistry::createSelectionWidget
Q_DECL_DEPRECATED QWidget * createSelectionWidget(const QString &providerKey, QWidget *parent=nullptr, Qt::WindowFlags fl=Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode=QgsProviderRegistry::WidgetMode::None)
Returns a new widget for selecting layers from a provider.
Definition: qgsproviderregistry.cpp:598
QgsProviderMetadata::pyramidResamplingMethods
virtual QList< QPair< QString, QString > > pyramidResamplingMethods()
Returns pyramid resampling methods available for provider.
Definition: qgsprovidermetadata.cpp:167
QgsProviderRegistry::registerGuis
Q_DECL_DEPRECATED void registerGuis(QWidget *widget)
Definition: qgsproviderregistry.cpp:653
Q_NOWARN_DEPRECATED_PUSH
#define Q_NOWARN_DEPRECATED_PUSH
Definition: qgis.h:796
QgsProviderRegistry::instance
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
Definition: qgsproviderregistry.cpp:48
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:89
qgsproject.h
QgsProviderMetadata::filters
virtual QString filters(FilterType type)
Builds the list of file filter strings (supported formats)
Definition: qgsprovidermetadata.cpp:73
QgsProviderMetadata::decodeUri
virtual QVariantMap decodeUri(const QString &uri)
Breaks a provider data source URI into its component paths (e.g.
Definition: qgsprovidermetadata.cpp:128
QgsProviderMetadata::createDb
virtual bool createDb(const QString &dbPath, QString &errCause)
Creates database by the provider on the path.
Definition: qgsprovidermetadata.cpp:209
QgsProviderMetadata::FilterType::FilterMeshDataset
@ FilterMeshDataset
qgsmessagelog.h
QgsProviderMetadata::FilterType::FilterRaster
@ FilterRaster