QGIS API Documentation 4.1.0-Master (60fea48833c)
Loading...
Searching...
No Matches
qgsproviderregistry.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsproviderregistry.h - Singleton class for
3 registering data providers.
4 -------------------
5 begin : Sat Jan 10 2004
6 copyright : (C) 2004 by Gary E.Sherman
7 email : sherman at mrcc.com
8 ***************************************************************************/
9
10/***************************************************************************
11 * *
12 * This program is free software; you can redistribute it and/or modify *
13 * it under the terms of the GNU General Public License as published by *
14 * the Free Software Foundation; either version 2 of the License, or *
15 * (at your option) any later version. *
16 * *
17 ***************************************************************************/
18
19#ifndef QGSPROVIDERREGISTRY_H
20#define QGSPROVIDERREGISTRY_H
21
22#include <map>
23
24#include "qgis_core.h"
25#include "qgis_sip.h"
26#include "qgsdataprovider.h"
27
28#include <QDir>
29#include <QLibrary>
30#include <QString>
31
32using namespace Qt::StringLiterals;
33
35class QgsVectorLayer;
38class QgsDataItem;
40class QgsTransaction;
41class QgsFields;
43class QgsFeedback;
44
59class CORE_EXPORT QgsProviderRegistry
60{
61 public:
62 // TODO QGIS 5 - either move to QgsAbstractDataSourceWidget or remove altogether
63
68 {
69
76
82
89 };
90
92 static QgsProviderRegistry *instance( const QString &pluginPath = QString() );
93
95
104 Q_DECL_DEPRECATED QString library( const QString &providerKey ) const SIP_DEPRECATED;
105
107 QString pluginList( bool asHtml = false ) const;
108
112 QDir libraryDirectory() const;
113
115 void setLibraryDirectory( const QDir &path );
116
117 /*
118 * IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
119 * the case.
120 * Paraphrasing Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
121 *
122 * "
123 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
124 * In this case it isn't because it has already been seen when being returned by by the python function
125 * creating the provider subclass.
126 *
127 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
128 * by Python so the /Factory/ on create() would be correct.)
129 *
130 * You might try using /TransferBack/ on createProvider() instead - that might be the best compromise.
131 * "
132 */
133
144 QgsDataProvider *createProvider(
145 const QString &providerKey,
146 const QString &dataSource,
150
156 Q_DECL_DEPRECATED Qgis::DataItemProviderCapabilities providerCapabilities( const QString &providerKey ) const SIP_DEPRECATED;
157
163 SIP_SKIP Qgis::VectorExportResult createEmptyLayer(
164 const QString &providerKey,
165 const QString &uri,
166 const QgsFields &fields,
167 Qgis::WkbType wkbType,
169 bool overwrite,
170 QMap<int, int> &oldToNewAttrIdxMap,
171 QString &errorMessage,
172 const QMap<QString, QVariant> *options,
173 QString &createdLayerName
174 );
175
176 // TODO QGIS 5.0: rename createOptions to creationOptions for consistency with GDAL
177
184 QgsRasterDataProvider *createRasterDataProvider(
185 const QString &providerKey,
186 const QString &uri,
187 const QString &format,
188 int nBands,
189 Qgis::DataType type,
190 int width,
191 int height,
192 double *geoTransform,
194 const QStringList &createOptions = QStringList()
195 ) SIP_FACTORY;
196
202 QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
203
212 QVariantMap decodeUri( const QString &providerKey, const QString &uri );
213
223 QString encodeUri( const QString &providerKey, const QVariantMap &parts );
224
236 QString absoluteToRelativeUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
237
249 QString relativeToAbsoluteUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
250
257 Q_DECL_DEPRECATED QWidget *createSelectionWidget(
258 const QString &providerKey, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Standalone
260
266 QList< QgsDataItemProvider * > dataItemProviders( const QString &providerKey ) const SIP_FACTORY;
267
273 int listStyles( const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause );
274
287 bool styleExists( const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
288
296 QString getStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
297
302 bool deleteStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
303
309 bool saveStyle(
310 const QString &providerKey,
311 const QString &uri,
312 const QString &qmlStyle,
313 const QString &sldStyle,
314 const QString &styleName,
315 const QString &styleDescription,
316 const QString &uiFileContent,
317 bool useAsDefault,
318 QString &errCause
319 );
320
326 QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );
327
337 QString loadStoredStyle( const QString &providerKey, const QString &uri, QString &styleName, QString &errCause );
338
354 bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
355
360 bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
361
366 QgsTransaction *createTransaction( const QString &providerKey, const QString &connString ) SIP_FACTORY;
367
378 Q_DECL_DEPRECATED QFunctionPointer function( const QString &providerKey, const QString &functionName ) const SIP_DEPRECATED;
379
389 Q_DECL_DEPRECATED QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY SIP_DEPRECATED;
390
392 QStringList providerList() const;
393
395 QgsProviderMetadata *providerMetadata( const QString &providerKey ) const;
396
403 QSet< QString > providersForLayerType( Qgis::LayerType type ) const;
404
412 class CORE_EXPORT ProviderCandidateDetails
413 {
414 public:
419 : mMetadata( metadata )
420 , mLayerTypes( layerTypes )
421 {}
422
426 QgsProviderMetadata *metadata() const { return mMetadata; }
427
432 QList<Qgis::LayerType> layerTypes() const { return mLayerTypes; }
433
434#ifdef SIP_RUN
435 // clang-format off
436 SIP_PYOBJECT __repr__();
437 % MethodCode
438 QString str = u"<QgsProviderRegistry.ProviderCandidateDetails: %1>"_s.arg( sipCpp->metadata()->key() );
439 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
440 % End
441// clang-format on
442#endif
443
444 // clang-format off
445 private:
446 // clang-format on
447 QgsProviderMetadata *mMetadata
448 = nullptr;
449
450 QList< Qgis::LayerType > mLayerTypes;
451 };
452
469 QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
470
482 class CORE_EXPORT UnusableUriDetails
483 {
484 public:
491 UnusableUriDetails( const QString &uri = QString(), const QString &warning = QString(), const QList< Qgis::LayerType > &layerTypes = QList< Qgis::LayerType >() )
492 : uri( uri )
493 , warning( warning )
495 {}
496
500 QString uri;
501
505 QString warning;
506
511
516 QList<Qgis::LayerType> layerTypes;
517
518#ifdef SIP_RUN
519 // clang-format off
520 SIP_PYOBJECT __repr__();
521 % MethodCode
522 QString str = u"<QgsProviderRegistry.UnusableUriDetails: %1>"_s.arg( sipCpp->warning );
523 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
524 % End
525// clang-format on
526#endif
527 };
528
542 {
543 public:
544 virtual ~UnusableUriHandlerInterface() = default;
545
549 virtual bool matchesUri( const QString &uri ) const = 0;
550
554 virtual UnusableUriDetails details( const QString &uri ) const = 0;
555 };
556
568
592 bool handleUnusableUri( const QString &uri, UnusableUriDetails &details SIP_OUT ) const;
593
610 bool shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const;
611
625 bool uriIsBlocklisted( const QString &uri ) const;
626
638 QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
639
652 QString fileVectorFilters() const;
653
668 QString fileRasterFilters() const;
669
685 QString fileMeshFilters() const;
686
697 QString fileMeshDatasetFilters() const;
698
713 QString filePointCloudFilters() const;
714
729 QString fileVectorTileFilters() const;
730
745 QString fileTiledSceneFilters() const;
746
748 QString databaseDrivers() const;
750 QString directoryDrivers() const;
752 QString protocolDrivers() const;
753
757 Q_DECL_DEPRECATED void registerGuis( QWidget *widget ) SIP_DEPRECATED;
758
766
768 SIP_SKIP typedef std::map<QString, QgsProviderMetadata *> Providers;
769
770 private:
772 QgsProviderRegistry( const QString &pluginPath );
773
774#ifdef SIP_RUN
775 QgsProviderRegistry( const QString &pluginPath );
776#endif
777
778 void init();
779 void clean();
780
782 Providers mProviders;
783
785 QDir mLibraryDirectory;
786
787 void rebuildFilterStrings();
788
798 QString mVectorFileFilters;
799
803 QString mRasterFileFilters;
804
808 QString mMeshFileFilters;
809
813 QString mMeshDatasetFileFilters;
814
818 QString mPointCloudFileFilters;
819
823 QString mVectorTileFileFilters;
824
828 QString mTiledSceneFileFilters;
829
836 QString mDatabaseDrivers;
837
843 QString mDirectoryDrivers;
844
851 QString mProtocolDrivers;
852
853 QList< UnusableUriHandlerInterface * > mUnusableUriHandlers;
854
858 static bool exists();
859
860 friend class QgsApplication;
861
862}; // class QgsProviderRegistry
863
864#endif //QGSPROVIDERREGISTRY_H
Provides global constants and enumerations for use throughout the application.
Definition qgis.h:62
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:512
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1477
Represents a coordinate reference system (CRS).
Interface for providers that add custom data items to the browser tree.
Base class for all items in the model.
Definition qgsdataitem.h:50
Abstract base class for spatial data provider implementations.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Container of fields for a vector layer.
Definition qgsfields.h:46
A structured metadata store for a map layer.
Custom exception class which is raised when an operation is not supported.
Holds data provider key, description, and associated shared library file or function pointer informat...
QList< Qgis::LayerType > layerTypes() const
Returns a list of map layer types which are valid options for opening the target using this candidate...
QgsProviderMetadata * metadata() const
Returns the candidate provider metadata.
ProviderCandidateDetails(QgsProviderMetadata *metadata, const QList< Qgis::LayerType > &layerTypes)
Constructor for ProviderCandidateDetails, with the specified provider metadata and valid candidate la...
Contains information about unusable URIs which aren't handled by any registered providers.
QString warning
Contains a short, user-friendly, translated message advising why the URI is not usable.
QString uri
URI which could not be handled.
QString detailedWarning
Contains a longer, user-friendly, translated message advising why the URI is not usable.
UnusableUriDetails(const QString &uri=QString(), const QString &warning=QString(), const QList< Qgis::LayerType > &layerTypes=QList< Qgis::LayerType >())
Constructor for UnusableUriDetails for the given uri, with the specified user-friendly,...
QList< Qgis::LayerType > layerTypes
Contains a list of map layer types which are usually valid options for opening the target URI.
An interface used to handle unusable URIs which aren't handled by any registered providers,...
virtual UnusableUriDetails details(const QString &uri) const =0
Returns the details for advising the user why the uri is not usable.
virtual bool matchesUri(const QString &uri) const =0
Returns true if the handle is an unusable URI handler for the specified uri.
A registry / canonical manager of data providers.
std::map< QString, QgsProviderMetadata * > Providers
Type for data provider metadata associative container.
QString fileVectorTileFilters() const
Returns a file filter string for supported vector tile files.
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...
Q_DECL_DEPRECATED void registerGuis(QWidget *widget)
WidgetMode
Different ways a source select dialog can be used.
@ Standalone
Basic mode when the widget is used as a standalone dialog.
@ Embedded
Used for the data source manager dialog where the widget is embedded as the main content for a partic...
@ Manager
Used by data items for QgsDataItem::paramWidget().
QString protocolDrivers() const
Returns a string containing the available protocol drivers.
QString fileTiledSceneFilters() const
Returns a file filter string for supported tiled scene files.
QString databaseDrivers() const
Returns a string containing the available database drivers.
bool uriIsBlocklisted(const QString &uri) const
Returns true if the specified uri is known by any registered provider to be something which should be...
bool handleUnusableUri(const QString &uri, UnusableUriDetails &details) const
Returns true if the specified uri can potentially be handled by QGIS, if additional dependencies or b...
QString fileVectorFilters() const
Returns a file filter string for supported vector files.
QString fileRasterFilters() const
Returns a file filter string for supported raster files.
QString fileMeshFilters() const
Returns a file filter string for supported mesh files.
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 ...
QString fileMeshDatasetFilters() const
Returns a file filter string for supported mesh dataset files.
QgsProviderMetadata * providerMetadata(const QString &providerKey) const
Returns metadata of the provider or nullptr if not found.
bool registerProvider(QgsProviderMetadata *providerMetadata)
register a new vector data provider from its providerMetadata
QString directoryDrivers() const
Returns a string containing the available directory drivers.
bool registerUnusableUriHandler(UnusableUriHandlerInterface *handler)
Registers an unusable URI handler, used to handle unusable URIs which aren't handled by any registere...
QString filePointCloudFilters() const
Returns a file filter string for supported point clouds.
Contains details about a sub layer available from a dataset.
Base class for raster data providers.
A container for the context for various read/write operations on objects.
Allows creation of a multi-layer database-side transaction.
Represents a vector layer which manages a vector based dataset.
#define SIP_DEPRECATED
Definition qgis_sip.h:113
#define SIP_SKIP
Definition qgis_sip.h:133
#define SIP_TRANSFER
Definition qgis_sip.h:35
#define SIP_OUT
Definition qgis_sip.h:57
#define SIP_TRANSFERBACK
Definition qgis_sip.h:47
#define SIP_FACTORY
Definition qgis_sip.h:83
#define SIP_THROW(name,...)
Definition qgis_sip.h:210
Setting options for creating vector data providers.