QGIS API Documentation  3.20.0-Odense (decaadbb31)
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 #include "qgsexception.h"
37 
38 class QgsDataItem;
40 class QgsTransaction;
41 
45 class QgsLayerMetadata;
46 
47 struct QgsMesh;
48 
55 class CORE_EXPORT QgsMeshDriverMetadata
56 {
57  Q_GADGET
58 
59  public:
60 
65  {
66  CanWriteFaceDatasets = 1 << 0,
67  CanWriteVertexDatasets = 1 << 1,
68  CanWriteEdgeDatasets = 1 << 2,
69  CanWriteMeshData = 1 << 3,
70  };
71 
72  Q_ENUM( MeshDriverCapability )
73  Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
74  Q_FLAG( MeshDriverCapabilities )
75 
76 
78 
87  QgsMeshDriverMetadata( const QString &name,
88  const QString &description,
89  const MeshDriverCapabilities &capabilities,
90  const QString &writeDatasetOnFileSuffix );
91 
95  MeshDriverCapabilities capabilities() const;
96 
100  QString name() const;
101 
105  QString description() const;
106 
110  QString writeDatasetOnFileSuffix() const;
111 
112  private:
113  QString mName;
114  QString mDescription;
115  MeshDriverCapabilities mCapabilities;
116  QString mWriteDatasetOnFileSuffix;
117 };
118 
119 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMeshDriverMetadata::MeshDriverCapabilities )
120 
138 class CORE_EXPORT QgsProviderMetadata : public QObject
139 {
140  Q_OBJECT
141 
142  public:
143 
150  {
151  PriorityForUri = 1 << 0,
152  LayerTypesForUri = 1 << 1,
153  };
154  Q_DECLARE_FLAGS( ProviderMetadataCapabilities, ProviderMetadataCapability )
155 
156 
162  {
163  FileBasedUris = 1 << 0,
164  SaveLayerMetadata = 1 << 1,
165  };
166  Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )
167 
168 
172  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
173 
180  QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
181 
188  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
189 
191  virtual ~QgsProviderMetadata();
192 
198  QString key() const;
199 
205  QString description() const;
206 
212  virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
213 
219  virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
220 
228  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
229 
237  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
238 
243  virtual void initProvider();
244 
249  virtual void cleanupProvider();
250 
255  enum class FilterType
256  {
257  FilterVector = 1,
258  FilterRaster,
259  FilterMesh,
260  FilterMeshDataset,
261  FilterPointCloud,
262  };
263 
271  virtual QString filters( FilterType type );
272 
278  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
279 
295  virtual int priorityForUri( const QString &uri ) const;
296 
307  virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;
308 
325  virtual bool uriIsBlocklisted( const QString &uri ) const;
326 
336  virtual QgsDataProvider *createProvider( const QString &uri,
337  const QgsDataProvider::ProviderOptions &options,
338  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
339 
346  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
347 
354  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
355 
356 
357 #ifndef SIP_RUN
358 
364  virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
365  const QgsFields &fields,
366  QgsWkbTypes::Type wkbType,
367  const QgsCoordinateReferenceSystem &srs,
368  bool overwrite,
369  QMap<int, int> &oldToNewAttrIdxMap,
370  QString &errorMessage,
371  const QMap<QString, QVariant> *options );
372 #endif
373 
378  virtual QgsRasterDataProvider *createRasterDataProvider(
379  const QString &uri,
380  const QString &format,
381  int nBands,
382  Qgis::DataType type,
383  int width,
384  int height,
385  double *geoTransform,
387  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
388 
393  virtual bool createMeshData(
394  const QgsMesh &mesh,
395  const QString uri,
396  const QString &driverName,
397  const QgsCoordinateReferenceSystem &crs ) const;
398 
403  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
404 
422  virtual QVariantMap decodeUri( const QString &uri ) const;
423 
432  virtual QString encodeUri( const QVariantMap &parts ) const;
433 
440  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
441 
447  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
448  QStringList &descriptions, QString &errCause );
449 
454  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
455 
460  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
461 
466  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
467  const QString &styleName, const QString &styleDescription,
468  const QString &uiFileContent, bool useAsDefault, QString &errCause );
469 
474  virtual QString loadStyle( const QString &uri, QString &errCause );
475 
490  virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
491 
496  virtual bool createDb( const QString &dbPath, QString &errCause );
497 
502  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
503 
513  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
514 
524  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
525 
535  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
536 
537 #ifndef SIP_RUN
538 
546  template <typename T> QMap<QString, T *>connections( bool cached = true );
547 
548 
549 #endif
550 
560  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
561 
568  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
569 
576  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
577 
585  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
586 
587 #ifdef SIP_RUN
588  SIP_PYOBJECT __repr__();
589  % MethodCode
590  QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
591  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
592  % End
593 #endif
594 
595  signals:
596 
603  void connectionCreated( const QString &name );
604 
611  void connectionDeleted( const QString &name );
612 
620  void connectionChanged( const QString &name );
621 
622  protected:
623 
624 #ifndef SIP_RUN
626 
627  // Common functionality for connections management, to be moved into the class
628  // when all the providers are ready
629  // T_provider_conn: subclass of QgsAbstractProviderConnection,
630  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
631  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
632  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
633  {
634  if ( ! cached || mProviderConnections.isEmpty() )
635  {
636  qDeleteAll( mProviderConnections );
637  mProviderConnections.clear();
638  const auto connNames { T_conn::connectionList() };
639  for ( const auto &cname : connNames )
640  {
641  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
642  }
643  }
644  return mProviderConnections;
645  }
646 
647  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
648  {
649  T_provider_conn conn( name );
650  conn.remove( name );
651  mProviderConnections.clear();
652  emit connectionDeleted( name );
653  }
654  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
656  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
657 
659 
660 #endif
661 
662  private:
663 
665  QString mKey;
666 
668  QString mDescription;
669 
672  QString mLibrary;
673 
674  CreateDataProviderFunction mCreateFunction = nullptr;
675 
676 };
677 
678 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
679 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
680 
681 #endif //QGSPROVIDERMETADATA_H
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:316
DataType
Raster data types.
Definition: qgis.h:119
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.
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.
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
#define str(x)
Definition: qgis.cpp:37
#define SIP_THROW(name)
Definition: qgis_sip.h:189
#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
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.