Skip to content

Commit 839a889

Browse files
committed
SIP wrappers for QgsProviderMetadata
1 parent 9d66eb8 commit 839a889

File tree

2 files changed

+90
-1
lines changed

2 files changed

+90
-1
lines changed

python/core/auto_generated/qgsprovidermetadata.sip.in

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,54 @@ library object.
3636

3737
QgsProviderMetadata( const QString &_key, const QString &_description, const QString &_library );
3838

39+
QgsProviderMetadata( const QString &key, const QString &description, SIP_PYCALLABLE / AllowNone / );
40+
%Docstring
41+
Metadata for provider with direct provider creation function pointer, where
42+
no library is involved.
43+
44+
.. versionadded:: 3.0
45+
46+
.. note::
47+
48+
not available in Python bindings
49+
%End
50+
%MethodCode
51+
52+
// Make sure the callable doesn't get garbage collected
53+
Py_INCREF( a2 );
54+
55+
Py_BEGIN_ALLOW_THREADS
56+
57+
sipCpp = new QgsProviderMetadata( *a0, *a1, [a2]( const QString &dataSource ) -> QgsDataProvider*
58+
{
59+
QgsDataProvider *provider;
60+
provider = nullptr;
61+
PyObject *sipResObj;
62+
SIP_BLOCK_THREADS
63+
64+
sipResObj = sipCallMethod( NULL, a2, "N", new QString( dataSource ), sipType_QString, NULL );
65+
Py_DECREF( a2 );
66+
if ( sipResObj )
67+
{
68+
// Py_DECREF(sipResObj);
69+
if ( sipCanConvertToType( sipResObj, sipType_QgsDataProvider, SIP_NOT_NONE ) )
70+
{
71+
int state0;
72+
int sipIsErr = 0;
73+
provider = reinterpret_cast<QgsDataProvider *>( sipConvertToType( sipResObj, sipType_QgsDataProvider, NULL, SIP_NOT_NONE, &state0, &sipIsErr ) );
74+
if ( sipIsErr != 0 )
75+
{
76+
provider = nullptr;
77+
}
78+
}
79+
}
80+
SIP_UNBLOCK_THREADS
81+
return provider;
82+
} );
83+
84+
Py_END_ALLOW_THREADS
85+
86+
%End
3987

4088
QString key() const;
4189
%Docstring

src/core/qgsprovidermetadata.h

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,48 @@ class CORE_EXPORT QgsProviderMetadata
6161
* \note not available in Python bindings
6262
* \since QGIS 3.0
6363
*/
64-
SIP_SKIP QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
64+
#ifndef SIP_RUN
65+
QgsProviderMetadata( const QString &key, const QString &description, const QgsProviderMetadata::CreateDataProviderFunction &createFunc );
66+
#else
67+
QgsProviderMetadata( const QString &key, const QString &description, SIP_PYCALLABLE / AllowNone / );
68+
% MethodCode
69+
70+
// Make sure the callable doesn't get garbage collected
71+
Py_INCREF( a2 );
72+
73+
Py_BEGIN_ALLOW_THREADS
74+
75+
sipCpp = new QgsProviderMetadata( *a0, *a1, [a2]( const QString &dataSource ) -> QgsDataProvider*
76+
{
77+
QgsDataProvider *provider;
78+
provider = nullptr;
79+
PyObject *sipResObj;
80+
SIP_BLOCK_THREADS
81+
82+
sipResObj = sipCallMethod( NULL, a2, "N", new QString( dataSource ), sipType_QString, NULL );
83+
Py_DECREF( a2 );
84+
if ( sipResObj )
85+
{
86+
// Py_DECREF(sipResObj);
87+
if ( sipCanConvertToType( sipResObj, sipType_QgsDataProvider, SIP_NOT_NONE ) )
88+
{
89+
int state0;
90+
int sipIsErr = 0;
91+
provider = reinterpret_cast<QgsDataProvider *>( sipConvertToType( sipResObj, sipType_QgsDataProvider, NULL, SIP_NOT_NONE, &state0, &sipIsErr ) );
92+
if ( sipIsErr != 0 )
93+
{
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
65106

66107
/**
67108
* This returns the unique key associated with the provider

0 commit comments

Comments
 (0)