QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
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 <QDir>
25#include <QLibrary>
26#include <QString>
27
28#include "qgsdataprovider.h"
29#include "qgis_core.h"
30#include "qgis_sip.h"
31
32#include <vector>
33#include <memory>
34
36class QgsVectorLayer;
39class QgsDataItem;
41class QgsTransaction;
42class QgsFields;
44class QgsFeedback;
45
60class CORE_EXPORT QgsProviderRegistry
61{
62
63 public:
64
65 // TODO QGIS 4 - either move to QgsAbstractDataSourceWidget or remove altogether
66
71 {
72
79
85
92 };
93
95 static QgsProviderRegistry *instance( const QString &pluginPath = QString() );
96
98
107 Q_DECL_DEPRECATED QString library( const QString &providerKey ) const SIP_DEPRECATED;
108
110 QString pluginList( bool asHtml = false ) const;
111
115 QDir libraryDirectory() const;
116
118 void setLibraryDirectory( const QDir &path );
119
120 /*
121 * IMPORTANT: While it seems like /Factory/ would be the correct annotation here, that's not
122 * the case.
123 * Paraphrasing Phil Thomson's advice on https://www.riverbankcomputing.com/pipermail/pyqt/2017-July/039450.html:
124 *
125 * "
126 * /Factory/ is used when the instance returned is guaranteed to be new to Python.
127 * In this case it isn't because it has already been seen when being returned by by the python function
128 * creating the provider subclass.
129 *
130 * (However for a different sub-class implemented in C++ then it would be the first time it was seen
131 * by Python so the /Factory/ on create() would be correct.)
132 *
133 * You might try using /TransferBack/ on createProvider() instead - that might be the best compromise.
134 * "
135 */
136
147 QgsDataProvider *createProvider( const QString &providerKey,
148 const QString &dataSource,
151
157 Q_DECL_DEPRECATED Qgis::DataItemProviderCapabilities providerCapabilities( const QString &providerKey ) const SIP_DEPRECATED;
158
164 SIP_SKIP Qgis::VectorExportResult createEmptyLayer( const QString &providerKey, const QString &uri, const QgsFields &fields, Qgis::WkbType wkbType, const QgsCoordinateReferenceSystem &srs, bool overwrite, QMap<int, int> &oldToNewAttrIdxMap, QString &errorMessage, const QMap<QString, QVariant> *options );
165
172 QgsRasterDataProvider *createRasterDataProvider(
173 const QString &providerKey,
174 const QString &uri,
175 const QString &format,
176 int nBands,
177 Qgis::DataType type,
178 int width, int height,
179 double *geoTransform,
181 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
182
188 QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
189
198 QVariantMap decodeUri( const QString &providerKey, const QString &uri );
199
209 QString encodeUri( const QString &providerKey, const QVariantMap &parts );
210
222 QString absoluteToRelativeUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
223
235 QString relativeToAbsoluteUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
236
243 Q_DECL_DEPRECATED QWidget *createSelectionWidget( const QString &providerKey, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::None ) SIP_DEPRECATED;
244
250 QList< QgsDataItemProvider * > dataItemProviders( const QString &providerKey ) const SIP_FACTORY;
251
257 int listStyles( const QString &providerKey,
258 const QString &uri,
259 QStringList &ids,
260 QStringList &names,
261 QStringList &descriptions,
262 QString &errCause );
263
276 bool styleExists( const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
277
285 QString getStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
286
291 bool deleteStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
292
298 bool saveStyle( const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle,
299 const QString &styleName, const QString &styleDescription,
300 const QString &uiFileContent, bool useAsDefault, QString &errCause );
301
307 QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );
308
318 QString loadStoredStyle( const QString &providerKey, const QString &uri, QString &styleName, QString &errCause );
319
335 bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
336
341 bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
342
347 QgsTransaction *createTransaction( const QString &providerKey, const QString &connString ) SIP_FACTORY;
348
359 Q_DECL_DEPRECATED QFunctionPointer function( const QString &providerKey, const QString &functionName ) const SIP_DEPRECATED;
360
370 Q_DECL_DEPRECATED QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY SIP_DEPRECATED;
371
373 QStringList providerList() const;
374
376 QgsProviderMetadata *providerMetadata( const QString &providerKey ) const;
377
384 QSet< QString > providersForLayerType( Qgis::LayerType type ) const;
385
393 class CORE_EXPORT ProviderCandidateDetails
394 {
395
396 public:
397
401 ProviderCandidateDetails( QgsProviderMetadata *metadata, const QList< Qgis::LayerType > &layerTypes )
402 : mMetadata( metadata )
403 , mLayerTypes( layerTypes )
404 {}
405
409 QgsProviderMetadata *metadata() const { return mMetadata; }
410
415 QList<Qgis::LayerType> layerTypes() const { return mLayerTypes; }
416
417#ifdef SIP_RUN
418 SIP_PYOBJECT __repr__();
419 % MethodCode
420 QString str = QStringLiteral( "<QgsProviderRegistry.ProviderCandidateDetails: %1>" ).arg( sipCpp->metadata()->key() );
421 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
422 % End
423#endif
424
425 private:
426 QgsProviderMetadata *mMetadata = nullptr;
427
428 QList< Qgis::LayerType > mLayerTypes;
429
430 };
431
448 QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
449
461 class CORE_EXPORT UnusableUriDetails
462 {
463 public:
464
471 UnusableUriDetails( const QString &uri = QString(), const QString &warning = QString(), const QList< Qgis::LayerType > &layerTypes = QList< Qgis::LayerType >() )
472 : uri( uri )
473 , warning( warning )
474 , layerTypes( layerTypes )
475 {}
476
480 QString uri;
481
485 QString warning;
486
491
496 QList<Qgis::LayerType> layerTypes;
497
498#ifdef SIP_RUN
499 SIP_PYOBJECT __repr__();
500 % MethodCode
501 QString str = QStringLiteral( "<QgsProviderRegistry.UnusableUriDetails: %1>" ).arg( sipCpp->warning );
502 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
503 % End
504#endif
505
506 };
507
521 {
522
523 public:
524
525 virtual ~UnusableUriHandlerInterface() = default;
526
530 virtual bool matchesUri( const QString &uri ) const = 0;
531
535 virtual UnusableUriDetails details( const QString &uri ) const = 0;
536
537 };
538
549 bool registerUnusableUriHandler( UnusableUriHandlerInterface *handler SIP_TRANSFER );
550
574 bool handleUnusableUri( const QString &uri, UnusableUriDetails &details SIP_OUT ) const;
575
592 bool shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const;
593
607 bool uriIsBlocklisted( const QString &uri ) const;
608
620 QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
621
634 QString fileVectorFilters() const;
635
650 QString fileRasterFilters() const;
651
667 QString fileMeshFilters() const;
668
679 QString fileMeshDatasetFilters() const;
680
695 QString filePointCloudFilters() const;
696
711 QString fileVectorTileFilters() const;
712
727 QString fileTiledSceneFilters() const;
728
730 QString databaseDrivers() const;
732 QString directoryDrivers() const;
734 QString protocolDrivers() const;
735
739 Q_DECL_DEPRECATED void registerGuis( QWidget *widget ) SIP_DEPRECATED;
740
747 bool registerProvider( QgsProviderMetadata *providerMetadata SIP_TRANSFER );
748
750 SIP_SKIP typedef std::map<QString, QgsProviderMetadata *> Providers;
751
752 private:
754 QgsProviderRegistry( const QString &pluginPath );
755
756#ifdef SIP_RUN
757 QgsProviderRegistry( const QString &pluginPath );
758#endif
759
760 void init();
761 void clean();
762
764 Providers mProviders;
765
767 QDir mLibraryDirectory;
768
769 void rebuildFilterStrings();
770
780 QString mVectorFileFilters;
781
785 QString mRasterFileFilters;
786
790 QString mMeshFileFilters;
791
795 QString mMeshDatasetFileFilters;
796
800 QString mPointCloudFileFilters;
801
805 QString mVectorTileFileFilters;
806
810 QString mTiledSceneFileFilters;
811
818 QString mDatabaseDrivers;
819
825 QString mDirectoryDrivers;
826
833 QString mProtocolDrivers;
834
835 QList< UnusableUriHandlerInterface * > mUnusableUriHandlers;
836
840 static bool exists();
841
842 friend class QgsApplication;
843
844}; // class QgsProviderRegistry
845
846#endif //QGSPROVIDERREGISTRY_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:54
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition: qgis.h:1097
Extends QApplication to provide access to QGIS specific resources such as theme paths,...
This class represents a coordinate reference system (CRS).
This is the interface for those who want to add custom data items to the browser tree.
Base class for all items in the model.
Definition: qgsdataitem.h:46
Abstract base class for spatial data provider implementations.
QFlags< ReadFlag > ReadFlags
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:45
A structured metadata store for a map layer.
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:118
Holds data provider key, description, and associated shared library file or function pointer informat...
Contains information pertaining to a candidate provider.
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.
WidgetMode
Different ways a source select dialog can be used.
@ Embedded
Used for the data source manager dialog where the widget is embedded as the main content for a partic...
@ None
Basic mode when the widget is used as a standalone dialog.
@ Manager
Used by data items for QgsDataItem::paramWidget().
Contains details about a sub layer available from a dataset.
Base class for raster data providers.
The class is used as a container of context for various read/write operations on other objects.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Represents a vector layer which manages a vector based data sets.
#define str(x)
Definition: qgis.cpp:38
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_TRANSFER
Definition: qgis_sip.h:36
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_TRANSFERBACK
Definition: qgis_sip.h:48
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_THROW(name,...)
Definition: qgis_sip.h:203
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.