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