QGIS API Documentation  3.17.0-Master (a035f434f4)
qgsproviderregistry.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsproviderregistry.h - 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 #ifndef QGSPROVIDERREGISTRY_H
20 #define QGSPROVIDERREGISTRY_H
21 
22 #include <map>
23 
24 #include <QDir>
25 #include <QLibrary>
26 #include <QString>
27 
28 #include "qgsvectorlayerexporter.h"
29 #include "qgsdataprovider.h"
30 #include "qgis_core.h"
31 #include "qgis_sip.h"
32 
34 class QgsVectorLayer;
37 class QgsDataItem;
39 
54 class CORE_EXPORT QgsProviderRegistry
55 {
56 
57  public:
58 
59  // TODO QGIS 4 - either move to QgsAbstractDataSourceWidget or remove altogether
60 
65  {
66 
73 
79 
86  };
87 
89  static QgsProviderRegistry *instance( const QString &pluginPath = QString() );
90 
92 
101  Q_DECL_DEPRECATED QString library( const QString &providerKey ) const SIP_DEPRECATED;
102 
104  QString pluginList( bool asHtml = false ) const;
105 
109  QDir libraryDirectory() const;
110 
112  void setLibraryDirectory( const QDir &path );
113 
124  QgsDataProvider *createProvider( const QString &providerKey,
125  const QString &dataSource,
127  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
128 
135  Q_DECL_DEPRECATED int providerCapabilities( const QString &providerKey ) const SIP_DEPRECATED;
136 
142  SIP_SKIP 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 );
143 
150  QgsRasterDataProvider *createRasterDataProvider(
151  const QString &providerKey,
152  const QString &uri,
153  const QString &format,
154  int nBands,
155  Qgis::DataType type,
156  int width, int height,
157  double *geoTransform,
159  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
160 
166  QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
167 
176  QVariantMap decodeUri( const QString &providerKey, const QString &uri );
177 
187  QString encodeUri( const QString &providerKey, const QVariantMap &parts );
188 
195  Q_DECL_DEPRECATED QWidget *createSelectionWidget( const QString &providerKey, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ) SIP_DEPRECATED;
196 
202  QList< QgsDataItemProvider * > dataItemProviders( const QString &providerKey ) const SIP_FACTORY;
203 
209  int listStyles( const QString &providerKey,
210  const QString &uri,
211  QStringList &ids,
212  QStringList &names,
213  QStringList &descriptions,
214  QString &errCause );
215 
221  QString getStyleById( const QString &providerKey, const QString &uri, QString styleId, QString &errCause );
222 
227  bool deleteStyleById( const QString &providerKey, const QString &uri, QString styleId, QString &errCause );
228 
234  bool saveStyle( const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle,
235  const QString &styleName, const QString &styleDescription,
236  const QString &uiFileContent, bool useAsDefault, QString &errCause );
237 
242  QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );
243 
248  bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
249 
254  QgsTransaction *createTransaction( const QString &providerKey, const QString &connString ) SIP_FACTORY;
255 
266  Q_DECL_DEPRECATED QFunctionPointer function( const QString &providerKey, const QString &functionName ) SIP_DEPRECATED;
267 
277  Q_DECL_DEPRECATED QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY SIP_DEPRECATED;
278 
280  QStringList providerList() const;
281 
283  QgsProviderMetadata *providerMetadata( const QString &providerKey ) const;
284 
292  class CORE_EXPORT ProviderCandidateDetails
293  {
294 
295  public:
296 
300  ProviderCandidateDetails( QgsProviderMetadata *metadata, const QList< QgsMapLayerType > &layerTypes )
301  : mMetadata( metadata )
302  , mLayerTypes( layerTypes )
303  {}
304 
308  QgsProviderMetadata *metadata() const { return mMetadata; }
309 
314  QList<QgsMapLayerType> layerTypes() const { return mLayerTypes; }
315 
316 #ifdef SIP_RUN
317  SIP_PYOBJECT __repr__();
318  % MethodCode
319  QString str = QStringLiteral( "<QgsProviderRegistry.ProviderCandidateDetails: %1>" ).arg( sipCpp->metadata()->key() );
320  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
321  % End
322 #endif
323 
324  private:
325  QgsProviderMetadata *mMetadata = nullptr;
326 
327  QList< QgsMapLayerType > mLayerTypes;
328 
329  };
330 
347  QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
348 
365  bool shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const;
366 
380  bool uriIsBlocklisted( const QString &uri ) const;
381 
392  QString fileVectorFilters() const;
393 
406  QString fileRasterFilters() const;
407 
421  QString fileMeshFilters() const;
422 
433  QString fileMeshDatasetFilters() const;
434 
447  QString filePointCloudFilters() const;
448 
450  QString databaseDrivers() const;
452  QString directoryDrivers() const;
454  QString protocolDrivers() const;
455 
459  Q_DECL_DEPRECATED void registerGuis( QWidget *widget ) SIP_DEPRECATED;
460 
467  bool registerProvider( QgsProviderMetadata *providerMetadata SIP_TRANSFER );
468 
470  SIP_SKIP typedef std::map<QString, QgsProviderMetadata *> Providers;
471 
472  private:
474  QgsProviderRegistry( const QString &pluginPath );
475 
476 #ifdef SIP_RUN
477  QgsProviderRegistry( const QString &pluginPath );
478 #endif
479 
480  void init();
481  void clean();
482 
484  Providers mProviders;
485 
487  QDir mLibraryDirectory;
488 
498  QString mVectorFileFilters;
499 
503  QString mRasterFileFilters;
504 
508  QString mMeshFileFilters;
509 
513  QString mMeshDatasetFileFilters;
514 
518  QString mPointCloudFileFilters;
519 
526  QString mDatabaseDrivers;
527 
533  QString mDirectoryDrivers;
534 
541  QString mProtocolDrivers;
542 
546  static bool exists();
547 
548  friend class QgsApplication;
549 
550 }; // class QgsProviderRegistry
551 
552 #endif //QGSPROVIDERREGISTRY_H
553 
WidgetMode
Different ways a source select dialog can be used.
Extends QApplication to provide access to QGIS specific resources such as theme paths, database paths etc.
Handles storage of information regarding WKB types and their properties.
Definition: qgswkbtypes.h:41
Used by data items for QgsDataItem::paramWidget().
Container of fields for a vector layer.
Definition: qgsfields.h:44
Abstract base class for spatial data provider implementations.
const QgsCoordinateReferenceSystem & crs
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:45
QList< QgsMapLayerType > layerTypes() const
Returns a list of map layer types which are valid options for opening the target using this candidate...
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Basic mode when the widget is used as a standalone dialog.
Base class for all items in the model.
Definition: qgsdataitem.h:50
A convenience class for exporting vector layers to a destination data provider.
A registry / canonical manager of data providers.
Setting options for creating vector data providers.
Used for the data source manager dialog where the widget is embedded as the main content for a partic...
Holds data provider key, description, and associated shared library file or function pointer informat...
This class allows including a set of layers in a database-side transaction, provided the layer data p...
std::map< QString, QgsProviderMetadata * > Providers
Type for data provider metadata associative container.
This class represents a coordinate reference system (CRS).
QgsProviderMetadata * metadata() const
Returns the candidate provider metadata.
Represents a vector layer which manages a vector based data sets.
Contains information pertaining to a candidate provider.
This is the interface for those who want to add custom data items to the browser tree.
ProviderCandidateDetails(QgsProviderMetadata *metadata, const QList< QgsMapLayerType > &layerTypes)
Constructor for ProviderCandidateDetails, with the specified provider metadata and valid candidate la...
Base class for raster data providers.