QGIS API Documentation  3.2.0-Bonn (bc43194)
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 "qgis.h"
25 #include "qgsdataprovider.h"
26 #include "qgis_core.h"
27 #include <functional>
28 
46 class CORE_EXPORT QgsProviderMetadata
47 {
48  public:
49 
54  SIP_SKIP typedef std::function < QgsDataProvider*( const QString &, const QgsDataProvider::ProviderOptions & ) > CreateDataProviderFunction;
55 
56  QgsProviderMetadata( const QString &_key, const QString &_description, const QString &_library );
57 
63 #ifndef SIP_RUN
64  QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
65 #else
66  QgsProviderMetadata( const QString &key, const QString &description, SIP_PYCALLABLE / AllowNone / );
67  % MethodCode
68 
69  // Make sure the callable doesn't get garbage collected, this is needed because refcount for a2 is 0
70  // and the creation function pointer is passed to the metadata and it needs to be kept in memory.
71  Py_INCREF( a2 );
72 
73  Py_BEGIN_ALLOW_THREADS
74 
75  sipCpp = new QgsProviderMetadata( *a0, *a1, [a2]( const QString &dataSource, const QgsDataProvider::ProviderOptions &providerOptions ) -> QgsDataProvider*
76  {
77  QgsDataProvider *provider;
78  provider = nullptr;
79  PyObject *sipResObj;
80  SIP_BLOCK_THREADS
81 
82  sipResObj = sipCallMethod( nullptr, a2, "DD", new QString( dataSource ), sipType_QString, nullptr, new QgsDataProvider::ProviderOptions( providerOptions ), sipType_QgsDataProvider_ProviderOptions, NULL );
83 
84  if ( sipResObj )
85  {
86  if ( sipCanConvertToType( sipResObj, sipType_QgsDataProvider, SIP_NOT_NONE ) )
87  {
88  int state0;
89  int sipIsErr = 0;
90  provider = reinterpret_cast<QgsDataProvider *>( sipConvertToType( sipResObj, sipType_QgsDataProvider, nullptr, SIP_NOT_NONE, &state0, &sipIsErr ) );
91  if ( sipIsErr != 0 )
92  {
93  sipReleaseType( provider, sipType_QgsDataProvider, state0 );
94  provider = nullptr;
95  }
96  }
97  }
98  SIP_UNBLOCK_THREADS
99  return provider;
100  } );
101 
102  Py_END_ALLOW_THREADS
103 
104  % End
105 #endif
106 
112  QString key() const;
113 
119  QString description() const;
120 
126  QString library() const;
127 
134  SIP_SKIP CreateDataProviderFunction createFunction() const;
135 
136  private:
137 
139  QString key_;
140 
142  QString description_;
143 
145  QString library_;
146 
147  CreateDataProviderFunction mCreateFunc = nullptr;
148 
149 };
150 
151 #endif //QGSPROVIDERMETADATA_H
152 
Abstract base class for spatial data provider implementations.
#define SIP_SKIP
Definition: qgis_sip.h:119
std::function< QgsDataProvider *(const QString &, const QgsDataProvider::ProviderOptions &) > CreateDataProviderFunction
Typedef for data provider creation function.
Setting options for creating vector data providers.
Holds data provider key, description, and associated shared library file or function pointer informat...