QGIS API Documentation  3.21.0-Master (5b68dc587e)
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;
47 class QgsFeedback;
48 
49 struct QgsMesh;
50 
57 class CORE_EXPORT QgsMeshDriverMetadata
58 {
59  Q_GADGET
60 
61  public:
62 
67  {
68  CanWriteFaceDatasets = 1 << 0,
69  CanWriteVertexDatasets = 1 << 1,
70  CanWriteEdgeDatasets = 1 << 2,
71  CanWriteMeshData = 1 << 3,
72  };
73 
74  Q_ENUM( MeshDriverCapability )
75  Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
76  Q_FLAG( MeshDriverCapabilities )
77 
78 
80 
91  Q_DECL_DEPRECATED QgsMeshDriverMetadata( const QString &name,
92  const QString &description,
93  const MeshDriverCapabilities &capabilities,
94  const QString &writeDatasetOnFileSuffix ) SIP_DEPRECATED;
95 
108  QgsMeshDriverMetadata( const QString &name,
109  const QString &description,
110  const MeshDriverCapabilities &capabilities,
111  const QString &writeDatasetOnFileSuffix,
112  const QString &writeMeshFrameOnFileSuffix,
113  int maxVerticesPerface );
114 
118  MeshDriverCapabilities capabilities() const;
119 
123  QString name() const;
124 
128  QString description() const;
129 
133  QString writeDatasetOnFileSuffix() const;
134 
140  QString writeMeshFrameOnFileSuffix() const;
141 
147  int maximumVerticesCountPerFace() const;
148 
149  private:
150  QString mName;
151  QString mDescription;
152  MeshDriverCapabilities mCapabilities;
153  QString mWriteDatasetOnFileSuffix;
154  QString mWriteMeshFrameOnFileSuffix;
155  int mMaxVerticesPerFace = -1;
156 };
157 
158 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMeshDriverMetadata::MeshDriverCapabilities )
159 
177 class CORE_EXPORT QgsProviderMetadata : public QObject
178 {
179  Q_OBJECT
180 
181  public:
182 
189  {
190  PriorityForUri = 1 << 0,
191  LayerTypesForUri = 1 << 1,
192  QuerySublayers = 1 << 2,
193  };
194  Q_DECLARE_FLAGS( ProviderMetadataCapabilities, ProviderMetadataCapability )
195 
196 
202  {
203  FileBasedUris = 1 << 0,
204  SaveLayerMetadata = 1 << 1,
205  };
206  Q_DECLARE_FLAGS( ProviderCapabilities, ProviderCapability )
207 
208 
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 
228  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
229 
231  virtual ~QgsProviderMetadata();
232 
238  QString key() const;
239 
245  QString description() const;
246 
252  virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
253 
259  virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
260 
268  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
269 
277  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
278 
283  virtual void initProvider();
284 
289  virtual void cleanupProvider();
290 
295  enum class FilterType
296  {
297  FilterVector = 1,
298  FilterRaster,
299  FilterMesh,
300  FilterMeshDataset,
301  FilterPointCloud,
302  };
303 
311  virtual QString filters( FilterType type );
312 
318  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
319 
335  virtual int priorityForUri( const QString &uri ) const;
336 
347  virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;
348 
365  virtual bool uriIsBlocklisted( const QString &uri ) const;
366 
388  virtual QStringList sidecarFilesForUri( const QString &uri ) const;
389 
404  virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
405 
415  virtual QgsDataProvider *createProvider( const QString &uri,
416  const QgsDataProvider::ProviderOptions &options,
417  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
418 
425  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
426 
433  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
434 
435 
436 #ifndef SIP_RUN
437 
443  virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
444  const QgsFields &fields,
445  QgsWkbTypes::Type wkbType,
446  const QgsCoordinateReferenceSystem &srs,
447  bool overwrite,
448  QMap<int, int> &oldToNewAttrIdxMap,
449  QString &errorMessage,
450  const QMap<QString, QVariant> *options );
451 #endif
452 
457  virtual QgsRasterDataProvider *createRasterDataProvider(
458  const QString &uri,
459  const QString &format,
460  int nBands,
461  Qgis::DataType type,
462  int width,
463  int height,
464  double *geoTransform,
466  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
467 
472  virtual bool createMeshData(
473  const QgsMesh &mesh,
474  const QString &fileName,
475  const QString &driverName,
476  const QgsCoordinateReferenceSystem &crs ) const;
477 
482  virtual bool createMeshData(
483  const QgsMesh &mesh,
484  const QString &uri,
485  const QgsCoordinateReferenceSystem &crs ) const;
486 
491  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
492 
510  virtual QVariantMap decodeUri( const QString &uri ) const;
511 
520  virtual QString encodeUri( const QVariantMap &parts ) const;
521 
528  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
529 
535  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
536  QStringList &descriptions, QString &errCause );
537 
542  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
543 
548  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
549 
554  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
555  const QString &styleName, const QString &styleDescription,
556  const QString &uiFileContent, bool useAsDefault, QString &errCause );
557 
562  virtual QString loadStyle( const QString &uri, QString &errCause );
563 
578  virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
579 
584  virtual bool createDb( const QString &dbPath, QString &errCause );
585 
590  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
591 
601  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
602 
612  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
613 
623  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
624 
625 #ifndef SIP_RUN
626 
634  template <typename T> QMap<QString, T *>connections( bool cached = true );
635 
636 
637 #endif
638 
648  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
649 
656  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
657 
664  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
665 
673  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
674 
675 #ifdef SIP_RUN
676  SIP_PYOBJECT __repr__();
677  % MethodCode
678  QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
679  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
680  % End
681 #endif
682 
683  signals:
684 
691  void connectionCreated( const QString &name );
692 
699  void connectionDeleted( const QString &name );
700 
708  void connectionChanged( const QString &name );
709 
710  protected:
711 
712 #ifndef SIP_RUN
714 
715  // Common functionality for connections management, to be moved into the class
716  // when all the providers are ready
717  // T_provider_conn: subclass of QgsAbstractProviderConnection,
718  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
719  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
720  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
721  {
722  if ( ! cached || mProviderConnections.isEmpty() )
723  {
724  qDeleteAll( mProviderConnections );
725  mProviderConnections.clear();
726  const auto connNames { T_conn::connectionList() };
727  for ( const auto &cname : connNames )
728  {
729  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
730  }
731  }
732  return mProviderConnections;
733  }
734 
735  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
736  {
737  T_provider_conn conn( name );
738  conn.remove( name );
739  mProviderConnections.clear();
740  emit connectionDeleted( name );
741  }
742  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
744  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
745 
747 
748 #endif
749 
750  private:
751 
753  QString mKey;
754 
756  QString mDescription;
757 
760  QString mLibrary;
761 
762  CreateDataProviderFunction mCreateFunction = nullptr;
763 
764 };
765 
766 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
767 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
768 
769 #endif //QGSPROVIDERMETADATA_H
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:347
DataType
Raster data types.
Definition: qgis.h:120
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.
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.
Contains details about a sub layer available from a dataset.
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.