QGIS API Documentation 4.3.0-Master (bf28115e945)
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;
45
60class CORE_EXPORT QgsProviderRegistry
61{
62 public:
63 // TODO QGIS 5 - either move to QgsAbstractDataSourceWidget or remove altogether
64
69 {
70
77
83
90 };
91
93 static QgsProviderRegistry *instance( const QString &pluginPath = QString() );
94
96
105 Q_DECL_DEPRECATED QString library( const QString &providerKey ) const SIP_DEPRECATED;
106
108 QString pluginList( bool asHtml = false ) const;
109
113 QDir libraryDirectory() const;
114
116 void setLibraryDirectory( const QDir &path );
117
118 /*
119 * IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
120 * the case.
121 * Paraphrasing Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
122 *
123 * "
124 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
125 * In this case it isn't because it has already been seen when being returned by by the python function
126 * creating the provider subclass.
127 *
128 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
129 * by Python so the /Factory/ on create() would be correct.)
130 *
131 * You might try using /TransferBack/ on createProvider() instead - that might be the best compromise.
132 * "
133 */
134
145 QgsDataProvider *createProvider(
146 const QString &providerKey,
147 const QString &dataSource,
151
157 Q_DECL_DEPRECATED Qgis::DataItemProviderCapabilities providerCapabilities( const QString &providerKey ) const SIP_DEPRECATED;
158
173 QgsEmptyLayerCreationResult createEmptyLayer(
174 const QString &providerKey,
175 const QString &uri,
176 const QgsFields &fields,
177 Qgis::WkbType wkbType = Qgis::WkbType::NoGeometry,
179 Qgis::CreateLayerActionOnExisting actionOnExisting = Qgis::CreateLayerActionOnExisting::Abort
180 );
181
187 SIP_SKIP Qgis::VectorExportResult createEmptyLayer(
188 const QString &providerKey,
189 const QString &uri,
190 const QgsFields &fields,
191 Qgis::WkbType wkbType,
193 bool overwrite,
194 QMap<int, int> &oldToNewAttrIdxMap,
195 QString &errorMessage,
196 const QMap<QString, QVariant> *options,
197 QString &createdLayerName
198 );
199
200 // TODO QGIS 5.0: rename createOptions to creationOptions for consistency with GDAL
201
208 QgsRasterDataProvider *createRasterDataProvider(
209 const QString &providerKey,
210 const QString &uri,
211 const QString &format,
212 int nBands,
213 Qgis::DataType type,
214 int width,
215 int height,
216 double *geoTransform,
218 const QStringList &createOptions = QStringList()
219 ) SIP_FACTORY;
220
226 QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
227
236 QVariantMap decodeUri( const QString &providerKey, const QString &uri );
237
247 QString encodeUri( const QString &providerKey, const QVariantMap &parts );
248
260 QString absoluteToRelativeUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
261
273 QString relativeToAbsoluteUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
274
281 Q_DECL_DEPRECATED QWidget *createSelectionWidget(
282 const QString &providerKey, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Standalone
284
290 QList< QgsDataItemProvider * > dataItemProviders( const QString &providerKey ) const SIP_FACTORY;
291
297 int listStyles( const QString &providerKey, const QString &uri, QStringList &ids, QStringList &names, QStringList &descriptions, QString &errCause );
298
311 bool styleExists( const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
312
320 QString getStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
321
326 bool deleteStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
327
333 bool saveStyle(
334 const QString &providerKey,
335 const QString &uri,
336 const QString &qmlStyle,
337 const QString &sldStyle,
338 const QString &styleName,
339 const QString &styleDescription,
340 const QString &uiFileContent,
341 bool useAsDefault,
342 QString &errCause
343 );
344
350 QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );
351
361 QString loadStoredStyle( const QString &providerKey, const QString &uri, QString &styleName, QString &errCause );
362
378 bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
379
384 bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
385
390 QgsTransaction *createTransaction( const QString &providerKey, const QString &connString ) SIP_FACTORY;
391
402 Q_DECL_DEPRECATED QFunctionPointer function( const QString &providerKey, const QString &functionName ) const SIP_DEPRECATED;
403
413 Q_DECL_DEPRECATED QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY SIP_DEPRECATED;
414
416 QStringList providerList() const;
417
419 QgsProviderMetadata *providerMetadata( const QString &providerKey ) const;
420
427 QSet< QString > providersForLayerType( Qgis::LayerType type ) const;
428
436 class CORE_EXPORT ProviderCandidateDetails
437 {
438 public:
443 : mMetadata( metadata )
444 , mLayerTypes( layerTypes )
445 {}
446
450 QgsProviderMetadata *metadata() const { return mMetadata; }
451
456 QList<Qgis::LayerType> layerTypes() const { return mLayerTypes; }
457
458#ifdef SIP_RUN
459 // clang-format off
460 SIP_PYOBJECT __repr__();
461 % MethodCode
462 QString str = u"<QgsProviderRegistry.ProviderCandidateDetails: %1>"_s.arg( sipCpp->metadata()->key() );
463 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
464 % End
465// clang-format on
466#endif
467
468 // clang-format off
469 private:
470 // clang-format on
471 QgsProviderMetadata *mMetadata
472 = nullptr;
473
474 QList< Qgis::LayerType > mLayerTypes;
475 };
476
493 QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
494
506 class CORE_EXPORT UnusableUriDetails
507 {
508 public:
515 UnusableUriDetails( const QString &uri = QString(), const QString &warning = QString(), const QList< Qgis::LayerType > &layerTypes = QList< Qgis::LayerType >() )
516 : uri( uri )
517 , warning( warning )
519 {}
520
524 QString uri;
525
529 QString warning;
530
535
540 QList<Qgis::LayerType> layerTypes;
541
542#ifdef SIP_RUN
543 // clang-format off
544 SIP_PYOBJECT __repr__();
545 % MethodCode
546 QString str = u"<QgsProviderRegistry.UnusableUriDetails: %1>"_s.arg( sipCpp->warning );
547 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
548 % End
549// clang-format on
550#endif
551 };
552
566 {
567 public:
568 virtual ~UnusableUriHandlerInterface() = default;
569
573 virtual bool matchesUri( const QString &uri ) const = 0;
574
578 virtual UnusableUriDetails details( const QString &uri ) const = 0;
579 };
580
592
616 bool handleUnusableUri( const QString &uri, UnusableUriDetails &details SIP_OUT ) const;
617
634 bool shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const;
635
649 bool uriIsBlocklisted( const QString &uri ) const;
650
662 QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
663
676 QString fileVectorFilters() const;
677
692 QString fileRasterFilters() const;
693
709 QString fileMeshFilters() const;
710
721 QString fileMeshDatasetFilters() const;
722
737 QString filePointCloudFilters() const;
738
753 QString fileVectorTileFilters() const;
754
769 QString fileTiledSceneFilters() const;
770
772 QString databaseDrivers() const;
774 QString directoryDrivers() const;
776 QString protocolDrivers() const;
777
781 Q_DECL_DEPRECATED void registerGuis( QWidget *widget ) SIP_DEPRECATED;
782
790
792 SIP_SKIP typedef std::map<QString, QgsProviderMetadata *> Providers;
793
794 private:
796 QgsProviderRegistry( const QString &pluginPath );
797
798#ifdef SIP_RUN
799 QgsProviderRegistry( const QString &pluginPath );
800#endif
801
802 void init();
803 void clean();
804
806 Providers mProviders;
807
809 QDir mLibraryDirectory;
810
811 void rebuildFilterStrings();
812
822 QString mVectorFileFilters;
823
827 QString mRasterFileFilters;
828
832 QString mMeshFileFilters;
833
837 QString mMeshDatasetFileFilters;
838
842 QString mPointCloudFileFilters;
843
847 QString mVectorTileFileFilters;
848
852 QString mTiledSceneFileFilters;
853
860 QString mDatabaseDrivers;
861
867 QString mDirectoryDrivers;
868
875 QString mProtocolDrivers;
876
877 QList< UnusableUriHandlerInterface * > mUnusableUriHandlers;
878
882 static bool exists();
883
884 friend class QgsApplication;
885
886}; // class QgsProviderRegistry
887
888#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:1532
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.
Encapsulates the details of a newly created empty layer.
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.