QGIS API Documentation
3.20.0-Odense (decaadbb31)
|
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... | |
Qgis::VectorExportResult | 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... | |
QgsDataProvider * | 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. More... | |
Q_DECL_DEPRECATED QLibrary * | createProviderLibrary (const QString &providerKey) const |
Returns a new QLibrary for the specified providerKey. More... | |
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. 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... | |
QgsTransaction * | createTransaction (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::ProviderCandidateDetails > | preferredProvidersForUri (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... | |
QgsProviderMetadata * | providerMetadata (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 | saveLayerMetadata (const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage) SIP_THROW(QgsNotSupportedException) |
Saves metadata to the layer corresponding to the specified uri. 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 QgsProviderRegistry * | instance (const QString &pluginPath=QString()) |
Means of accessing canonical single instance. More... | |
Friends | |
class | QgsApplication |
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 58 of file qgsproviderregistry.h.
typedef std::map<QString, QgsProviderMetadata *> QgsProviderRegistry::Providers |
Type for data provider metadata associative container.
Definition at line 634 of file qgsproviderregistry.h.
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 68 of file qgsproviderregistry.h.
QgsProviderRegistry::~QgsProviderRegistry | ( | ) |
Definition at line 415 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::createDb | ( | const QString & | providerKey, |
const QString & | dbPath, | ||
QString & | errCause | ||
) |
Creates database by the provider on the path.
Definition at line 671 of file qgsproviderregistry.cpp.
Qgis::VectorExportResult 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.
Definition at line 538 of file qgsproviderregistry.cpp.
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.
providerKey | identifier of the provider |
dataSource | string containing data source for the provider |
options | provider options |
flags | provider flags since QGIS 3.16 |
nullptr
on errorDefinition at line 491 of file qgsproviderregistry.cpp.
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.
Definition at line 727 of file qgsproviderregistry.cpp.
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.
Definition at line 557 of file qgsproviderregistry.cpp.
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.
Definition at line 692 of file qgsproviderregistry.cpp.
QgsTransaction * QgsProviderRegistry::createTransaction | ( | const QString & | providerKey, |
const QString & | connString | ||
) |
Returns new instance of transaction.
Ownership is transferred to the caller
Definition at line 683 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::databaseDrivers | ( | ) | const |
Returns a string containing the available database drivers.
Definition at line 798 of file qgsproviderregistry.cpp.
QList< QgsDataItemProvider * > QgsProviderRegistry::dataItemProviders | ( | const QString & | providerKey | ) | const |
Returns list of data item providers of the provider.
Definition at line 578 of file qgsproviderregistry.cpp.
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).
providerKey | identifier of the provider |
uri | uri string |
Definition at line 520 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::deleteStyleById | ( | const QString & | providerKey, |
const QString & | uri, | ||
QString | styleId, | ||
QString & | errCause | ||
) |
Deletes a layer style defined by styleId.
Definition at line 617 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::directoryDrivers | ( | ) | const |
Returns a string containing the available directory drivers.
Definition at line 803 of file qgsproviderregistry.cpp.
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).
providerKey | identifier of the provider |
parts | parts as returned by decodeUri |
Definition at line 529 of file qgsproviderregistry.cpp.
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.
Definition at line 788 of file qgsproviderregistry.cpp.
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.
Definition at line 783 of file qgsproviderregistry.cpp.
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.
Definition at line 793 of file qgsproviderregistry.cpp.
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.
Definition at line 778 of file qgsproviderregistry.cpp.
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.
Definition at line 773 of file qgsproviderregistry.cpp.
QFunctionPointer QgsProviderRegistry::function | ( | const QString & | providerKey, |
const QString & | functionName | ||
) |
Gets pointer to provider function.
providerKey | identifier of the provider |
functionName | name of function |
nullptr
on error. If the provider uses direct provider function pointers instead of a library nullptr
will be returned.Definition at line 703 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::getStyleById | ( | const QString & | providerKey, |
const QString & | uri, | ||
QString | styleId, | ||
QString & | errCause | ||
) |
Gets a layer style defined by styleId.
Definition at line 602 of file qgsproviderregistry.cpp.
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.
uri | URI to test |
details | will be populated with details allowing construction of a user-friendly warning message |
true
if the uri was matched to a registered QgsProviderRegistry::UnusableUriHandlerInterface.Definition at line 860 of file qgsproviderregistry.cpp.
|
static |
Means of accessing canonical single instance.
Definition at line 54 of file qgsproviderregistry.cpp.
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.
Definition at line 424 of file qgsproviderregistry.cpp.
QDir QgsProviderRegistry::libraryDirectory | ( | ) | const |
Returns the library directory where plugins are found.
Definition at line 478 of file qgsproviderregistry.cpp.
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.
Definition at line 587 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::loadStyle | ( | const QString & | providerKey, |
const QString & | uri, | ||
QString & | errCause | ||
) |
Loads a layer style defined by uri.
Definition at line 647 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::pluginList | ( | bool | asHtml = false | ) | const |
Returns list of provider plugins found.
Definition at line 438 of file qgsproviderregistry.cpp.
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.
Definition at line 828 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::protocolDrivers | ( | ) | const |
Returns a string containing the available protocol drivers.
Definition at line 808 of file qgsproviderregistry.cpp.
int QgsProviderRegistry::providerCapabilities | ( | const QString & | providerKey | ) | const |
Returns the provider capabilities.
providerKey | identifier of the provider |
Definition at line 508 of file qgsproviderregistry.cpp.
QStringList QgsProviderRegistry::providerList | ( | ) | const |
Returns list of available providers by their keys.
Definition at line 813 of file qgsproviderregistry.cpp.
QgsProviderMetadata * QgsProviderRegistry::providerMetadata | ( | const QString & | providerKey | ) | const |
Returns metadata of the provider or nullptr
if not found.
Definition at line 823 of file qgsproviderregistry.cpp.
QList< QPair< QString, QString > > QgsProviderRegistry::pyramidResamplingMethods | ( | const QString & | providerKey | ) |
Returns list of raster pyramid resampling methods.
Definition at line 569 of file qgsproviderregistry.cpp.
void QgsProviderRegistry::registerGuis | ( | QWidget * | widget | ) |
Definition at line 747 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::registerProvider | ( | QgsProviderMetadata * | providerMetadata | ) |
register a new vector data provider from its providerMetadata
true
on success, false
if a provider with the same key was already registered Definition at line 752 of file qgsproviderregistry.cpp.
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.
true
on successDefinition at line 854 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::saveLayerMetadata | ( | const QString & | providerKey, |
const QString & | uri, | ||
const QgsLayerMetadata & | metadata, | ||
QString & | errorMessage | ||
) |
Saves metadata to the layer corresponding to the specified uri.
providerKey | identifier of the provider |
uri | uri of layer to store metadata for |
metadata | layer metadata |
errorMessage | descriptive string of error if encountered |
true
if the metadata was successfully saved.QgsNotSupportedException | if the provider does not support saving layer metadata for the specified uri. |
Definition at line 660 of file qgsproviderregistry.cpp.
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.
Definition at line 631 of file qgsproviderregistry.cpp.
void QgsProviderRegistry::setLibraryDirectory | ( | const QDir & | path | ) |
Sets library directory where to search for plugins.
Definition at line 471 of file qgsproviderregistry.cpp.
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.
Definition at line 873 of file qgsproviderregistry.cpp.
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.
Definition at line 887 of file qgsproviderregistry.cpp.
|
friend |
Definition at line 714 of file qgsproviderregistry.h.