QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsprovidermetadata.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsprovidermetadata.h - Metadata class for
3 describing a data provider.
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 QGSPROVIDERMETADATA_H
20#define QGSPROVIDERMETADATA_H
21
22
23#include <QString>
24#include <QVariantMap>
25#include <QMap>
26#include <QList>
27#include <memory>
28#include <QPair>
29
30#include "qgis_sip.h"
31#include "qgsdataprovider.h"
32#include "qgis_core.h"
33#include <functional>
36#include "qgsfields.h"
37#include "qgsexception.h"
38
39class QgsDataItem;
41class QgsTransaction;
42
48class QgsFeedback;
49
50struct QgsMesh;
51
58class CORE_EXPORT QgsMeshDriverMetadata
59{
60 Q_GADGET
61
62 public:
63
68 {
69 CanWriteFaceDatasets = 1 << 0,
70 CanWriteVertexDatasets = 1 << 1,
71 CanWriteEdgeDatasets = 1 << 2,
72 CanWriteMeshData = 1 << 3,
73 };
74
75 Q_ENUM( MeshDriverCapability )
76 Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
77 Q_FLAG( MeshDriverCapabilities )
78
79
81
92 Q_DECL_DEPRECATED QgsMeshDriverMetadata( const QString &name,
93 const QString &description,
94 const MeshDriverCapabilities &capabilities,
95 const QString &writeDatasetOnFileSuffix ) SIP_DEPRECATED;
96
109 QgsMeshDriverMetadata( const QString &name,
110 const QString &description,
111 const MeshDriverCapabilities &capabilities,
112 const QString &writeDatasetOnFileSuffix,
113 const QString &writeMeshFrameOnFileSuffix,
114 int maxVerticesPerface );
115
119 MeshDriverCapabilities capabilities() const;
120
124 QString name() const;
125
129 QString description() const;
130
134 QString writeDatasetOnFileSuffix() const;
135
141 QString writeMeshFrameOnFileSuffix() const;
142
148 int maximumVerticesCountPerFace() const;
149
150 private:
151 QString mName;
152 QString mDescription;
153 MeshDriverCapabilities mCapabilities;
154 QString mWriteDatasetOnFileSuffix;
155 QString mWriteMeshFrameOnFileSuffix;
156 int mMaxVerticesPerFace = -1;
157};
158
160
178class CORE_EXPORT QgsProviderMetadata : public QObject
179{
180 Q_OBJECT
181
182 public:
183
190 {
191 PriorityForUri = 1 << 0,
192 LayerTypesForUri = 1 << 1,
193 QuerySublayers = 1 << 2,
194 CreateDatabase = 1 << 3,
195 };
196 Q_DECLARE_FLAGS( ProviderMetadataCapabilities, ProviderMetadataCapability )
197
198
204 {
205 FileBasedUris = 1 << 0,
206 SaveLayerMetadata = 1 << 1,
207 };
208 Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )
209
210
214 SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
215
222 QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
223
230 SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
231
233 virtual ~QgsProviderMetadata();
234
240 QString key() const;
241
247 QString description() const;
248
254 virtual QIcon icon() const;
255
261 virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
262
268 virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
269
275#ifndef SIP_RUN
276 virtual QList< Qgis::LayerType > supportedLayerTypes() const;
277#else
278 SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[Qgis.LayerType] );
279 % MethodCode
280 // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
281
282 const QList< Qgis::LayerType > cppRes = sipCpp->supportedLayerTypes();
283
284 PyObject *l = PyList_New( cppRes.size() );
285
286 if ( !l )
287 sipIsErr = 1;
288 else
289 {
290 for ( int i = 0; i < cppRes.size(); ++i )
291 {
292 PyObject *eobj = sipConvertFromEnum( static_cast<int>( cppRes.at( i ) ),
293 sipType_Qgis_LayerType );
294
295 if ( !eobj )
296 {
297 sipIsErr = 1;
298 }
299
300 PyList_SetItem( l, i, eobj );
301 }
302
303 if ( !sipIsErr )
304 {
305 sipRes = l;
306 }
307 else
308 {
309 Py_DECREF( l );
310 }
311 }
312 % End
313#endif
314
322 Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
323
331 SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
332
337 virtual void initProvider();
338
343 virtual void cleanupProvider();
344
349 enum class FilterType
350 {
351 FilterVector = 1,
352 FilterRaster,
353 FilterMesh,
354 FilterMeshDataset,
355 FilterPointCloud,
356 };
357
365 virtual QString filters( FilterType type );
366
372 virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
373
389 virtual int priorityForUri( const QString &uri ) const;
390
401 virtual QList< Qgis::LayerType > validLayerTypesForUri( const QString &uri ) const;
402
419 virtual bool uriIsBlocklisted( const QString &uri ) const;
420
442 virtual QStringList sidecarFilesForUri( const QString &uri ) const;
443
458 virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
459
468 virtual QString suggestGroupNameForUri( const QString &uri ) const;
469
479 virtual QgsDataProvider *createProvider( const QString &uri,
481 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
482
489 static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
490
497 static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
498
499
500#ifndef SIP_RUN
501
507 virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
508 const QgsFields &fields,
509 Qgis::WkbType wkbType,
511 bool overwrite,
512 QMap<int, int> &oldToNewAttrIdxMap,
513 QString &errorMessage,
514 const QMap<QString, QVariant> *options );
515#endif
516
532 virtual bool createDatabase( const QString &uri, QString &errorMessage SIP_OUT );
533
538 virtual QgsRasterDataProvider *createRasterDataProvider(
539 const QString &uri,
540 const QString &format,
541 int nBands,
542 Qgis::DataType type,
543 int width,
544 int height,
545 double *geoTransform,
547 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
548
553 virtual bool createMeshData(
554 const QgsMesh &mesh,
555 const QString &fileName,
556 const QString &driverName,
557 const QgsCoordinateReferenceSystem &crs ) const;
558
563 virtual bool createMeshData(
564 const QgsMesh &mesh,
565 const QString &uri,
566 const QgsCoordinateReferenceSystem &crs ) const;
567
572 virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
573
591 virtual QVariantMap decodeUri( const QString &uri ) const;
592
601 virtual QString encodeUri( const QVariantMap &parts ) const;
602
614 virtual QString absoluteToRelativeUri( const QString &uri, const QgsReadWriteContext &context ) const;
615
627 virtual QString relativeToAbsoluteUri( const QString &uri, const QgsReadWriteContext &context ) const;
628
635 virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
636
642 virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
643 QStringList &descriptions, QString &errCause );
644
656 virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
657
665 virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
666
671 virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
672
684 virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
685 const QString &styleName, const QString &styleDescription,
686 const QString &uiFileContent, bool useAsDefault, QString &errCause );
687
692 virtual QString loadStyle( const QString &uri, QString &errCause );
693
702 virtual QString loadStoredStyle( const QString &uri, QString &styleName, QString &errCause );
703
718 virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
719
724 virtual bool createDb( const QString &dbPath, QString &errCause );
725
730 virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
731
741 virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
742
752 QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
753
763 QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
764
765#ifndef SIP_RUN
766
774 template <typename T> QMap<QString, T *>connections( bool cached = true );
775
776
777#endif
778
788 virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
789
796 virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
797
804 virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
805
813 virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
814
815#ifdef SIP_RUN
816 SIP_PYOBJECT __repr__();
817 % MethodCode
818 QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
819 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
820 % End
821#endif
822
823 signals:
824
831 void connectionCreated( const QString &name );
832
839 void connectionDeleted( const QString &name );
840
848 void connectionChanged( const QString &name );
849
850 protected:
851
852#ifndef SIP_RUN
854
855 // Common functionality for connections management, to be moved into the class
856 // when all the providers are ready
857 // T_provider_conn: subclass of QgsAbstractProviderConnection,
858 // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
859 // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
860 template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
861 {
862 if ( ! cached || mProviderConnections.isEmpty() )
863 {
864 qDeleteAll( mProviderConnections );
865 mProviderConnections.clear();
866 const auto connNames { T_conn::connectionList() };
867 for ( const auto &cname : connNames )
868 {
869 mProviderConnections.insert( cname, new T_provider_conn( cname ) );
870 }
871 }
872 return mProviderConnections;
873 }
874
875 template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
876 {
877 T_provider_conn conn( name );
878 conn.remove( name );
879 mProviderConnections.clear();
880 emit connectionDeleted( name );
881 }
882 virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
884 QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
885
887
888#endif
889
890 private:
891
893 QString mKey;
894
896 QString mDescription;
897
900 QString mLibrary;
901
902 CreateDataProviderFunction mCreateFunction = nullptr;
903
904};
905
906Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
907Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
908
909#endif //QGSPROVIDERMETADATA_H
The Qgis class provides global constants for use throughout the application.
Definition: qgis.h:55
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:620
DataType
Raster data types.
Definition: qgis.h:242
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition: qgis.h:155
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
The QgsAbstractProviderConnection provides an interface for data provider connections.
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:45
Container of fields for a vector layer.
Definition: qgsfields.h:45
A structured metadata store for a map layer.
Base class for providing data for QgsMeshLayer.
Holds metadata about mesh driver.
MeshDriverCapability
Flags for the capabilities of the driver.
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:118
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:101
Holds data provider key, description, and associated shared library file or function pointer informat...
FilterType
Type of file filters.
ProviderCapability
Provider capabilities.
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags &) > CreateDataProviderFunction
Typedef for data provider creation function.
void connectionDeleted(const QString &name)
Emitted when the connection with the specified name was deleted.
void connectionChanged(const QString &name)
Emitted when the connection with the specified name is changed, e.g.
void connectionCreated(const QString &name)
Emitted when a connection with the specified name is created.
ProviderMetadataCapability
Indicates capabilities of the provider metadata implementation.
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...
#define str(x)
Definition: qgis.cpp:37
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:227
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_THROW(name,...)
Definition: qgis_sip.h:198
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
const QgsCoordinateReferenceSystem & crs
Setting options for creating vector data providers.
Mesh - vertices, edges and faces.