QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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>

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

virtual ~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())
 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...
 
virtual 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...
 
virtual 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...
 
virtual QString directoryDrivers () const
 Returns a string containing the available directory drivers. More...
 
virtual QString fileMeshDatasetFilters () const
 Returns mesh's dataset file filter string. More...
 
virtual QString fileMeshFilters () const
 Returns mesh file filter string. More...
 
virtual QString fileRasterFilters () const
 Returns raster file filter string. More...
 
virtual QString fileVectorFilters () const
 Returns vector file filter string. 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...
 
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...
 
virtual 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 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...
 

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 54 of file qgsproviderregistry.h.

Member Typedef Documentation

◆ Providers

Type for data provider metadata associative container.

Definition at line 350 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 63 of file qgsproviderregistry.h.

Constructor & Destructor Documentation

◆ ~QgsProviderRegistry()

QgsProviderRegistry::~QgsProviderRegistry ( )
virtual

Definition at line 273 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 509 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 383 of file qgsproviderregistry.cpp.

◆ createProvider()

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

Creates a new instance of a provider.

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

Definition at line 347 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 565 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() 
)
virtual

Creates new instance of raster data provider.

See also
createProvider()
Since
QGIS 3.10

Definition at line 406 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::providerGuiRegistry()->createDataSourceWidget() instead

Definition at line 530 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 521 of file qgsproviderregistry.cpp.

◆ databaseDrivers()

QString QgsProviderRegistry::databaseDrivers ( ) const
virtual

Returns a string containing the available database drivers.

Definition at line 631 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 427 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 374 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 466 of file qgsproviderregistry.cpp.

◆ directoryDrivers()

QString QgsProviderRegistry::directoryDrivers ( ) const
virtual

Returns a string containing the available directory drivers.

Definition at line 636 of file qgsproviderregistry.cpp.

◆ fileMeshDatasetFilters()

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.

See also
fileMeshFilters()
Since
QGIS 3.6

Definition at line 626 of file qgsproviderregistry.cpp.

◆ fileMeshFilters()

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.

See also
fileMeshDatasetFilters()
Since
QGIS 3.6

Definition at line 621 of file qgsproviderregistry.cpp.

◆ fileRasterFilters()

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.

Note
This replaces QgsRasterLayer::buildSupportedRasterFileFilter()

Definition at line 616 of file qgsproviderregistry.cpp.

◆ fileVectorFilters()

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.

Note

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

Definition at line 611 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 541 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 451 of file qgsproviderregistry.cpp.

◆ instance()

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

Means of accessing canonical single instance.

Definition at line 44 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 280 of file qgsproviderregistry.cpp.

◆ libraryDirectory()

QDir QgsProviderRegistry::libraryDirectory ( ) const

Returns the library directory where plugins are found.

Definition at line 334 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 436 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 496 of file qgsproviderregistry.cpp.

◆ pluginList()

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

Returns list of provider plugins found.

Definition at line 294 of file qgsproviderregistry.cpp.

◆ protocolDrivers()

QString QgsProviderRegistry::protocolDrivers ( ) const
virtual

Returns a string containing the available protocol drivers.

Definition at line 641 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 362 of file qgsproviderregistry.cpp.

◆ providerList()

QStringList QgsProviderRegistry::providerList ( ) const

Returns list of available providers by their keys.

Definition at line 646 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 656 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 418 of file qgsproviderregistry.cpp.

◆ registerGuis()

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

Definition at line 585 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 590 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 480 of file qgsproviderregistry.cpp.

◆ setLibraryDirectory()

void QgsProviderRegistry::setLibraryDirectory ( const QDir &  path)

Sets library directory where to search for plugins.

Definition at line 327 of file qgsproviderregistry.cpp.

Friends And Related Function Documentation

◆ QgsApplication

friend class QgsApplication
friend

Definition at line 423 of file qgsproviderregistry.h.


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