QgsProviderRegistry class

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.

Public types

using Providers = std::map<QString, QgsProviderMetadata*>
Open the given vector data source.
enum WidgetMode { None, Embedded, Manager }
Different ways a source select dialog can be used (embedded is for the data source manager dialog)

Public static functions

static auto instance(const QString& pluginPath = QString()) -> QgsProviderRegistry*
Means of accessing canonical single instance.

Public functions

auto createProvider(const QString& providerKey, const QString& dataSource, const QgsDataProvider::ProviderOptions& options = QgsDataProvider::ProviderOptions()) -> QgsDataProvider*
Creates a new instance of a provider.
auto createProviderLibrary(const QString& providerKey) const -> QLibrary*
Returns a new QLibrary for the specified providerKey.
auto createSelectionWidget(const QString& providerKey, QWidget* parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None) -> QWidget*
Returns a new widget for selecting layers from a provider.
auto databaseDrivers() const -> QString virtual
Returns a string containing the available database drivers.
auto decodeUri(const QString& providerKey, const QString& uri) -> QVariantMap
Breaks a provider data source URI into its component paths (e.g.
auto directoryDrivers() const -> QString virtual
Returns a string containing the available directory drivers.
auto fileMeshDatasetFilters() const -> QString virtual
Returns mesh's dataset file filter string.
auto fileMeshFilters() const -> QString virtual
Returns mesh file filter string.
auto fileRasterFilters() const -> QString virtual
Returns raster file filter string.
auto fileVectorFilters() const -> QString virtual
Returns vector file filter string.
auto function(const QString& providerKey, const QString& functionName) -> QFunctionPointer
Gets pointer to provider function.
auto library(const QString& providerKey) const -> QString
Returns path for the library of the provider.
auto libraryDirectory() const -> QDir
Returns the library directory where plugins are found.
auto pluginList(bool asHtml = false) const -> QString
Returns list of provider plugins found.
auto protocolDrivers() const -> QString virtual
Returns a string containing the available protocol drivers.
auto providerCapabilities(const QString& providerKey) const -> int
Returns the provider capabilities.
auto providerList() const -> QStringList
Returns list of available providers by their keys.
auto providerMetadata(const QString& providerKey) const -> const QgsProviderMetadata*
Returns metadata of the provider or NULL if not found.
auto registerProvider(QgsProviderMetadata* providerMetadata) -> bool
register a new vector data provider from its providerMetadata
void setLibraryDirectory(const QDir& path)
Sets library directory where to search for plugins.

Typedef documentation

typedef std::map<QString, QgsProviderMetadata*> QgsProviderRegistry::Providers

Open the given vector data source.

Similar to open(QString const &), except that the user specifies a data provider with which to open the data source instead of using the default data provider that QgsDataManager would figure out to use. This should be useful when (and if) there will exist more than one data provider that can handle a given data source. (E.g., use GDAL to open an SDTS file, or a different data provider that uses sdts++.)

Called by QgsDataManager::open().

Temporarily always returns false until finished implementing.

Eventually would be nice if could make QgsDataManager smart enough to figure out whether the given name mapped to a vector, raster, or database source.Type for data provider metadata associative container

Function documentation

QgsDataProvider* QgsProviderRegistry::createProvider(const QString& providerKey, const QString& dataSource, const QgsDataProvider::ProviderOptions& options = QgsDataProvider::ProviderOptions())

Creates a new instance of a provider.

Parameters
providerKey identifier of the provider
dataSource string containing data source for the provider
options provider options
Returns new instance of provider or NULL on error

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.

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.

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

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

Parameters
providerKey identifier of the provider
uri uri string
Returns map containing components. Standard components include "path", "layerName", "url".

file path, layer name).

QString QgsProviderRegistry::fileMeshDatasetFilters() const virtual

Returns mesh's dataset file filter string.

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

This walks through all data providers appending calls to their fileMeshFilters to a string, which is then returned.

QString QgsProviderRegistry::fileMeshFilters() const virtual

Returns mesh file filter string.

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

This walks through all data providers appending calls to their fileMeshFilters to a string, which is then returned.

QString QgsProviderRegistry::fileRasterFilters() const virtual

Returns raster file filter string.

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

This walks through all data providers appending calls to their buildSupportedRasterFileFilter to a string, which is then returned.

QString QgsProviderRegistry::fileVectorFilters() const virtual

Returns vector file filter string.

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

This walks through all data providers appending calls to their fileVectorFilters to a string, which is then returned.

It'd be nice to eventually be raster/vector neutral.

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

Gets pointer to provider function.

Parameters
providerKey identifier of the provider
functionName name of function
Returns pointer to function or NULL on error. If the provider uses direct provider function pointers instead of a library nullptr will be returned.

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.

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

Returns the provider capabilities.

Parameters
providerKey identifier of the provider

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