QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
37 #include "qgsfields.h"
38 #include "qgsexception.h"
39 
40 class QgsDataItem;
42 class QgsTransaction;
43 
46 struct QgsMesh;
47 
54 class CORE_EXPORT QgsMeshDriverMetadata
55 {
56  Q_GADGET
57 
58  public:
59 
64  {
65  CanWriteFaceDatasets = 1 << 0,
66  CanWriteVertexDatasets = 1 << 1,
67  CanWriteEdgeDatasets = 1 << 2,
68  CanWriteMeshData = 1 << 3,
69  };
70 
71  Q_ENUM( MeshDriverCapability )
72  Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
73  Q_FLAG( MeshDriverCapabilities )
74 
75 
77 
85  QgsMeshDriverMetadata( const QString &name,
86  const QString &description,
87  const MeshDriverCapabilities &capabilities,
88  const QString &writeDatasetOnFileSuffix );
89 
93  MeshDriverCapabilities capabilities() const;
94 
98  QString name() const;
99 
103  QString description() const;
104 
108  QString writeDatasetOnFileSuffix() const;
109 
110  private:
111  QString mName;
112  QString mDescription;
113  MeshDriverCapabilities mCapabilities;
114  QString mWriteDatasetOnFileSuffix;
115 };
116 
117 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMeshDriverMetadata::MeshDriverCapabilities )
118 
136 class CORE_EXPORT QgsProviderMetadata : public QObject
137 {
138  Q_OBJECT
139 
140  public:
141 
146  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags & ) > CreateDataProviderFunction;
147 
154  QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
155 
162  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
163 
165  virtual ~QgsProviderMetadata();
166 
172  QString key() const;
173 
179  QString description() const;
180 
188  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
189 
197  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
198 
203  virtual void initProvider();
204 
209  virtual void cleanupProvider();
210 
215  enum class FilterType
216  {
217  FilterVector = 1,
218  FilterRaster,
219  FilterMesh,
220  FilterMeshDataset
221  };
222 
230  virtual QString filters( FilterType type );
231 
237  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
238 
248  virtual QgsDataProvider *createProvider( const QString &uri,
249  const QgsDataProvider::ProviderOptions &options,
250  QgsDataProvider::ReadFlags flags = QgsDataProvider::ReadFlags() ) SIP_FACTORY;
251 
258  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
259 
266  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
267 
268 
269 #ifndef SIP_RUN
270 
276  virtual QgsVectorLayerExporter::ExportError createEmptyLayer( const QString &uri,
277  const QgsFields &fields,
278  QgsWkbTypes::Type wkbType,
279  const QgsCoordinateReferenceSystem &srs,
280  bool overwrite,
281  QMap<int, int> &oldToNewAttrIdxMap,
282  QString &errorMessage,
283  const QMap<QString, QVariant> *options );
284 #endif
285 
290  virtual QgsRasterDataProvider *createRasterDataProvider(
291  const QString &uri,
292  const QString &format,
293  int nBands,
294  Qgis::DataType type,
295  int width,
296  int height,
297  double *geoTransform,
299  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
300 
305  virtual bool createMeshData(
306  const QgsMesh &mesh,
307  const QString uri,
308  const QString &driverName,
309  const QgsCoordinateReferenceSystem &crs ) const;
310 
315  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
316 
334  virtual QVariantMap decodeUri( const QString &uri );
335 
344  virtual QString encodeUri( const QVariantMap &parts );
345 
352  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
353 
359  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
360  QStringList &descriptions, QString &errCause );
361 
366  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
367 
372  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
373 
378  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
379  const QString &styleName, const QString &styleDescription,
380  const QString &uiFileContent, bool useAsDefault, QString &errCause );
381 
386  virtual QString loadStyle( const QString &uri, QString &errCause );
387 
392  virtual bool createDb( const QString &dbPath, QString &errCause );
393 
398  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
399 
409  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
410 
420  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
421 
431  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
432 
433 #ifndef SIP_RUN
434 
442  template <typename T> QMap<QString, T *>connections( bool cached = true );
443 
444 
445 #endif
446 
456  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
457 
464  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
465 
472  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
473 
481  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
482 
483  signals:
484 
491  void connectionCreated( const QString &name );
492 
499  void connectionDeleted( const QString &name );
500 
508  void connectionChanged( const QString &name );
509 
510  protected:
511 
512 #ifndef SIP_RUN
513 
515  // Common functionality for connections management, to be moved into the class
516  // when all the providers are ready
517  // T_provider_conn: subclass of QgsAbstractProviderConnection,
518  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
519  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
520  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
521  {
522  if ( ! cached || mProviderConnections.isEmpty() )
523  {
524  qDeleteAll( mProviderConnections );
525  mProviderConnections.clear();
526  const auto connNames { T_conn::connectionList() };
527  for ( const auto &cname : connNames )
528  {
529  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
530  }
531  }
532  return mProviderConnections;
533  }
534 
535  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
536  {
537  T_provider_conn conn( name );
538  conn.remove( name );
539  mProviderConnections.clear();
540  emit connectionDeleted( name );
541  }
542  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
544  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
545 
547 #endif
548 
549  private:
550 
552  QString mKey;
553 
555  QString mDescription;
556 
559  QString mLibrary;
560 
561  CreateDataProviderFunction mCreateFunction = nullptr;
562 
563 };
564 
565 #endif //QGSPROVIDERMETADATA_H
qgsfields.h
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:102
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:105
QgsDataProvider
Abstract base class for spatial data provider implementations.
Definition: qgsdataprovider.h:42
QgsProviderMetadata::FilterType
FilterType
Type of file filters.
Definition: qgsprovidermetadata.h:216
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:51
QgsFields
Container of fields for a vector layer.
Definition: qgsfields.h:45
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:70
QgsTransaction
This class allows including a set of layers in a database-side transaction, provided the layer data p...
Definition: qgstransaction.h:57
QgsMesh
Mesh - vertices, edges and faces.
Definition: qgsmeshdataprovider.h:58
QgsMeshDriverMetadata
Holds metadata about mesh driver.
Definition: qgsprovidermetadata.h:55
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:189
QgsProviderMetadata::CreateDataProviderFunction
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &, QgsDataProvider::ReadFlags &) > CreateDataProviderFunction
Typedef for data provider creation function.
Definition: qgsprovidermetadata.h:146
QgsDataItemProvider
This is the interface for those who want to add custom data items to the browser tree.
Definition: qgsdataitemprovider.h:46
QgsProviderMetadata::connectionCreated
void connectionCreated(const QString &name)
Emitted when a connection with the specified name is created.
QgsProviderMetadata::connectionDeleted
void connectionDeleted(const QString &name)
Emitted when the connection with the specified name was deleted.
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:398
QgsProviderConnectionException
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:101
QgsCoordinateReferenceSystem
This class represents a coordinate reference system (CRS).
Definition: qgscoordinatereferencesystem.h:206
QgsProviderMetadata
Holds data provider key, description, and associated shared library file or function pointer informat...
Definition: qgsprovidermetadata.h:137
QgsVectorLayerExporter::ExportError
ExportError
Error codes.
Definition: qgsvectorlayerexporter.h:52
qgsvectorlayerexporter.h
qgsdataprovider.h
qgsexception.h
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:45
QgsProviderMetadata::connectionChanged
void connectionChanged(const QString &name)
Emitted when the connection with the specified name is changed, e.g.
QgsDataItem
Base class for all items in the model.
Definition: qgsdataitem.h:51
qgsabstractdatabaseproviderconnection.h
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:89
QgsMeshDriverMetadata::MeshDriverCapability
MeshDriverCapability
Flags for the capabilities of the driver.
Definition: qgsprovidermetadata.h:64
qgsabstractproviderconnection.h