QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
549  virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
550 
558  virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
559 
564  virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
565 
577  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
578  const QString &styleName, const QString &styleDescription,
579  const QString &uiFileContent, bool useAsDefault, QString &errCause );
580 
585  virtual QString loadStyle( const QString &uri, QString &errCause );
586 
601  virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
602 
607  virtual bool createDb( const QString &dbPath, QString &errCause );
608 
613  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
614 
624  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
625 
635  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
636 
646  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
647 
648 #ifndef SIP_RUN
649 
657  template <typename T> QMap<QString, T *>connections( bool cached = true );
658 
659 
660 #endif
661 
671  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
672 
679  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
680 
687  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
688 
696  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
697 
698 #ifdef SIP_RUN
699  SIP_PYOBJECT __repr__();
700  % MethodCode
701  QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
702  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
703  % End
704 #endif
705 
706  signals:
707 
714  void connectionCreated( const QString &name );
715 
722  void connectionDeleted( const QString &name );
723 
731  void connectionChanged( const QString &name );
732 
733  protected:
734 
735 #ifndef SIP_RUN
737 
738  // Common functionality for connections management, to be moved into the class
739  // when all the providers are ready
740  // T_provider_conn: subclass of QgsAbstractProviderConnection,
741  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
742  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
743  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
744  {
745  if ( ! cached || mProviderConnections.isEmpty() )
746  {
747  qDeleteAll( mProviderConnections );
748  mProviderConnections.clear();
749  const auto connNames { T_conn::connectionList() };
750  for ( const auto &cname : connNames )
751  {
752  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
753  }
754  }
755  return mProviderConnections;
756  }
757 
758  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
759  {
760  T_provider_conn conn( name );
761  conn.remove( name );
762  mProviderConnections.clear();
763  emit connectionDeleted( name );
764  }
765  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
767  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
768 
770 
771 #endif
772 
773  private:
774 
776  QString mKey;
777 
779  QString mDescription;
780 
783  QString mLibrary;
784 
785  CreateDataProviderFunction mCreateFunction = nullptr;
786 
787 };
788 
789 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
790 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
791 
792 #endif //QGSPROVIDERMETADATA_H
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:361
DataType
Raster data types.
Definition: qgis.h:121
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.