QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
|
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, const 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) const |
Gets pointer to provider function. More... | |
QString | getStyleById (const QString &providerKey, const QString &uri, const 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... | |
QSet< QString > | providersForLayerType (QgsMapLayerType type) const |
Returns a list of the provider keys for available providers which handle the specified layer type. More... | |
QList< QPair< QString, QString > > | pyramidResamplingMethods (const QString &providerKey) |
Returns list of raster pyramid resampling methods. More... | |
QList< QgsProviderSublayerDetails > | querySublayers (const QString &uri, Qgis::SublayerQueryFlags flags=Qgis::SublayerQueryFlags(), QgsFeedback *feedback=nullptr) const |
Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be handled by any registered data provider. 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 | styleExists (const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause) |
Returns true if a layer style with the specified styleId exists in the provider defined by providerKey and uri. 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 60 of file qgsproviderregistry.h.
typedef std::map<QString, QgsProviderMetadata *> QgsProviderRegistry::Providers |
Type for data provider metadata associative container.
Definition at line 673 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 70 of file qgsproviderregistry.h.
QgsProviderRegistry::~QgsProviderRegistry | ( | ) |
Definition at line 450 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 721 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 573 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 526 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 777 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 592 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 742 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 733 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::databaseDrivers | ( | ) | const |
Returns a string containing the available database drivers.
Definition at line 848 of file qgsproviderregistry.cpp.
QList< QgsDataItemProvider * > QgsProviderRegistry::dataItemProviders | ( | const QString & | providerKey | ) | const |
Returns list of data item providers of the provider.
Definition at line 613 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 555 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::deleteStyleById | ( | const QString & | providerKey, |
const QString & | uri, | ||
const QString & | styleId, | ||
QString & | errCause | ||
) |
Deletes a layer style defined by styleId.
Definition at line 667 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::directoryDrivers | ( | ) | const |
Returns a string containing the available directory drivers.
Definition at line 853 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 564 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 838 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 833 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 843 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 828 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 823 of file qgsproviderregistry.cpp.
QFunctionPointer QgsProviderRegistry::function | ( | const QString & | providerKey, |
const QString & | functionName | ||
) | const |
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 753 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::getStyleById | ( | const QString & | providerKey, |
const QString & | uri, | ||
const QString & | styleId, | ||
QString & | errCause | ||
) |
Gets a layer style defined by styleId.
Definition at line 652 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 921 of file qgsproviderregistry.cpp.
|
static |
Means of accessing canonical single instance.
Definition at line 73 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 459 of file qgsproviderregistry.cpp.
QDir QgsProviderRegistry::libraryDirectory | ( | ) | const |
Returns the library directory where plugins are found.
Definition at line 513 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 622 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 697 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::pluginList | ( | bool | asHtml = false | ) | const |
Returns list of provider plugins found.
Definition at line 473 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 889 of file qgsproviderregistry.cpp.
QString QgsProviderRegistry::protocolDrivers | ( | ) | const |
Returns a string containing the available protocol drivers.
Definition at line 858 of file qgsproviderregistry.cpp.
int QgsProviderRegistry::providerCapabilities | ( | const QString & | providerKey | ) | const |
Returns the provider capabilities.
providerKey | identifier of the provider |
Definition at line 543 of file qgsproviderregistry.cpp.
QStringList QgsProviderRegistry::providerList | ( | ) | const |
Returns list of available providers by their keys.
Definition at line 863 of file qgsproviderregistry.cpp.
QgsProviderMetadata * QgsProviderRegistry::providerMetadata | ( | const QString & | providerKey | ) | const |
Returns metadata of the provider or nullptr
if not found.
Definition at line 873 of file qgsproviderregistry.cpp.
QSet< QString > QgsProviderRegistry::providersForLayerType | ( | QgsMapLayerType | type | ) | const |
Returns a list of the provider keys for available providers which handle the specified layer type.
Definition at line 878 of file qgsproviderregistry.cpp.
QList< QPair< QString, QString > > QgsProviderRegistry::pyramidResamplingMethods | ( | const QString & | providerKey | ) |
Returns list of raster pyramid resampling methods.
Definition at line 604 of file qgsproviderregistry.cpp.
QList< QgsProviderSublayerDetails > QgsProviderRegistry::querySublayers | ( | const QString & | uri, |
Qgis::SublayerQueryFlags | flags = Qgis::SublayerQueryFlags() , |
||
QgsFeedback * | feedback = nullptr |
||
) | const |
Queries the specified uri and returns a list of any valid sublayers found in the dataset which can be handled by any registered data provider.
This method iteratively queries each registered data provider and returns the complete collated list of all valid sublayers found in the dataset which can be opened by the data providers.
The optional flags argument can be used to control the behavior of the query.
The optional feedback argument can be used to provide cancellation support for long-running queries.
Definition at line 958 of file qgsproviderregistry.cpp.
void QgsProviderRegistry::registerGuis | ( | QWidget * | widget | ) |
Definition at line 797 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 802 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 915 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 710 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 681 of file qgsproviderregistry.cpp.
void QgsProviderRegistry::setLibraryDirectory | ( | const QDir & | path | ) |
Sets library directory where to search for plugins.
Definition at line 506 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 934 of file qgsproviderregistry.cpp.
bool QgsProviderRegistry::styleExists | ( | const QString & | providerKey, |
const QString & | uri, | ||
const QString & | styleId, | ||
QString & | errorCause | ||
) |
Returns true
if a layer style with the specified styleId exists in the provider defined by providerKey and uri.
providerKey | provider key |
uri | provider URI |
styleId | style ID to test for |
errorCause | will be set to a descriptive error message, if an error occurs while checking if the style exists |
true
if the layer style already existsDefinition at line 637 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 948 of file qgsproviderregistry.cpp.
|
friend |
Definition at line 753 of file qgsproviderregistry.h.