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