QGIS API Documentation 3.29.0-Master (8c80f25a4f)
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< QgsMapLayerType > supportedLayerTypes() const;
277#else
278 SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[QgsMapLayerType] );
279 % MethodCode
280 // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
281
282 const QList< QgsMapLayerType > 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_QgsMapLayerType );
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< QgsMapLayerType > 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
469 virtual QgsDataProvider *createProvider( const QString &uri,
471 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
472
479 static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
480
487 static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
488
489
490#ifndef SIP_RUN
491
497 virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
498 const QgsFields &fields,
499 QgsWkbTypes::Type wkbType,
501 bool overwrite,
502 QMap<int, int> &oldToNewAttrIdxMap,
503 QString &errorMessage,
504 const QMap<QString, QVariant> *options );
505#endif
506
522 virtual bool createDatabase( const QString &uri, QString &errorMessage SIP_OUT );
523
528 virtual QgsRasterDataProvider *createRasterDataProvider(
529 const QString &uri,
530 const QString &format,
531 int nBands,
532 Qgis::DataType type,
533 int width,
534 int height,
535 double *geoTransform,
537 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
538
543 virtual bool createMeshData(
544 const QgsMesh &mesh,
545 const QString &fileName,
546 const QString &driverName,
547 const QgsCoordinateReferenceSystem &crs ) const;
548
553 virtual bool createMeshData(
554 const QgsMesh &mesh,
555 const QString &uri,
556 const QgsCoordinateReferenceSystem &crs ) const;
557
562 virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
563
581 virtual QVariantMap decodeUri( const QString &uri ) const;
582
591 virtual QString encodeUri( const QVariantMap &parts ) const;
592
599 virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
600
606 virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
607 QStringList &descriptions, QString &errCause );
608
620 virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
621
629 virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
630
635 virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
636
648 virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
649 const QString &styleName, const QString &styleDescription,
650 const QString &uiFileContent, bool useAsDefault, QString &errCause );
651
656 virtual QString loadStyle( const QString &uri, QString &errCause );
657
666 virtual QString loadStoredStyle( const QString &uri, QString &styleName, QString &errCause );
667
682 virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
683
688 virtual bool createDb( const QString &dbPath, QString &errCause );
689
694 virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
695
705 virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
706
716 QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
717
727 QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
728
729#ifndef SIP_RUN
730
738 template <typename T> QMap<QString, T *>connections( bool cached = true );
739
740
741#endif
742
752 virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
753
760 virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
761
768 virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
769
777 virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
778
779#ifdef SIP_RUN
780 SIP_PYOBJECT __repr__();
781 % MethodCode
782 QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
783 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
784 % End
785#endif
786
787 signals:
788
795 void connectionCreated( const QString &name );
796
803 void connectionDeleted( const QString &name );
804
812 void connectionChanged( const QString &name );
813
814 protected:
815
816#ifndef SIP_RUN
818
819 // Common functionality for connections management, to be moved into the class
820 // when all the providers are ready
821 // T_provider_conn: subclass of QgsAbstractProviderConnection,
822 // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
823 // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
824 template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
825 {
826 if ( ! cached || mProviderConnections.isEmpty() )
827 {
828 qDeleteAll( mProviderConnections );
829 mProviderConnections.clear();
830 const auto connNames { T_conn::connectionList() };
831 for ( const auto &cname : connNames )
832 {
833 mProviderConnections.insert( cname, new T_provider_conn( cname ) );
834 }
835 }
836 return mProviderConnections;
837 }
838
839 template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
840 {
841 T_provider_conn conn( name );
842 conn.remove( name );
843 mProviderConnections.clear();
844 emit connectionDeleted( name );
845 }
846 virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
848 QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
849
851
852#endif
853
854 private:
855
857 QString mKey;
858
860 QString mDescription;
861
864 QString mLibrary;
865
866 CreateDataProviderFunction mCreateFunction = nullptr;
867
868};
869
870Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
871Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
872
873#endif //QGSPROVIDERMETADATA_H
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:450
DataType
Raster data types.
Definition: qgis.h:129
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.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:47
#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.