QGIS API Documentation 3.41.0-Master (af5edcb665c)
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 &, Qgis::DataProviderReadFlags & ) > 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
229 virtual ~QgsProviderMetadata();
230
236 QString key() const;
237
243 QString description() const;
244
250 virtual QIcon icon() const;
251
257 virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
258
264 virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
265
271#ifndef SIP_RUN
272 virtual QList< Qgis::LayerType > supportedLayerTypes() const;
273#else
274 SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[Qgis.LayerType] );
275 % MethodCode
276 // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
277
278 const QList< Qgis::LayerType > cppRes = sipCpp->supportedLayerTypes();
279
280 PyObject *l = PyList_New( cppRes.size() );
281
282 if ( !l )
283 sipIsErr = 1;
284 else
285 {
286 for ( int i = 0; i < cppRes.size(); ++i )
287 {
288 PyObject *eobj = sipConvertFromEnum( static_cast<int>( cppRes.at( i ) ),
289 sipType_Qgis_LayerType );
290
291 if ( !eobj )
292 {
293 sipIsErr = 1;
294 }
295
296 PyList_SetItem( l, i, eobj );
297 }
298
299 if ( !sipIsErr )
300 {
301 sipRes = l;
302 }
303 else
304 {
305 Py_DECREF( l );
306 }
307 }
308 % End
309#endif
310
318 Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
319
326 SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
327
332 virtual void initProvider();
333
338 virtual void cleanupProvider();
339
347 virtual QString filters( Qgis::FileFilterType type );
348
354 virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
355
371 virtual int priorityForUri( const QString &uri ) const;
372
383 virtual QList< Qgis::LayerType > validLayerTypesForUri( const QString &uri ) const;
384
401 virtual bool uriIsBlocklisted( const QString &uri ) const;
402
424 virtual QStringList sidecarFilesForUri( const QString &uri ) const;
425
440 virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
441
450 virtual QString suggestGroupNameForUri( const QString &uri ) const;
451
461 virtual QgsDataProvider *createProvider( const QString &uri,
462 const QgsDataProvider::ProviderOptions &options,
463 Qgis::DataProviderReadFlags flags = Qgis::DataProviderReadFlags() ) SIP_FACTORY;
464
471 static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
472
479 static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
480
481
482#ifndef SIP_RUN
483
489 virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
490 const QgsFields &fields,
491 Qgis::WkbType wkbType,
493 bool overwrite,
494 QMap<int, int> &oldToNewAttrIdxMap,
495 QString &errorMessage,
496 const QMap<QString, QVariant> *options );
497#endif
498
514 virtual bool createDatabase( const QString &uri, QString &errorMessage SIP_OUT );
515
520 virtual QgsRasterDataProvider *createRasterDataProvider(
521 const QString &uri,
522 const QString &format,
523 int nBands,
524 Qgis::DataType type,
525 int width,
526 int height,
527 double *geoTransform,
529 const QStringList &createOptions = QStringList() ) SIP_FACTORY;
530
536 virtual bool createMeshData(
537 const QgsMesh &mesh,
538 const QString &fileName,
539 const QString &driverName,
541 const QMap<QString, QString> &metadata = QMap<QString, QString>() ) const;
542
548 virtual bool createMeshData(
549 const QgsMesh &mesh,
550 const QString &uri,
552 const QMap<QString, QString> &metadata = QMap<QString, QString>() ) 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
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:983
DataType
Raster data types.
Definition qgis.h:351
WkbType
The WKB type describes the number of dimensions a geometry has.
Definition qgis.h:256
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 &, Qgis::DataProviderReadFlags &) > 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 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.