QGIS API Documentation  3.14.0-Pi (9f7028fd23)
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 
45 
52 class CORE_EXPORT QgsMeshDriverMetadata
53 {
54  Q_GADGET
55 
56  public:
57 
62  {
63  CanWriteFaceDatasets = 1 << 0,
64  CanWriteVertexDatasets = 1 << 1,
65  CanWriteEdgeDatasets = 1 << 2,
66  };
67 
68  Q_ENUM( MeshDriverCapability )
69  Q_DECLARE_FLAGS( MeshDriverCapabilities, MeshDriverCapability )
70  Q_FLAG( MeshDriverCapabilities )
71 
72 
74 
82  QgsMeshDriverMetadata( const QString &name,
83  const QString &description,
84  const MeshDriverCapabilities &capabilities );
85 
89  MeshDriverCapabilities capabilities() const;
90 
94  QString name() const;
95 
99  QString description() const;
100 
101  private:
102  QString mName;
103  QString mDescription;
104  MeshDriverCapabilities mCapabilities;
105 };
106 
107 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMeshDriverMetadata::MeshDriverCapabilities )
108 
109 
126 class CORE_EXPORT QgsProviderMetadata : public QObject
127 {
128  Q_OBJECT
129 
130  public:
131 
136  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions & ) > CreateDataProviderFunction;
137 
144  QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
145 
152  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
153 
155  virtual ~QgsProviderMetadata();
156 
162  QString key() const;
163 
169  QString description() const;
170 
178  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
179 
187  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
188 
193  virtual void initProvider();
194 
199  virtual void cleanupProvider();
200 
205  enum class FilterType
206  {
207  FilterVector = 1,
208  FilterRaster,
209  FilterMesh,
210  FilterMeshDataset
211  };
212 
220  virtual QString filters( FilterType type );
221 
227  virtual QList<QgsMeshDriverMetadata> meshDriversMetadata();
228 
233  virtual QgsDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options ) SIP_FACTORY;
234 
241  static void setBoolParameter( QVariantMap &uri, const QString &parameter, const QVariant &value );
242 
249  static bool boolParameter( const QVariantMap &uri, const QString &parameter, bool defaultValue = false );
250 
251 
252 #ifndef SIP_RUN
253 
259  virtual QgsVectorLayerExporter::ExportError createEmptyLayer( const QString &uri,
260  const QgsFields &fields,
261  QgsWkbTypes::Type wkbType,
262  const QgsCoordinateReferenceSystem &srs,
263  bool overwrite,
264  QMap<int, int> &oldToNewAttrIdxMap,
265  QString &errorMessage,
266  const QMap<QString, QVariant> *options );
267 #endif
268 
273  virtual QgsRasterDataProvider *createRasterDataProvider(
274  const QString &uri,
275  const QString &format,
276  int nBands,
277  Qgis::DataType type,
278  int width,
279  int height,
280  double *geoTransform,
282  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
283 
288  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
289 
307  virtual QVariantMap decodeUri( const QString &uri );
308 
317  virtual QString encodeUri( const QVariantMap &parts );
318 
325  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
326 
332  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
333  QStringList &descriptions, QString &errCause );
334 
339  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
340 
345  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
346 
351  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
352  const QString &styleName, const QString &styleDescription,
353  const QString &uiFileContent, bool useAsDefault, QString &errCause );
354 
359  virtual QString loadStyle( const QString &uri, QString &errCause );
360 
365  virtual bool createDb( const QString &dbPath, QString &errCause );
366 
371  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
372 
382  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
383 
393  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
394 
404  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
405 
406 #ifndef SIP_RUN
407 
415  template <typename T> QMap<QString, T *>connections( bool cached = true );
416 
417 
418 #endif
419 
429  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_THROW( QgsProviderConnectionException ) SIP_FACTORY;
430 
437  virtual QgsAbstractProviderConnection *createConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
438 
445  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
446 
454  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name ) SIP_THROW( QgsProviderConnectionException );
455 
456  signals:
457 
464  void connectionCreated( const QString &name );
465 
472  void connectionDeleted( const QString &name );
473 
481  void connectionChanged( const QString &name );
482 
483  protected:
484 
485 #ifndef SIP_RUN
486 
488  // Common functionality for connections management, to be moved into the class
489  // when all the providers are ready
490  // T_provider_conn: subclass of QgsAbstractProviderConnection,
491  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
492  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
493  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
494  {
495  if ( ! cached || mProviderConnections.isEmpty() )
496  {
497  qDeleteAll( mProviderConnections );
498  mProviderConnections.clear();
499  const auto connNames { T_conn::connectionList() };
500  for ( const auto &cname : connNames )
501  {
502  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
503  }
504  }
505  return mProviderConnections;
506  }
507 
508  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
509  {
510  T_provider_conn conn( name );
511  conn.remove( name );
512  mProviderConnections.clear();
513  emit connectionDeleted( name );
514  }
515  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
517  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
518 
520 #endif
521 
522  private:
523 
525  QString mKey;
526 
528  QString mDescription;
529 
532  QString mLibrary;
533 
534  CreateDataProviderFunction mCreateFunction = nullptr;
535 
536 };
537 
538 #endif //QGSPROVIDERMETADATA_H
qgsfields.h
Qgis::DataType
DataType
Raster data types.
Definition: qgis.h:114
QgsDataProvider::ProviderOptions
Setting options for creating vector data providers.
Definition: qgsdataprovider.h:104
QgsDataProvider
Definition: qgsdataprovider.h:41
QgsProviderMetadata::CreateDataProviderFunction
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &) > CreateDataProviderFunction
Typedef for data provider creation function.
Definition: qgsprovidermetadata.h:136
QgsProviderMetadata::FilterType
FilterType
Type of file filters.
Definition: qgsprovidermetadata.h:205
crs
const QgsCoordinateReferenceSystem & crs
Definition: qgswfsgetfeature.cpp:105
QgsFields
Definition: qgsfields.h:44
QgsWkbTypes::Type
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
QgsTransaction
Definition: qgstransaction.h:56
QgsMeshDriverMetadata
Definition: qgsprovidermetadata.h:52
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:184
QgsDataItemProvider
Definition: qgsdataitemprovider.h:45
qgis_sip.h
QgsProviderConnectionException
Definition: qgsexception.h:100
QgsCoordinateReferenceSystem
Definition: qgscoordinatereferencesystem.h:206
QgsProviderMetadata
Definition: qgsprovidermetadata.h:126
QgsVectorLayerExporter::ExportError
ExportError
Error codes.
Definition: qgsvectorlayerexporter.h:51
qgsvectorlayerexporter.h
qgsdataprovider.h
qgsexception.h
QgsAbstractProviderConnection
The QgsAbstractProviderConnection provides an interface for data provider connections.
Definition: qgsabstractproviderconnection.h:44
QgsDataItem
Definition: qgsdataitem.h:49
qgsabstractdatabaseproviderconnection.h
QgsAbstractDatabaseProviderConnection
The QgsAbstractDatabaseProviderConnection class provides common functionality for DB based connection...
Definition: qgsabstractdatabaseproviderconnection.h:40
QgsRasterDataProvider
Definition: qgsrasterdataprovider.h:88
QgsMeshDriverMetadata::MeshDriverCapability
MeshDriverCapability
Flags for the capabilities of the driver.
Definition: qgsprovidermetadata.h:61
qgsabstractproviderconnection.h