Skip to content
Permalink
Browse files
Put some sip code into qgsfeature.h
Just for reference
  • Loading branch information
m-kuhn authored and 3nids committed Mar 30, 2017
1 parent ca008d7 commit bd75aeef4980eac5a9c267c6e6f25740cf0856cd
Showing with 98 additions and 1 deletion.
  1. +11 −1 python/core/qgsfeature.sip
  2. +87 −0 src/core/qgsfeature.h
@@ -7,7 +7,7 @@ typedef QVector<QVariant> QgsAttributes;
%MappedType QgsAttributes
{
%TypeHeaderCode
#include <qgsfeature.h>
#include <qgsfeature.h> // NO_SIPIFY
%End

%ConvertFromTypeCode
@@ -113,6 +113,16 @@ class QgsFeature
#define sipType_QVariant ((sipWrapperType *) sipTypeAsPyTypeObject (sipType_QVariant))
#endif
%End
%Docstring
/** \ingroup core
The feature class encapsulates a single feature including its id,
geometry and a list of field/values attributes.
\note QgsFeature objects are implicitly shared.
@author Gary E.Sherman
/

%End


public:

@@ -44,6 +44,93 @@ typedef qint64 QgsFeatureId;
// key = field index, value = field value
typedef QMap<int, QVariant> QgsAttributeMap;

#ifdef SIP_RUN
typedef QVector<QVariant> QgsAttributes;

// QgsAttributes is implemented as a Python list of Python objects.
% MappedType QgsAttributes
{
% TypeHeaderCode
#include <qgsfeature.h> // NO_SIPIFY
% 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 )
{
QVariant *v = new QVariant( sipCpp->at( i ) );
PyObject *tobj;

if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant, 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_QVariant, SIP_NOT_NONE ) )
return 0;

return 1;
}

QgsAttributes *qv = new QgsAttributes;

for ( SIP_SSIZE_T i = 0; i < PyList_GET_SIZE( sipPy ); ++i )
{
int state;
PyObject *obj = PyList_GET_ITEM( sipPy, i );
QVariant *t;
if ( obj == Py_None )
{
t = new QVariant( QVariant::Int );
}
else
{
t = reinterpret_cast<QVariant *>( sipConvertToType( obj, sipType_QVariant, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr ) );

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

delete qv;
return 0;
}
}

qv->append( *t );

sipReleaseType( t, sipType_QVariant, state );
}

*sipCppPtr = qv;

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

/***************************************************************************
* This class is considered CRITICAL and any change MUST be accompanied with
* full unit tests in testqgsfeature.cpp.

0 comments on commit bd75aee

Please sign in to comment.