QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
160 
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 QIcon icon() const;
253 
259  virtual QgsProviderMetadata::ProviderMetadataCapabilities capabilities() const;
260 
266  virtual QgsProviderMetadata::ProviderCapabilities providerCapabilities() const;
267 
273 #ifndef SIP_RUN
274  virtual QList< QgsMapLayerType > supportedLayerTypes() const;
275 #else
276  SIP_PYOBJECT supportedLayerTypes() const SIP_TYPEHINT( List[QgsMapLayerType] );
277  % MethodCode
278  // adapted from the qpymultimedia_qlist.sip file from the PyQt6 sources
279 
280  const QList< QgsMapLayerType > cppRes = sipCpp->supportedLayerTypes();
281 
282  PyObject *l = PyList_New( cppRes.size() );
283 
284  if ( !l )
285  sipIsErr = 1;
286  else
287  {
288  for ( int i = 0; i < cppRes.size(); ++i )
289  {
290  PyObject *eobj = sipConvertFromEnum( static_cast<int>( cppRes.at( i ) ),
291  sipType_QgsMapLayerType );
292 
293  if ( !eobj )
294  {
295  sipIsErr = 1;
296  }
297 
298  PyList_SetItem( l, i, eobj );
299  }
300 
301  if ( !sipIsErr )
302  {
303  sipRes = l;
304  }
305  else
306  {
307  Py_DECREF( l );
308  }
309  }
310  % End
311 #endif
312 
320  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
321 
329  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
330 
335  virtual void initProvider();
336 
341  virtual void cleanupProvider();
342 
347  enum class FilterType
348  {
349  FilterVector = 1,
350  FilterRaster,
351  FilterMesh,
352  FilterMeshDataset,
353  FilterPointCloud,
354  };
355 
363  virtual QString filters( FilterType type );
364 
370  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
371 
387  virtual int priorityForUri( const QString &uri ) const;
388 
399  virtual QList< QgsMapLayerType > validLayerTypesForUri( const QString &uri ) const;
400 
417  virtual bool uriIsBlocklisted( const QString &uri ) const;
418 
440  virtual QStringList sidecarFilesForUri( const QString &uri ) const;
441 
456  virtual QList< QgsProviderSublayerDetails > querySublayers( const QString &uri, Qgis::SublayerQueryFlags flags = Qgis::SublayerQueryFlags(), QgsFeedback *feedback = nullptr ) const;
457 
467  virtual QgsDataProvider *createProvider( const QString &uri,
468  const QgsDataProvider::ProviderOptions &options,
469  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
470 
477  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
478 
485  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
486 
487 
488 #ifndef SIP_RUN
489 
495  virtual Qgis::VectorExportResult createEmptyLayer( const QString &uri,
496  const QgsFields &fields,
497  QgsWkbTypes::Type wkbType,
498  const QgsCoordinateReferenceSystem &srs,
499  bool overwrite,
500  QMap<int, int> &oldToNewAttrIdxMap,
501  QString &errorMessage,
502  const QMap<QString, QVariant> *options );
503 #endif
504 
509  virtual QgsRasterDataProvider *createRasterDataProvider(
510  const QString &uri,
511  const QString &format,
512  int nBands,
513  Qgis::DataType type,
514  int width,
515  int height,
516  double *geoTransform,
518  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
519 
524  virtual bool createMeshData(
525  const QgsMesh &mesh,
526  const QString &fileName,
527  const QString &driverName,
528  const QgsCoordinateReferenceSystem &crs ) const;
529 
534  virtual bool createMeshData(
535  const QgsMesh &mesh,
536  const QString &uri,
537  const QgsCoordinateReferenceSystem &crs ) const;
538 
543  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
544 
562  virtual QVariantMap decodeUri( const QString &uri ) const;
563 
572  virtual QString encodeUri( const QVariantMap &parts ) const;
573 
580  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
581 
587  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
588  QStringList &descriptions, QString &errCause );
589 
601  virtual bool styleExists( const QString &uri, const QString &styleId, QString &errorCause SIP_OUT );
602 
610  virtual QString getStyleById( const QString &uri, const QString &styleId, QString &errCause );
611 
616  virtual bool deleteStyleById( const QString &uri, const QString &styleId, QString &errCause );
617 
629  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
630  const QString &styleName, const QString &styleDescription,
631  const QString &uiFileContent, bool useAsDefault, QString &errCause );
632 
637  virtual QString loadStyle( const QString &uri, QString &errCause );
638 
653  virtual bool saveLayerMetadata( const QString &uri, const QgsLayerMetadata &metadata, QString &errorMessage SIP_OUT ) SIP_THROW( QgsNotSupportedException );
654 
659  virtual bool createDb( const QString &dbPath, QString &errCause );
660 
665  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
666 
676  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
677 
687  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
688 
698  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
699 
700 #ifndef SIP_RUN
701 
709  template <typename T> QMap<QString, T *>connections( bool cached = true );
710 
711 
712 #endif
713 
723  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
724 
731  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
732 
739  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
740 
748  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
749 
750 #ifdef SIP_RUN
751  SIP_PYOBJECT __repr__();
752  % MethodCode
753  QString str = QStringLiteral( "<QgsProviderMetadata: %1>" ).arg( sipCpp->key() );
754  sipRes = PyUnicode_FromString( str.toUtf8().constData() );
755  % End
756 #endif
757 
758  signals:
759 
766  void connectionCreated( const QString &name );
767 
774  void connectionDeleted( const QString &name );
775 
783  void connectionChanged( const QString &name );
784 
785  protected:
786 
787 #ifndef SIP_RUN
788 
790  // Common functionality for connections management, to be moved into the class
791  // when all the providers are ready
792  // T_provider_conn: subclass of QgsAbstractProviderConnection,
793  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
794  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
795  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
796  {
797  if ( ! cached || mProviderConnections.isEmpty() )
798  {
799  qDeleteAll( mProviderConnections );
800  mProviderConnections.clear();
801  const auto connNames { T_conn::connectionList() };
802  for ( const auto &cname : connNames )
803  {
804  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
805  }
806  }
807  return mProviderConnections;
808  }
809 
810  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
811  {
812  T_provider_conn conn( name );
813  conn.remove( name );
814  mProviderConnections.clear();
815  emit connectionDeleted( name );
816  }
817  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
819  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
820 
822 
823 #endif
824 
825  private:
826 
828  QString mKey;
829 
831  QString mDescription;
832 
835  QString mLibrary;
836 
837  CreateDataProviderFunction mCreateFunction = nullptr;
838 
839 };
840 
841 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderMetadataCapabilities )
842 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsProviderMetadata::ProviderCapabilities )
843 
844 #endif //QGSPROVIDERMETADATA_H
qgsfields.h
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:107
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:40
Qgis::VectorExportResult
VectorExportResult
Vector layer export result codes.
Definition: qgis.h:449
QgsProviderMetadata::FilterType
FilterType
Type of file filters.
Definition: qgsprovidermetadata.h:347
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsLayerMetadata
A structured metadata store for a map layer.
Definition: qgslayermetadata.h:56
QgsMapLayerType
QgsMapLayerType
Types of layers that can be added to a map.
Definition: qgis.h:46
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:44
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:128
QgsProviderMetadata::ProviderCapability
ProviderCapability
Provider capabilities.
Definition: qgsprovidermetadata.h:201
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:69
QgsTransaction
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Definition: qgstransaction.h:56
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
SIP_TYPEHINT
#define SIP_TYPEHINT(type)
Definition: qgis_sip.h:227
QgsMeshDriverMetadata
Holds metadata about mesh driver.
Definition: qgsprovidermetadata.h:57
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
SIP_DEPRECATED
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
SIP_SKIP
#define SIP_SKIP
Definition: qgis_sip.h:126
SIP_THROW
#define SIP_THROW(name)
Definition: qgis_sip.h:198
QgsProviderMetadata::CreateDataProviderFunction
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags &) > CreateDataProviderFunction
Typedef for data provider creation function.
Definition: qgsprovidermetadata.h:212
QgsDataItemProvider
This is the interface for those who want to add custom data items to the browser tree.
Definition: qgsdataitemprovider.h:44
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
qgis_sip.h
Q_DECLARE_OPERATORS_FOR_FLAGS
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.
QgsMeshDataProvider
Base class for providing data for QgsMeshLayer.
Definition: qgsmeshdataprovider.h:436
QgsProviderSublayerDetails
Contains details about a sub layer available from a dataset.
Definition: qgsprovidersublayerdetails.h:44
QgsProviderConnectionException
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:100
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:211
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:177
str
#define str(x)
Definition: qgis.cpp:37
QgsProviderMetadata::ProviderMetadataCapability
ProviderMetadataCapability
Indicates capabilities of the provider metadata implementation.
Definition: qgsprovidermetadata.h:188
qgsdataprovider.h
qgsexception.h
QgsNotSupportedException
Custom exception class which is raised when an operation is not supported.
Definition: qgsexception.h:117
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:44
QgsDataItem
Base class for all items in the model.
Definition: qgsdataitem.h:45
QgsAbstractDatabaseProviderConnection
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Definition: qgsabstractdatabaseproviderconnection.h:44
QgsRasterDataProvider
Base class for raster data providers.
Definition: qgsrasterdataprovider.h:88
QgsMeshDriverMetadata::MeshDriverCapability
MeshDriverCapability
Flags for the capabilities of the driver.
Definition: qgsprovidermetadata.h:66
qgsabstractproviderconnection.h