QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
Classes | Public Types | Public Member Functions | Static Public Member Functions | Friends | List of all members
QgsProviderRegistry Class Reference

A registry / canonical manager of data providers. More...

#include <qgsproviderregistry.h>

Classes

class  ProviderCandidateDetails
 Contains information pertaining to a candidate provider. More...
 
class  UnusableUriDetails
 Contains information about unusable URIs which aren't handled by any registered providers. More...
 
class  UnusableUriHandlerInterface
 An interface used to handle unusable URIs which aren't handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable. More...
 

Public Types

typedef std::map< QString, QgsProviderMetadata * > Providers
 Type for data provider metadata associative container. More...
 
enum  WidgetMode { None , Embedded , Manager }
 Different ways a source select dialog can be used. More...
 

Public Member Functions

 ~QgsProviderRegistry ()
 
bool createDb (const QString &providerKey, const QString &dbPath, QString &errCause)
 Creates database by the provider on the path. More...
 
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. More...
 
QgsDataProvidercreateProvider (const QString &providerKey, const QString &dataSource, const QgsDataProvider::ProviderOptions &options=QgsDataProvider::ProviderOptions(), QgsDataProvider::ReadFlags flags=QgsDataProvider::ReadFlags())
 Creates a new instance of a provider. More...
 
Q_DECL_DEPRECATED QLibrary * createProviderLibrary (const QString &providerKey) const
 Returns a new QLibrary for the specified providerKey. More...
 
