QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 <QDir>
25#include <QLibrary>
26#include <QString>
27
28#include "qgsdataprovider.h"
29#include "qgis_core.h"
30#include "qgis_sip.h"
31
33class QgsVectorLayer;
36class QgsDataItem;
38class QgsTransaction;
39class QgsFields;
41class QgsFeedback;
42
57class CORE_EXPORT QgsProviderRegistry
58{
59
60 public:
61
62 // TODO QGIS 4 - 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( const QString &providerKey,
145 const QString &dataSource,
148
154 Q_DECL_DEPRECATED Qgis::DataItemProviderCapabilities providerCapabilities( const QString &providerKey ) const SIP_DEPRECATED;
155
161 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 );
162
169 QgsRasterDataProvider *createRasterDataProvider(
170 const QString &providerKey,
171 const QString &uri,
172 const QString &format,
173 int nBands,
174 Qgis::DataType type,
175 int width, int height,
176 double *geoTransform,
178 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
179
185 QList<QPair<QString, QString> > pyramidResamplingMethods( const QString &providerKey );
186
195 QVariantMap decodeUri( const QString &providerKey, const QString &uri );
196
206 QString encodeUri( const QString &providerKey, const QVariantMap &parts );
207
219 QString absoluteToRelativeUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
220
232 QString relativeToAbsoluteUri( const QString &providerKey, const QString &uri, const QgsReadWriteContext &context ) const;
233
240 Q_DECL_DEPRECATED QWidget *createSelectionWidget( const QString &providerKey, QWidget *parent = nullptr, Qt::WindowFlags fl = Qt::WindowFlags(), QgsProviderRegistry::WidgetMode widgetMode = QgsProviderRegistry::WidgetMode::Standalone ) SIP_DEPRECATED;
241
247 QList< QgsDataItemProvider * > dataItemProviders( const QString &providerKey ) const SIP_FACTORY;
248
254 int listStyles( const QString &providerKey,
255 const QString &uri,
256 QStringList &ids,
257 QStringList &names,
258 QStringList &descriptions,
259 QString &errCause );
260
273 bool styleExists( const QString &providerKey, const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
274
282 QString getStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
283
288 bool deleteStyleById( const QString &providerKey, const QString &uri, const QString &styleId, QString &errCause );
289
295 bool saveStyle( const QString &providerKey, const QString &uri, const QString &qmlStyle, const QString &sldStyle,
296 const QString &styleName, const QString &styleDescription,
297 const QString &uiFileContent, bool useAsDefault, QString &errCause );
298
304 QString loadStyle( const QString &providerKey, const QString &uri, QString &errCause );
305
315 QString loadStoredStyle( const QString &providerKey, const QString &uri, QString &styleName, QString &errCause );
316
332 bool saveLayerMetadata( const QString &providerKey, const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
333
338 bool createDb( const QString &providerKey, const QString &dbPath, QString &errCause );
339
344 QgsTransaction *createTransaction( const QString &providerKey, const QString &connString ) SIP_FACTORY;
345
356 Q_DECL_DEPRECATED QFunctionPointer function( const QString &providerKey, const QString &functionName ) const SIP_DEPRECATED;
357
367 Q_DECL_DEPRECATED QLibrary *createProviderLibrary( const QString &providerKey ) const SIP_FACTORY SIP_DEPRECATED;
368
370 QStringList providerList() const;
371
373 QgsProviderMetadata *providerMetadata( const QString &providerKey ) const;
374
381 QSet< QString > providersForLayerType( Qgis::LayerType type ) const;
382
390 class CORE_EXPORT ProviderCandidateDetails
391 {
392
393 public:
394
398 ProviderCandidateDetails( QgsProviderMetadata *metadata, const QList< Qgis::LayerType > &layerTypes )
399 : mMetadata( metadata )
400 , mLayerTypes( layerTypes )
401 {}
402
406 QgsProviderMetadata *metadata() const { return mMetadata; }
407
412 QList<Qgis::LayerType> layerTypes() const { return mLayerTypes; }
413
414#ifdef SIP_RUN
415 SIP_PYOBJECT __repr__();
416 % MethodCode
417 QString str = QStringLiteral( "<QgsProviderRegistry.ProviderCandidateDetails: %1>" ).arg( sipCpp->metadata()->key() );
418 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
419 % End
420#endif
421
422 private:
423 QgsProviderMetadata *mMetadata = nullptr;
424
425 QList< Qgis::LayerType > mLayerTypes;
426
427 };
428
445 QList< QgsProviderRegistry::ProviderCandidateDetails > preferredProvidersForUri( const QString &uri ) const;
446
458 class CORE_EXPORT UnusableUriDetails
459 {
460 public:
461
468 UnusableUriDetails( const QString &uri = QString(), const QString &warning = QString(), const QList< Qgis::LayerType > &layerTypes = QList< Qgis::LayerType >() )
469 : uri( uri )
470 , warning( warning )
471 , layerTypes( layerTypes )
472 {}
473
477 QString uri;
478
482 QString warning;
483
488
493 QList<Qgis::LayerType> layerTypes;
494
495#ifdef SIP_RUN
496 SIP_PYOBJECT __repr__();
497 % MethodCode
498 QString str = QStringLiteral( "<QgsProviderRegistry.UnusableUriDetails: %1>" ).arg( sipCpp->warning );
499 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
500 % End
501#endif
502
503 };
504
518 {
519
520 public:
521
522 virtual ~UnusableUriHandlerInterface() = default;
523
527 virtual bool matchesUri( const QString &uri ) const = 0;
528
532 virtual UnusableUriDetails details( const QString &uri ) const = 0;
533
534 };
535
546 bool registerUnusableUriHandler( UnusableUriHandlerInterface *handler SIP_TRANSFER );
547
571 bool handleUnusableUri( const QString &uri, UnusableUriDetails &details SIP_OUT ) const;
572
589 bool shouldDeferUriForOtherProviders( const QString &uri, const QString &providerKey ) const;
590
604 bool uriIsBlocklisted( const QString &uri ) const;
605
617 QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
618
631 QString fileVectorFilters() const;
632
647 QString fileRasterFilters() const;
648
664 QString fileMeshFilters() const;
665
676 QString fileMeshDatasetFilters() const;
677
692 QString filePointCloudFilters() const;
693
708 QString fileVectorTileFilters() const;
709
724 QString fileTiledSceneFilters() const;
725
727 QString databaseDrivers() const;
729 QString directoryDrivers() const;
731 QString protocolDrivers() const;
732
736 Q_DECL_DEPRECATED void registerGuis( QWidget *widget ) SIP_DEPRECATED;
737
744 bool registerProvider( QgsProviderMetadata *providerMetadata SIP_TRANSFER );
745
747 SIP_SKIP typedef std::map<QString, QgsProviderMetadata *> Providers;
748
749 private:
751 QgsProviderRegistry( const QString &pluginPath );
752
753#ifdef SIP_RUN
754 QgsProviderRegistry( const QString &pluginPath );
755#endif
756
757 void init();
758 void clean();
759
761 Providers mProviders;
762
764 QDir mLibraryDirectory;
765
766 void rebuildFilterStrings();
767
777 QString mVectorFileFilters;
778
782 QString mRasterFileFilters;
783
787 QString mMeshFileFilters;
788
792 QString mMeshDatasetFileFilters;
793
797 QString mPointCloudFileFilters;
798
802 QString mVectorTileFileFilters;
803
807 QString mTiledSceneFileFilters;
808
815 QString mDatabaseDrivers;
816
822 QString mDirectoryDrivers;
823
830 QString mProtocolDrivers;
831
832 QList< UnusableUriHandlerInterface * > mUnusableUriHandlers;
833
837 static bool exists();
838
839 friend class QgsApplication;
840
841}; // class QgsProviderRegistry
842
843#endif //QGSPROVIDERREGISTRY_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
QFlags< DataProviderReadFlag > DataProviderReadFlags
Flags which control data provider construction.
Definition qgis.h:450
QFlags< SublayerQueryFlag > SublayerQueryFlags
Sublayer query flags.
Definition qgis.h:1309
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.
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...
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.
@ 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().
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 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.