Skip to content

Commit

Permalink
Allow conversion of QgsFeatureStoreList results to Python objects
Browse files Browse the repository at this point in the history
Fixes #39479
  • Loading branch information
nyalldawson committed Oct 21, 2020
1 parent 0920242 commit 49c5089
Show file tree
Hide file tree
Showing 3 changed files with 158 additions and 2 deletions.
77 changes: 76 additions & 1 deletion python/core/auto_generated/qgsfeaturestore.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,82 @@ Returns the map of optional parameters.

};

typedef QList<QgsFeatureStore> QgsFeatureStoreList;
typedef QVector<QgsFeatureStore> QgsFeatureStoreList;

%MappedType QgsFeatureStoreList
{
%TypeHeaderCode
#include "qgsfeaturestore.h"
%End

%ConvertFromTypeCode
// Create the list.
PyObject *l;

if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
return NULL;

// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM( l, i, tobj );
}

return l;
%End

%ConvertToTypeCode
// Check the type if that is all that is required.
if ( sipIsErr == NULL )
{
if ( !PyList_Check( sipPy ) )
return 0;

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
return 0;

return 1;
}

QgsFeatureStoreList *qv = new QgsFeatureStoreList;
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
qv->reserve( listSize );

for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
{
PyObject *obj = PyList_GET_ITEM( sipPy, i );
int state;
QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
sipReleaseType( t, sipType_QgsFeatureStore, state );

delete qv;
return 0;
}

qv->append( *t );
sipReleaseType( t, sipType_QgsFeatureStore, state );
}

*sipCppPtr = qv;

return sipGetState( sipTransferObj );
%End
};



Expand Down
2 changes: 2 additions & 0 deletions src/core/qgsapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
#include "qgsconnectionregistry.h"
#include "qgsremappingproxyfeaturesink.h"
#include "qgsmeshlayer.h"
#include "qgsfeaturestore.h"

#include "gps/qgsgpsconnectionregistry.h"
#include "processing/qgsprocessingregistry.h"
Expand Down Expand Up @@ -224,6 +225,7 @@ void QgsApplication::init( QString profileFolder )
qRegisterMetaType<QgsFeatureId>( "QgsFeatureId" );
qRegisterMetaType<QgsFeatureIds>( "QgsFeatureIds" );
qRegisterMetaType<QgsProperty>( "QgsProperty" );
qRegisterMetaType<QgsFeatureStoreList>( "QgsFeatureStoreList" );
qRegisterMetaType<Qgis::MessageLevel>( "Qgis::MessageLevel" );
qRegisterMetaType<QgsReferencedRectangle>( "QgsReferencedRectangle" );
qRegisterMetaType<QgsReferencedPointXY>( "QgsReferencedPointXY" );
Expand Down
81 changes: 80 additions & 1 deletion src/core/qgsfeaturestore.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,86 @@ class CORE_EXPORT QgsFeatureStore : public QgsFeatureSink
QMap<QString, QVariant> mParams;
};

typedef QList<QgsFeatureStore> QgsFeatureStoreList;
#ifndef SIP_RUN
typedef QVector<QgsFeatureStore> QgsFeatureStoreList;
#else
typedef QVector<QgsFeatureStore> QgsFeatureStoreList;

% MappedType QgsFeatureStoreList
{
% TypeHeaderCode
#include "qgsfeaturestore.h"
% End

% ConvertFromTypeCode
// Create the list.
PyObject *l;

if ( ( l = PyList_New( sipCpp->size() ) ) == NULL )
return NULL;

// Set the list elements.
for ( int i = 0; i < sipCpp->size(); ++i )
{
QgsFeatureStore *v = new QgsFeatureStore( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QgsFeatureStore, Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM( l, i, tobj );
}

return l;
% End

% ConvertToTypeCode
// Check the type if that is all that is required.
if ( sipIsErr == NULL )
{
if ( !PyList_Check( sipPy ) )
return 0;

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
if ( !sipCanConvertToType( PyList_GET_ITEM( sipPy, i ), sipType_QgsFeatureStore, SIP_NOT_NONE ) )
return 0;

return 1;
}

QgsFeatureStoreList *qv = new QgsFeatureStoreList;
SIP_SSIZE_T listSize = PyList_GET_SIZE( sipPy );
qv->reserve( listSize );

for ( SIP_SSIZE_T i = 0; i < listSize; ++i )
{
PyObject *obj = PyList_GET_ITEM( sipPy, i );
int state;
QgsFeatureStore *t = reinterpret_cast<QgsFeatureStore *>( sipConvertToType( obj, sipType_QgsFeatureStore, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

if ( *sipIsErr )
{
sipReleaseType( t, sipType_QgsFeatureStore, state );

delete qv;
return 0;
}

qv->append( *t );
sipReleaseType( t, sipType_QgsFeatureStore, state );
}

*sipCppPtr = qv;

return sipGetState( sipTransferObj );
% End
};
#endif

Q_DECLARE_METATYPE( QgsFeatureStore )

Expand Down

0 comments on commit 49c5089

Please sign in to comment.