QgsRasterDataProvidercreateRasterDataProvider (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. More...
 
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. More...
 
QgsTransactioncreateTransaction (const QString &providerKey, const QString &connString)
 Returns new instance of transaction. More...
 
QString databaseDrivers () const
 Returns a string containing the available database drivers. More...
 
QList< QgsDataItemProvider * > dataItemProviders (const QString &providerKey) const
 Returns list of data item providers of the provider. More...
 
QVariantMap decodeUri (const QString &providerKey, const QString &uri)
 Breaks a provider data source URI into its component paths (e.g. More...
 
bool deleteStyleById (const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
 Deletes a layer style defined by styleId. More...
 
QString directoryDrivers () const
 Returns a string containing the available directory drivers. More...
 
QString encodeUri (const QString &providerKey, const QVariantMap &parts)
 Reassembles a provider data source URI from its component paths (e.g. More...
 
QString fileMeshDatasetFilters () const
 Returns a file filter string for supported mesh dataset files. More...
 
QString fileMeshFilters () const
 Returns a file filter string for supported mesh files. More...
 
QString filePointCloudFilters () const
 Returns a file filter string for supported point clouds. More...
 
QString fileRasterFilters () const
 Returns a file filter string for supported raster files. More...
 
QString fileVectorFilters () const
 Returns a file filter string for supported vector files. More...
 
Q_DECL_DEPRECATED QFunctionPointer function (const QString &providerKey, const QString &functionName)
 Gets pointer to provider function. More...
 
QString getStyleById (const QString &providerKey, const QString &uri, QString styleId, QString &errCause)
 Gets a layer style defined by styleId. More...
 
bool handleUnusableUri (const QString &uri, UnusableUriDetails &details) const
 Returns true if the specified uri can potentially be handled by QGIS, if additional dependencies or build-time requirements are present. More...
 
Q_DECL_DEPRECATED QString library (const QString &providerKey) const
 Returns path for the library of the provider. More...
 
QDir libraryDirectory () const
 Returns the library directory where plugins are found. More...
 
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. More...
 
QString loadStyle (const QString &providerKey, const QString &uri, QString &errCause)
 Loads a layer style defined by uri. More...
 
QString pluginList (bool asHtml=false) const
 Returns list of provider plugins found. More...
 
QList< QgsProviderRegistry::ProviderCandidateDetailspreferredProvidersForUri (const QString &uri) const
 Returns the details for the preferred provider(s) for opening the specified uri. More...
 
QString protocolDrivers () const
 Returns a string containing the available protocol drivers. More...
 
Q_DECL_DEPRECATED int providerCapabilities (const QString &providerKey) const
 Returns the provider capabilities. More...
 
QStringList providerList () const
 Returns list of available providers by their keys. More...
 
QgsProviderMetadataproviderMetadata (const QString &providerKey) const
 Returns metadata of the provider or nullptr if not found. More...
 
QList< QPair< QString, QString > > pyramidResamplingMethods (const QString &providerKey)
 Returns list of raster pyramid resampling methods. More...
 
Q_DECL_DEPRECATED void registerGuis (QWidget *widget)
 
bool registerProvider (QgsProviderMetadata *providerMetadata)
 register a new vector data provider from its providerMetadata More...
 
bool registerUnusableUriHandler (UnusableUriHandlerInterface *handler)
 Registers an unusable URI handler, used to handle unusable URIs which aren't handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable. More...
 
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. More...
 
void setLibraryDirectory (const QDir &path)
 Sets library directory where to search for plugins. More...
 
bool shouldDeferUriForOtherProviders (const QString &uri, const QString &providerKey) const
 Returns true if the provider with matching providerKey should defer handling of the specified uri to another provider. More...
 
bool uriIsBlocklisted (const QString &uri) const
 Returns true if the specified uri is known by any registered provider to be something which should be blocklisted from the QGIS interface, e.g. More...
 

Static Public Member Functions

static QgsProviderRegistryinstance (const QString &pluginPath=QString())
 Means of accessing canonical single instance. More...
 

Friends

class QgsApplication
 

Detailed Description

A registry / canonical manager of data providers.

This is a Singleton class that manages data provider access.

Providers can be either loaded via libraries or native providers that are included in the core QGIS installation and accessed through function pointers.

Loaded providers may be restricted using QGIS_PROVIDER_FILE environment variable. QGIS_PROVIDER_FILE is regexp pattern applied to provider file name (not provider key). For example, if the variable is set to gdal|ogr|postgres it will load only providers gdal, ogr and postgres.

Definition at line 57 of file qgsproviderregistry.h.

Member Typedef Documentation

◆ Providers

Type for data provider metadata associative container.

Definition at line 616 of file qgsproviderregistry.h.

Member Enumeration Documentation

◆ WidgetMode

Different ways a source select dialog can be used.

Enumerator
None 

Basic mode when the widget is used as a standalone dialog.

Originally used as GUI for individual "Add XXX layer" buttons in the main window. Likely not used in live code anymore.

Embedded 

Used for the data source manager dialog where the widget is embedded as the main content for a particular tab.

Manager 

Used by data items for QgsDataItem::paramWidget().

Originally used by QGIS Browser, but does not seem to be in live code anymore. The mode was meant to avoid some actions to keep the browser interface simple (supposedly).

Definition at line 67 of file qgsproviderregistry.h.

Constructor & Destructor Documentation

◆ ~QgsProviderRegistry()

QgsProviderRegistry::~QgsProviderRegistry ( )

Definition at line 415 of file qgsproviderregistry.cpp.

Member Function Documentation

◆ createDb()

bool QgsProviderRegistry::createDb ( const QString &  providerKey,
const QString &  dbPath,
QString &  errCause 
)

Creates database by the provider on the path.

Since
QGIS 3.10

Definition at line 664 of file qgsproviderregistry.cpp.

◆ createEmptyLayer()

QgsVectorLayerExporter::ExportError QgsProviderRegistry::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.

Note
not available in Python bindings
Since
QGIS 3.10

Definition at line 538 of file qgsproviderregistry.cpp.

◆ createProvider()

QgsDataProvider * QgsProviderRegistry::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.

Parameters
providerKeyidentifier of the provider
dataSourcestring containing data source for the provider
optionsprovider options
flagsprovider flags since QGIS 3.16
Returns
new instance of provider or nullptr on error
See also
createRasterDataProvider()

Definition at line 491 of file qgsproviderregistry.cpp.

◆ createProviderLibrary()

QLibrary * QgsProviderRegistry::createProviderLibrary ( const QString &  providerKey) const

Returns a new QLibrary for the specified providerKey.

Ownership of the returned object is transferred to the caller and the caller is responsible for deleting it.

If the provider uses direct provider function pointers instead of a library nullptr will be returned.

Deprecated:
QGIS 3.10 - providers may not need to be loaded from a library

Definition at line 720 of file qgsproviderregistry.cpp.

◆ createRasterDataProvider()

QgsRasterDataProvider * QgsProviderRegistry::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.

See also
createProvider()
Since
QGIS 3.10

Definition at line 561 of file qgsproviderregistry.cpp.

◆ createSelectionWidget()

QWidget * QgsProviderRegistry::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.

Either the parent widget must be set or the caller becomes responsible for deleting the returned widget.

Deprecated:
QGIS 3.10 - use QgsGui::sourceSelectProviderRegistry()->createDataSourceWidget() instead

Definition at line 685 of file qgsproviderregistry.cpp.

◆ createTransaction()

QgsTransaction * QgsProviderRegistry::createTransaction ( const QString &  providerKey,
const QString &  connString 
)

Returns new instance of transaction.

Ownership is transferred to the caller

Since
QGIS 3.10

Definition at line 676 of file qgsproviderregistry.cpp.

◆ databaseDrivers()

QString QgsProviderRegistry::databaseDrivers ( ) const

Returns a string containing the available database drivers.

Definition at line 791 of file qgsproviderregistry.cpp.

◆ dataItemProviders()

QList< QgsDataItemProvider * > QgsProviderRegistry::dataItemProviders ( const QString &  providerKey) const

Returns list of data item providers of the provider.

Note
Ownership of created data item providers is passed to the caller.
Since
QGIS 3.10

Definition at line 582 of file qgsproviderregistry.cpp.

◆ decodeUri()

QVariantMap QgsProviderRegistry::decodeUri ( const QString &  providerKey,
const QString &  uri 
)

Breaks a provider data source URI into its component paths (e.g.

file path, layer name).

Parameters
providerKeyidentifier of the provider
uriuri string
Returns
map containing components. Standard components include "path", "layerName", "url".
Note
this function may not be supported by all providers, an empty map will be returned in such case
Since
QGIS 3.4

Definition at line 520 of file qgsproviderregistry.cpp.

◆ deleteStyleById()

bool QgsProviderRegistry::deleteStyleById ( const QString &  providerKey,
const QString &  uri,
QString  styleId,
QString &  errCause 
)

Deletes a layer style defined by styleId.

Since
QGIS 3.10

Definition at line 621 of file qgsproviderregistry.cpp.

◆ directoryDrivers()

QString QgsProviderRegistry::directoryDrivers ( ) const

Returns a string containing the available directory drivers.

Definition at line 796 of file qgsproviderregistry.cpp.

◆ encodeUri()

QString QgsProviderRegistry::encodeUri ( const QString &  providerKey,
const QVariantMap &  parts 
)

Reassembles a provider data source URI from its component paths (e.g.

file path, layer name).

Parameters
providerKeyidentifier of the provider
partsparts as returned by decodeUri
Returns
datasource uri string
Note
this function may not be supported by all providers, an empty string will be returned in such case
See also
decodeUri()
Since
QGIS 3.12

Definition at line 529 of file qgsproviderregistry.cpp.

◆ fileMeshDatasetFilters()

QString QgsProviderRegistry::fileMeshDatasetFilters ( ) const

Returns a file filter string for supported mesh dataset files.

Returns a string suitable for a QFileDialog of mesh datasets file formats supported by all data providers.

See also
fileMeshFilters()
Since
QGIS 3.6

Definition at line 781 of file qgsproviderregistry.cpp.

◆ fileMeshFilters()

QString QgsProviderRegistry::fileMeshFilters ( ) const

Returns a file filter string for supported mesh files.

Returns a string suitable for a QFileDialog of mesh file formats supported by all data providers.

See also
fileMeshDatasetFilters()
fileRasterFilters()
fileVectorFilters()
filePointCloudFilters()
Since
QGIS 3.6

Definition at line 776 of file qgsproviderregistry.cpp.

◆ filePointCloudFilters()

QString QgsProviderRegistry::filePointCloudFilters ( ) const

Returns a file filter string for supported point clouds.

Returns a string suitable for a QFileDialog of point cloud file formats supported by all data providers.

See also
fileMeshFilters()
fileRasterFilters()
fileVectorFilters()
Since
QGIS 3.18

Definition at line 786 of file qgsproviderregistry.cpp.

◆ fileRasterFilters()

QString QgsProviderRegistry::fileRasterFilters ( ) const

Returns a file filter string for supported raster files.

Returns a string suitable for a QFileDialog of raster file formats supported by all data providers.

Note
This replaces QgsRasterLayer::buildSupportedRasterFileFilter()
See also
fileVectorFilters()
fileMeshFilters()
filePointCloudFilters()

Definition at line 771 of file qgsproviderregistry.cpp.

◆ fileVectorFilters()

QString QgsProviderRegistry::fileVectorFilters ( ) const

Returns a file filter string for supported vector files.

Returns a string suitable for a QFileDialog of vector file formats supported by all data providers.

See also
fileRasterFilters()
fileMeshFilters()
filePointCloudFilters()

Definition at line 766 of file qgsproviderregistry.cpp.

◆ function()

QFunctionPointer QgsProviderRegistry::function ( const QString &  providerKey,
const QString &  functionName 
)

Gets pointer to provider function.

Parameters
providerKeyidentifier of the provider
functionNamename of function
Returns
pointer to function or nullptr on error. If the provider uses direct provider function pointers instead of a library nullptr will be returned.
Deprecated:
QGIS 3.10 - any provider functionality should be accessed through QgsProviderMetadata

Definition at line 696 of file qgsproviderregistry.cpp.

◆ getStyleById()

QString QgsProviderRegistry::getStyleById ( const QString &  providerKey,
const QString &  uri,
QString  styleId,
QString &  errCause 
)

Gets a layer style defined by styleId.

Since
QGIS 3.10

Definition at line 606 of file qgsproviderregistry.cpp.

◆ handleUnusableUri()

bool QgsProviderRegistry::handleUnusableUri ( const QString &  uri,
UnusableUriDetails details 
) const

Returns true if the specified uri can potentially be handled by QGIS, if additional dependencies or build-time requirements are present.

This can be used to show user-friendly warning messages advising them why a particular uri cannot be opened on their QGIS install. For example, if a QGIS install is built without the PDAL library then las/laz files are unusable, and this method can be used to retrieve a user-friendly warning as to why the las/laz files cannot be used on their QGIS build.

Warning
This method does not perform the test to actually determine if the given uri can be handled by any registered provider. It is assumed that prior to calling this method the caller has already determined in advance that the uri could not be handled.
Parameters
uriURI to test
detailswill be populated with details allowing construction of a user-friendly warning message
Returns
true if the uri was matched to a registered QgsProviderRegistry::UnusableUriHandlerInterface.
See also
registerUnusableUriHandler()
Since
QGIS 3.18.1

Definition at line 853 of file qgsproviderregistry.cpp.

◆ instance()

QgsProviderRegistry * QgsProviderRegistry::instance ( const QString &  pluginPath = QString())
static

Means of accessing canonical single instance.

Definition at line 54 of file qgsproviderregistry.cpp.

◆ library()

QString QgsProviderRegistry::library ( const QString &  providerKey) const

Returns path for the library of the provider.

If the provider uses direct provider function pointers instead of a library an empty string will be returned.

Deprecated:
QGIS 3.10 - providers may not need to be loaded from a library (empty string returned)

Definition at line 424 of file qgsproviderregistry.cpp.

◆ libraryDirectory()

QDir QgsProviderRegistry::libraryDirectory ( ) const

Returns the library directory where plugins are found.

Definition at line 478 of file qgsproviderregistry.cpp.

◆ listStyles()

int QgsProviderRegistry::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.

Returns
-1 if not implemented by provider, otherwise number of styles stored
Since
QGIS 3.10

Definition at line 591 of file qgsproviderregistry.cpp.

◆ loadStyle()

QString QgsProviderRegistry::loadStyle ( const QString &  providerKey,
const QString &  uri,
QString &  errCause 
)

Loads a layer style defined by uri.

Since
QGIS 3.10

Definition at line 651 of file qgsproviderregistry.cpp.

◆ pluginList()

QString QgsProviderRegistry::pluginList ( bool  asHtml = false) const

Returns list of provider plugins found.

Definition at line 438 of file qgsproviderregistry.cpp.

◆ preferredProvidersForUri()

QList< QgsProviderRegistry::ProviderCandidateDetails > QgsProviderRegistry::preferredProvidersForUri ( const QString &  uri) const

Returns the details for the preferred provider(s) for opening the specified uri.

The preferred provider is determined by comparing the priority returned by QgsProviderMetadata::priorityForUri() for all registered providers, and selecting the provider with the largest non-zero priority.

An empty list may be returned, which indicates that no providers are available which returned a non-zero priority for the specified URI.

In the case that multiple providers returned the same priority for the URI then all of these providers will be returned.

See also
shouldDeferUriForOtherProviders()
Since
QGIS 3.18

Definition at line 821 of file qgsproviderregistry.cpp.

◆ protocolDrivers()

QString QgsProviderRegistry::protocolDrivers ( ) const

Returns a string containing the available protocol drivers.

Definition at line 801 of file qgsproviderregistry.cpp.

◆ providerCapabilities()

int QgsProviderRegistry::providerCapabilities ( const QString &  providerKey) const

Returns the provider capabilities.

Parameters
providerKeyidentifier of the provider
Since
QGIS 2.6
Deprecated:
QGIS 3.10 (use instead capabilities() method of individual data item provider)

Definition at line 508 of file qgsproviderregistry.cpp.

◆ providerList()

QStringList QgsProviderRegistry::providerList ( ) const

Returns list of available providers by their keys.

Definition at line 806 of file qgsproviderregistry.cpp.

◆ providerMetadata()

QgsProviderMetadata * QgsProviderRegistry::providerMetadata ( const QString &  providerKey) const

Returns metadata of the provider or nullptr if not found.

Definition at line 816 of file qgsproviderregistry.cpp.

◆ pyramidResamplingMethods()

QList< QPair< QString, QString > > QgsProviderRegistry::pyramidResamplingMethods ( const QString &  providerKey)

Returns list of raster pyramid resampling methods.

Since
QGIS 3.10

Definition at line 573 of file qgsproviderregistry.cpp.

◆ registerGuis()

void QgsProviderRegistry::registerGuis ( QWidget *  widget)
Deprecated:
since QGIS 3.10 - does nothing - use QgsGui::providerGuiRegistry()

Definition at line 740 of file qgsproviderregistry.cpp.

◆ registerProvider()

bool QgsProviderRegistry::registerProvider ( QgsProviderMetadata providerMetadata)

register a new vector data provider from its providerMetadata

Returns
true on success, false if a provider with the same key was already registered
Note
ownership of the QgsProviderMetadata instance is transferred to the registry
Since
QGIS 3.2

Definition at line 745 of file qgsproviderregistry.cpp.

◆ registerUnusableUriHandler()

bool QgsProviderRegistry::registerUnusableUriHandler ( QgsProviderRegistry::UnusableUriHandlerInterface handler)

Registers an unusable URI handler, used to handle unusable URIs which aren't handled by any registered providers, and construct user-friendly warnings as to why the URI is unusable.

Returns
true on success
Note
ownership of the UnusableUriHandlerInterface instance is transferred to the registry
Since
QGIS 3.18.1

Definition at line 847 of file qgsproviderregistry.cpp.

◆ saveStyle()

bool QgsProviderRegistry::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.

Since
QGIS 3.10

Definition at line 635 of file qgsproviderregistry.cpp.

◆ setLibraryDirectory()

void QgsProviderRegistry::setLibraryDirectory ( const QDir &  path)

Sets library directory where to search for plugins.

Definition at line 471 of file qgsproviderregistry.cpp.

◆ shouldDeferUriForOtherProviders()

bool QgsProviderRegistry::shouldDeferUriForOtherProviders ( const QString &  uri,
const QString &  providerKey 
) const

Returns true if the provider with matching providerKey should defer handling of the specified uri to another provider.

This method tests whether any providers are listed as the preferred provider for uri (see preferredProvidersForUri()), and if so tests whether the specified provider is included in that preferred providers list. Returns true only if the specified provider is calculated as one of the preferred providers for the URI.

In the case that there is no registered preferred provider for the URI then false will be returned, and the provider must use another metric to determine whether it should handle the URI.

See also
preferredProvidersForUri()
Since
QGIS 3.18

Definition at line 866 of file qgsproviderregistry.cpp.

◆ uriIsBlocklisted()

bool QgsProviderRegistry::uriIsBlocklisted ( const QString &  uri) const

Returns true if the specified uri is known by any registered provider to be something which should be blocklisted from the QGIS interface, e.g.

an internal detail only.

Specifically, this method can be utilized by the browser panel to hide noisy internal details for URIs which are known to be sidecar files only, such as ".aux.xml" files or ".shp.xml" files, or the "ept-build.json" files which sit alongside Entwine "ept.json" point cloud sources.

This method tests whether any of the registered providers return true for the their QgsProviderMetadata::uriIsBlocklisted() implementation for the specified URI.

Since
QGIS 3.18

Definition at line 880 of file qgsproviderregistry.cpp.

Friends And Related Function Documentation

◆ QgsApplication

friend class QgsApplication
friend

Definition at line 696 of file qgsproviderregistry.h.


The documentation for this class was generated from the following files: