mirror of
https://github.com/qgis/QGIS.git
synced 2025-02-25 00:58:06 -05:00
Put some sip code into qgsfeature.h
Just for reference
This commit is contained in:
parent
ca008d7a48
commit
bd75aeef49
@ -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.
|
||||
|
Loading…
x
Reference in New Issue
Block a user