QGIS API Documentation  3.17.0-Master (8af46bc54f)
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>
34 #include "qgsvectorlayerexporter.h"
36 #include "qgsfields.h"
37 #include "qgsexception.h"
38 
39 class QgsDataItem;
41 class QgsTransaction;
42 
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 
121 
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 
160  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
161 
168  QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
169 
176  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
177 
179  virtual ~QgsProviderMetadata();
180 
186  QString key() const;
187 
193  QString description() const;
194 
200  virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
201 
209  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
210 
218  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
219 
224  virtual void initProvider();
225 
230  virtual void cleanupProvider();
231 
236  enum class FilterType
237  {
238  FilterVector = 1,
239  FilterRaster,
240  FilterMesh,
241  FilterMeshDataset,
242  FilterPointCloud,
243  };
244 
252  virtual QString filters( FilterType type );
253 
259  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
260 
276  virtual int priorityForUri( const QString &uri ) const;
277 
288  virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;
289 
306  virtual bool uriIsBlocklisted( const QString &uri ) const;
307 
317  virtual QgsDataProvider *createProvider( const QString &uri,
318  const QgsDataProvider::ProviderOptions &options,
319  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
320 
327  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
328 
335  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
336 
337 
338 #ifndef SIP_RUN
339 
345  virtual QgsVectorLayerExporter::ExportError createEmptyLayer( const QString &uri,
346  const QgsFields &fields,
347  QgsWkbTypes::Type wkbType,
348  const QgsCoordinateReferenceSystem &srs,
349  bool overwrite,
350  QMap<int, int> &oldToNewAttrIdxMap,
351  QString &errorMessage,
352  const QMap<QString, QVariant> *options );
353 #endif
354 
359  virtual QgsRasterDataProvider *createRasterDataProvider(
360  const QString &uri,
361  const QString &format,
362  int nBands,
363  Qgis::DataType type,
364  int width,
365  int height,
366  double *geoTransform,
368  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
369 
374  virtual bool createMeshData(
375  const QgsMesh &mesh,
376  const QString uri,
377  const QString &driverName,
378  const QgsCoordinateReferenceSystem &crs ) const;
379 
384  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
385 
403  virtual QVariantMap decodeUri( const QString &uri ) const;
404 
413  virtual QString encodeUri( const QVariantMap &parts ) const;
414 
421  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
422 
428  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
429  QStringList &descriptions, QString &errCause );
430 
435  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
436 
441  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
442 
447  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
448  const QString &styleName, const QString &styleDescription,
449  const QString &uiFileContent, bool useAsDefault, QString &errCause );
450 
455  virtual QString loadStyle( const QString &uri, QString &errCause );
456 
461  virtual bool createDb( const QString &dbPath, QString &errCause );
462 
467  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
468 
478  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
479 
489  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
490 
500  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
501 
502 #ifndef SIP_RUN
503 
511  template <typename T> QMap<QString, T *>connections( bool cached = true );
512 
513 
514 #endif
515 
525  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
526 
533  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
534 
541  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
542 
550  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
551 
552 #ifdef SIP_RUN
553  SIP_PYOBJECT __repr__();
554  % MethodCode
555  QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
556  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
557  % End
558 #endif
559 
560  signals:
561 
568  void connectionCreated( const QString &name );
569 
576  void connectionDeleted( const QString &name );
577 
585  void connectionChanged( const QString &name );
586 
587  protected:
588 
589 #ifndef SIP_RUN
590 
592  // Common functionality for connections management, to be moved into the class
593  // when all the providers are ready
594  // T_provider_conn: subclass of QgsAbstractProviderConnection,
595  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
596  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
597  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
598  {
599  if ( ! cached || mProviderConnections.isEmpty() )
600  {
601  qDeleteAll( mProviderConnections );
602  mProviderConnections.clear();
603  const auto connNames { T_conn::connectionList() };
604  for ( const auto &cname : connNames )
605  {
606  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
607  }
608  }
609  return mProviderConnections;
610  }
611 
612  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
613  {
614  T_provider_conn conn( name );
615  conn.remove( name );
616  mProviderConnections.clear();
617  emit connectionDeleted( name );
618  }
619  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
621  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
622 
624 
625 #endif
626 
627  private:
628 
630  QString mKey;
631 
633  QString mDescription;
634 
637  QString mLibrary;
638 
639  CreateDataProviderFunction mCreateFunction = nullptr;
640 
641 };
642 
643 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
644 
645 
646 #endif //QGSPROVIDERMETADATA_H
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
DataType
Raster data types.
Definition: qgis.h:101
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.
Container of fields for a vector layer.
Definition: qgsfields.h:44
Abstract base class for spatial data provider implementations.
const QgsCoordinateReferenceSystem & crs
The QgsAbstractProviderConnection provides an interface for data provider connections.
Holds metadata about mesh driver.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
#define SIP_SKIP
Definition: qgis_sip.h:126
ProviderMetadataCapability
Indicates capabilities of the provider metadata implementation.
#define SIP_FACTORY
Definition: qgis_sip.h:76
MeshDriverCapability
Flags for the capabilities of the driver.
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Base class for all items in the model.
Definition: qgsdataitem.h:50
Base class for providing data for QgsMeshLayer.
Setting options for creating vector data providers.
Holds data provider key, description, and associated shared library file or function pointer informat...
Mesh - vertices, edges and faces.
This class allows including a set of layers in a database-side transaction, provided the layer data p...
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags &) > CreateDataProviderFunction
Typedef for data provider creation function.
This class represents a coordinate reference system (CRS).
#define SIP_THROW(name)
Definition: qgis_sip.h:189
FilterType
Type of file filters.
This is the interface for those who want to add custom data items to the browser tree.
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:100
Base class for raster data providers.