QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
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>
35#include "qgsfields.h"
36
37class QgsDataItem;
39class QgsTransaction;
40
46class QgsFeedback;
47
48struct QgsMesh;
49
56class CORE_EXPORT QgsMeshDriverMetadata
57{
58 Q_GADGET
59
60 public:
61
66 {
67 CanWriteFaceDatasets = 1 << 0,
68 CanWriteVertexDatasets = 1 << 1,
69 CanWriteEdgeDatasets = 1 << 2,
70 CanWriteMeshData = 1 << 3,
71 };
72
73 Q_ENUM( MeshDriverCapability )
76
79
90 Q_DECL_DEPRECATED QgsMeshDriverMetadata( const QString &name,
91 const QString &description,
92 const MeshDriverCapabilities &capabilities,
93 const QString &writeDatasetOnFileSuffix ) SIP_DEPRECATED;
94
107 QgsMeshDriverMetadata( const QString &name,
108 const QString &description,
109 const MeshDriverCapabilities &capabilities,
110 const QString &writeDatasetOnFileSuffix,
111 const QString &writeMeshFrameOnFileSuffix,
112 int maxVerticesPerface );
113
117 MeshDriverCapabilities capabilities() const;
118
122 QString name() const;
123
127 QString description() const;
128
132 QString writeDatasetOnFileSuffix() const;
133
139 QString writeMeshFrameOnFileSuffix() const;
140
146 int maximumVerticesCountPerFace() const;
147
148 private:
149 QString mName;
150 QString mDescription;
151 MeshDriverCapabilities mCapabilities;
152 QString mWriteDatasetOnFileSuffix;
153 QString mWriteMeshFrameOnFileSuffix;
154 int mMaxVerticesPerFace = -1;
155};
156
158
176class CORE_EXPORT QgsProviderMetadata : public QObject
177{
178 Q_OBJECT
179
180 public:
181
188 {
189 PriorityForUri = 1 << 0,
190 LayerTypesForUri = 1 << 1,
191 QuerySublayers = 1 << 2,
192 CreateDatabase = 1 << 3,
193 };
195
196
202 {
203 FileBasedUris = 1 << 0,
204 SaveLayerMetadata = 1 << 1,
205 ParallelCreateProvider = 1 << 2,
206 };
208
209
212 SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
213
220 QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
221
227 SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
228
230 virtual ~QgsProviderMetadata();
231
237 QString key() const;
238
244 QString description() const;
245
251 virtual QIcon icon() const;
252
258 virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
259
265 virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
266
272#ifndef SIP_RUN
273 virtual QList< Qgis::LayerType > supportedLayerTypes() const;
274#else
275 SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[Qgis.LayerType] );
276 % MethodCode
277 // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
278
279 const QList< Qgis::LayerType > cppRes = sipCpp->supportedLayerTypes();
280
281 PyObject *l = PyList_New( cppRes.size() );
282
283 if ( !l )
284 sipIsErr = 1;
285 else
286 {
287 for ( int i = 0; i < cppRes.size(); ++i )
288 {
289 PyObject *eobj = sipConvertFromEnum( static_cast<int>( cppRes.at( i ) ),
290 sipType_Qgis_LayerType );
291
292 if ( !eobj )
293 {
294 sipIsErr = 1;
295 }
296
297 PyList_SetItem( l, i, eobj );
298 }
299
300 if ( !sipIsErr )
301 {
302 sipRes = l;
303 }
304 else
305 {
306 Py_DECREF( l );
307 }
308 }
309 % End
310#endif
311
319 Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
320
327 SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
328
333 virtual void initProvider();
334
339 virtual void cleanupProvider();
340
348 virtual QString filters( Qgis::FileFilterType type );
349
355 virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
356
372 virtual int priorityForUri( const QString &uri ) const;
373
384 virtual QList< Qgis::LayerType > validLayerTypesForUri( const QString &uri ) const;
385
402 virtual bool uriIsBlocklisted( const QString &uri ) const;
403
425 virtual QStringList sidecarFilesForUri( const QString &uri ) const;
426
441 virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
442
451 virtual QString suggestGroupNameForUri( const QString &uri ) const;
452
462 virtual QgsDataProvider *createProvider( const QString &uri,
463 const QgsDataProvider::ProviderOptions &options,
464 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
465
472 static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
473
480 static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
481
482
483#ifndef SIP_RUN
484
490 virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
491 const QgsFields &fields,
492 Qgis::WkbType wkbType,
494 bool overwrite,
495 QMap<int, int> &oldToNewAttrIdxMap,
496 QString &errorMessage,
497 const QMap<QString, QVariant> *options );
498#endif
499
515 virtual bool createDatabase( const QString &uri, QString &errorMessage SIP_OUT );
516
521 virtual QgsRasterDataProvider *createRasterDataProvider(
522 const QString &uri,
523 const QString &format,
524 int nBands,
525 Qgis::DataType type,
526 int width,
527 int height,
528 double *geoTransform,
530 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
531
537 virtual bool createMeshData(
538 const QgsMesh &mesh,
539 const QString &fileName,
540 const QString &driverName,
542 const QMap<QString, QString> &metadata = QMap<QString, QString>() ) const;
543
549 virtual bool createMeshData(
550 const QgsMesh &mesh,
551 const QString &uri,
553 const QMap<QString, QString> &metadata = QMap<QString, QString>() ) const;
554
559 virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
560
578 virtual QVariantMap decodeUri( const QString &uri ) const;
579
588 virtual QString encodeUri( const QVariantMap &parts ) const;
589
601 virtual QString absoluteToRelativeUri( const QString &uri, const QgsReadWriteContext &context ) const;
602
614 virtual QString relativeToAbsoluteUri( const QString &uri, const QgsReadWriteContext &context ) const;
615
622 virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
623
629 virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
630 QStringList &descriptions, QString &errCause );
631
643 virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
644
652 virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
653
658 virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
659
671 virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
672 const QString &styleName, const QString &styleDescription,
673 const QString &uiFileContent, bool useAsDefault, QString &errCause );
674
679 virtual QString loadStyle( const QString &uri, QString &errCause );
680
689 virtual QString loadStoredStyle( const QString &uri, QString &styleName, QString &errCause );
690
705 virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
706
711 virtual bool createDb( const QString &dbPath, QString &errCause );
712
717 virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
718
728 virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
729
739 QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
740
750 QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
751
752#ifndef SIP_RUN
753
761 template <typename T> QMap<QString, T *>connections( bool cached = true );
762
763
764#endif
765
775 virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
776
783 virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
784
791 virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
792
800 virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
801
802#ifdef SIP_RUN
803 SIP_PYOBJECT __repr__();
804 % MethodCode
805 QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
806 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
807 % End
808#endif
809
810 signals:
811
818 void connectionCreated( const QString &name );
819
826 void connectionDeleted( const QString &name );
827
835 void connectionChanged( const QString &name );
836
837 protected:
838
839#ifndef SIP_RUN
841
842 // Common functionality for connections management, to be moved into the class
843 // when all the providers are ready
844 // T_provider_conn: subclass of QgsAbstractProviderConnection,
845 // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
846 // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
847 template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
848 {
849 if ( ! cached || mProviderConnections.isEmpty() )
850 {
851 qDeleteAll( mProviderConnections );
852 mProviderConnections.clear();
853 const auto connNames { T_conn::connectionList() };
854 for ( const auto &cname : connNames )
855 {
856 mProviderConnections.insert( cname, new T_provider_conn( cname ) );
857 }
858 }
859 return mProviderConnections;
860 }
861
862 template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
863 {
864 T_provider_conn conn( name );
865 conn.remove( name );
866 mProviderConnections.clear();
867 emit connectionDeleted( name );
868 }
869 virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
871 QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
872
874
875#endif
876
877 private:
878
880 QString mKey;
881
883 QString mDescription;
884
887 QString mLibrary;
888
889 CreateDataProviderFunction mCreateFunction = nullptr;
890
891};
892
895
896#endif //QGSPROVIDERMETADATA_H
The Qgis class provides global constants for use throughout the application.
Definition qgis.h:54
VectorExportResult
Vector layer export result codes.
Definition qgis.h:806
DataType
Raster data types.
Definition qgis.h:288
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:201
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:44
Container of fields for a vector layer.
Definition qgsfields.h:46
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.
QFlags< MeshDriverCapability > MeshDriverCapabilities
Custom exception class which is raised when an operation is not supported.
Custom exception class for provider connection related exceptions.
Holds data provider key, description, and associated shared library file or function pointer informat...
QFlags< ProviderMetadataCapability > ProviderMetadataCapabilities
QFlags< ProviderCapability > ProviderCapabilities
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:38
#define SIP_TYPEHINT(type)
Definition qgis_sip.h:232
#define SIP_DEPRECATED
Definition qgis_sip.h:106
#define SIP_ENUM_BASETYPE(type)
Definition qgis_sip.h:278
#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:203
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Mesh - vertices, edges and faces.