QGIS API Documentation 3.34.0-Prizren (ffbdd678812)
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 )
74 Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
75 Q_FLAG( MeshDriverCapabilities )
76
77
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 };
194 Q_DECLARE_FLAGS( ProviderMetadataCapabilities, ProviderMetadataCapability )
195
196
202 {
203 FileBasedUris = 1 << 0,
204 SaveLayerMetadata = 1 << 1,
205 ParallelCreateProvider = 1 << 2,
206 };
207 Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )
208
209
213 SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
214
221 QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
222
229 SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
230
232 virtual ~QgsProviderMetadata();
233
239 QString key() const;
240
246 QString description() const;
247
253 virtual QIcon icon() const;
254
260 virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
261
267 virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
268
274#ifndef SIP_RUN
275 virtual QList< Qgis::LayerType > supportedLayerTypes() const;
276#else
277 SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[Qgis.LayerType] );
278 % MethodCode
279 // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
280
281 const QList< Qgis::LayerType > cppRes = sipCpp->supportedLayerTypes();
282
283 PyObject *l = PyList_New( cppRes.size() );
284
285 if ( !l )
286 sipIsErr = 1;
287 else
288 {
289 for ( int i = 0; i < cppRes.size(); ++i )
290 {
291 PyObject *eobj = sipConvertFromEnum( static_cast<int>( cppRes.at( i ) ),
292 sipType_Qgis_LayerType );
293
294 if ( !eobj )
295 {
296 sipIsErr = 1;
297 }
298
299 PyList_SetItem( l, i, eobj );
300 }
301
302 if ( !sipIsErr )
303 {
304 sipRes = l;
305 }
306 else
307 {
308 Py_DECREF( l );
309 }
310 }
311 % End
312#endif
313
321 Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
322
330 SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
331
336 virtual void initProvider();
337
342 virtual void cleanupProvider();
343
351 virtual QString filters( Qgis::FileFilterType type );
352
358 virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
359
375 virtual int priorityForUri( const QString &uri ) const;
376
387 virtual QList< Qgis::LayerType > validLayerTypesForUri( const QString &uri ) const;
388
405 virtual bool uriIsBlocklisted( const QString &uri ) const;
406
428 virtual QStringList sidecarFilesForUri( const QString &uri ) const;
429
444 virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
445
454 virtual QString suggestGroupNameForUri( const QString &uri ) const;
455
465 virtual QgsDataProvider *createProvider( const QString &uri,
466 const QgsDataProvider::ProviderOptions &options,
467 QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
468
475 static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
476
483 static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
484
485
486#ifndef SIP_RUN
487
493 virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
494 const QgsFields &fields,
495 Qgis::WkbType wkbType,
497 bool overwrite,
498 QMap<int, int> &oldToNewAttrIdxMap,
499 QString &errorMessage,
500 const QMap<QString, QVariant> *options );
501#endif
502
518 virtual bool createDatabase( const QString &uri, QString &errorMessage SIP_OUT );
519
524 virtual QgsRasterDataProvider *createRasterDataProvider(
525 const QString &uri,
526 const QString &format,
527 int nBands,
528 Qgis::DataType type,
529 int width,
530 int height,
531 double *geoTransform,
533 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
534
539 virtual bool createMeshData(
540 const QgsMesh &mesh,
541 const QString &fileName,
542 const QString &driverName,
543 const QgsCoordinateReferenceSystem &crs ) const;
544
549 virtual bool createMeshData(
550 const QgsMesh &mesh,
551 const QString &uri,
552 const QgsCoordinateReferenceSystem &crs ) const;
553
558 virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
559
577 virtual QVariantMap decodeUri( const QString &uri ) const;
578
587 virtual QString encodeUri( const QVariantMap &parts ) const;
588
600 virtual QString absoluteToRelativeUri( const QString &uri, const QgsReadWriteContext &context ) const;
601
613 virtual QString relativeToAbsoluteUri( const QString &uri, const QgsReadWriteContext &context ) const;
614
621 virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
622
628 virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
629 QStringList &descriptions, QString &errCause );
630
642 virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
643
651 virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
652
657 virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
658
670 virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
671 const QString &styleName, const QString &styleDescription,
672 const QString &uiFileContent, bool useAsDefault, QString &errCause );
673
678 virtual QString loadStyle( const QString &uri, QString &errCause );
679
688 virtual QString loadStoredStyle( const QString &uri, QString &styleName, QString &errCause );
689
704 virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
705
710 virtual bool createDb( const QString &dbPath, QString &errCause );
711
716 virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
717
727 virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
728
738 QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
739
749 QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
750
751#ifndef SIP_RUN
752
760 template <typename T> QMap<QString, T *>connections( bool cached = true );
761
762
763#endif
764
774 virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
775
782 virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
783
790 virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
791
799 virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
800
801#ifdef SIP_RUN
802 SIP_PYOBJECT __repr__();
803 % MethodCode
804 QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
805 sipRes = PyUnicode_FromString( str.toUtf8().constData() );
806 % End
807#endif
808
809 signals:
810
817 void connectionCreated( const QString &name );
818
825 void connectionDeleted( const QString &name );
826
834 void connectionChanged( const QString &name );
835
836 protected:
837
838#ifndef SIP_RUN
840
841 // Common functionality for connections management, to be moved into the class
842 // when all the providers are ready
843 // T_provider_conn: subclass of QgsAbstractProviderConnection,
844 // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
845 // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
846 template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
847 {
848 if ( ! cached || mProviderConnections.isEmpty() )
849 {
850 qDeleteAll( mProviderConnections );
851 mProviderConnections.clear();
852 const auto connNames { T_conn::connectionList() };
853 for ( const auto &cname : connNames )
854 {
855 mProviderConnections.insert( cname, new T_provider_conn( cname ) );
856 }
857 }
858 return mProviderConnections;
859 }
860
861 template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
862 {
863 T_provider_conn conn( name );
864 conn.remove( name );
865 mProviderConnections.clear();
866 emit connectionDeleted( name );
867 }
868 virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
870 QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
871
873
874#endif
875
876 private:
877
879 QString mKey;
880
882 QString mDescription;
883
886 QString mLibrary;
887
888 CreateDataProviderFunction mCreateFunction = nullptr;
889
890};
891
892Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
893Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
894
895#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:708
DataType
Raster data types.
Definition qgis.h:269
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:182
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.
Custom exception class for provider connection related exceptions.
Holds data provider key, description, and associated shared library file or function pointer informat...
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: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(QgsTextRendererUtils::CurvedTextFlags)
const QgsCoordinateReferenceSystem & crs
Mesh - vertices, edges and faces.