QGIS API Documentation  3.10.0-A Coruña (6c816b4204)
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 
46 
64 class CORE_EXPORT QgsProviderMetadata
65 {
66  public:
67 
72  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions & ) > CreateDataProviderFunction;
73 
80  QgsProviderMetadata( const QString &key, const QString &description, const QString &library = QString() );
81 
88  SIP_SKIP Q_DECL_DEPRECATED QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
89 
91  virtual ~QgsProviderMetadata();
92 
98  QString key() const;
99 
105  QString description() const;
106 
114  Q_DECL_DEPRECATED QString library() const SIP_DEPRECATED;
115 
123  SIP_SKIP Q_DECL_DEPRECATED CreateDataProviderFunction createFunction() const;
124 
129  virtual void initProvider();
130 
135  virtual void cleanupProvider();
136 
141  enum class FilterType
142  {
143  FilterVector = 1,
144  FilterRaster,
145  FilterMesh,
146  FilterMeshDataset
147  };
148 
156  virtual QString filters( FilterType type );
157 
162  virtual QgsDataProvider *createProvider( const QString &uri, const QgsDataProvider::ProviderOptions &options ) SIP_FACTORY;
163 
164 #ifndef SIP_RUN
165 
171  virtual QgsVectorLayerExporter::ExportError createEmptyLayer( const QString &uri,
172  const QgsFields &fields,
173  QgsWkbTypes::Type wkbType,
174  const QgsCoordinateReferenceSystem &srs,
175  bool overwrite,
176  QMap<int, int> &oldToNewAttrIdxMap,
177  QString &errorMessage,
178  const QMap<QString, QVariant> *options );
179 #endif
180 
185  virtual QgsRasterDataProvider *createRasterDataProvider(
186  const QString &uri,
187  const QString &format,
188  int nBands,
189  Qgis::DataType type,
190  int width,
191  int height,
192  double *geoTransform,
194  const QStringList &createOptions = QStringList() ) SIP_FACTORY;
195 
200  virtual QList<QPair<QString, QString> > pyramidResamplingMethods();
201 
209  virtual QVariantMap decodeUri( const QString &uri );
210 
217  virtual QList< QgsDataItemProvider * > dataItemProviders() const SIP_FACTORY;
218 
224  virtual int listStyles( const QString &uri, QStringList &ids, QStringList &names,
225  QStringList &descriptions, QString &errCause );
226 
231  virtual QString getStyleById( const QString &uri, QString styleId, QString &errCause );
232 
237  virtual bool deleteStyleById( const QString &uri, QString styleId, QString &errCause );
238 
243  virtual bool saveStyle( const QString &uri, const QString &qmlStyle, const QString &sldStyle,
244  const QString &styleName, const QString &styleDescription,
245  const QString &uiFileContent, bool useAsDefault, QString &errCause );
246 
251  virtual QString loadStyle( const QString &uri, QString &errCause );
252 
257  virtual bool createDb( const QString &dbPath, QString &errCause );
258 
263  virtual QgsTransaction *createTransaction( const QString &connString ) SIP_FACTORY;
264 
274  virtual QMap<QString, QgsAbstractProviderConnection *> connections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
275 
285  QMap<QString, QgsAbstractDatabaseProviderConnection *> dbConnections( bool cached = true ) SIP_THROW( QgsProviderConnectionException );
286 
296  QgsAbstractProviderConnection *findConnection( const QString &name, bool cached = true ) SIP_THROW( QgsProviderConnectionException );
297 
298 #ifndef SIP_RUN
299 
307  template <typename T> QMap<QString, T *>connections( bool cached = true );
308 
309 
310 #endif
311 
320  virtual QgsAbstractProviderConnection *createConnection( const QString &uri, const QVariantMap &configuration ) SIP_FACTORY;
321 
327  virtual QgsAbstractProviderConnection *createConnection( const QString &name );
328 
335  virtual void deleteConnection( const QString &name ) SIP_THROW( QgsProviderConnectionException );
336 
343  virtual void saveConnection( const QgsAbstractProviderConnection *connection, const QString &name );
344 
345  protected:
346 
347 #ifndef SIP_RUN
348 
350  // Common functionality for connections management, to be moved into the class
351  // when all the providers are ready
352  // T_provider_conn: subclass of QgsAbstractProviderConnection,
353  // T_conn: provider connection class (such as QgsOgrDbConnection or QgsPostgresConn)
354  // TODO QGIS4: remove all old provider conn classes and move functionality into QgsAbstractProviderConnection subclasses
355  template <class T_provider_conn, class T_conn> QMap<QString, QgsAbstractProviderConnection *> connectionsProtected( bool cached = true )
356  {
357  if ( ! cached || mProviderConnections.isEmpty() )
358  {
359  qDeleteAll( mProviderConnections );
360  mProviderConnections.clear();
361  const auto connNames { T_conn::connectionList() };
362  for ( const auto &cname : connNames )
363  {
364  mProviderConnections.insert( cname, new T_provider_conn( cname ) );
365  }
366  }
367  return mProviderConnections;
368  }
369 
370  template <class T_provider_conn> void deleteConnectionProtected( const QString &name )
371  {
372  T_provider_conn conn( name );
373  conn.remove( name );
374  mProviderConnections.clear();
375  }
376  virtual void saveConnectionProtected( const QgsAbstractProviderConnection *connection, const QString &name );
378  QMap<QString, QgsAbstractProviderConnection *> mProviderConnections;
379 
381 #endif
382 
383  private:
384 
386  QString mKey;
387 
389  QString mDescription;
390 
393  QString mLibrary;
394 
395  CreateDataProviderFunction mCreateFunction = nullptr;
396 
397 };
398 
399 #endif //QGSPROVIDERMETADATA_H
DataType
Raster data types.
Definition: qgis.h:80
Container of fields for a vector layer.
Definition: qgsfields.h:42
Abstract base class for spatial data provider implementations.
const QgsCoordinateReferenceSystem & crs
The QgsAbstractProviderConnection provides an interface for data provider connections.
Type
The WKB type describes the number of dimensions a geometry has.
Definition: qgswkbtypes.h:68
#define SIP_SKIP
Definition: qgis_sip.h:126
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &) > CreateDataProviderFunction
Typedef for data provider creation function.
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_DEPRECATED
Definition: qgis_sip.h:106
Base class for all items in the model.
Definition: qgsdataitem.h:49
Setting options for creating vector data providers.
Holds data provider key, description, and associated shared library file or function pointer informat...
This class allows including a set of layers in a database-side transaction, provided the layer data p...
This class represents a coordinate reference system (CRS).
#define SIP_THROW(name)
Definition: qgis_sip.h:184
FilterType
Type of file filters.
This is the interface for those who want to add custom data items to the browser tree.
Custom exception class for provider connection related exceptions.
Definition: qgsexception.h:100
Base class for raster data providers.