Skip to content
Permalink
Browse files

python: represent NULL attributes as QPyNullVariant

  • Loading branch information
m-kuhn committed Aug 28, 2013
1 parent 7aec0d4 commit 52ab06e295a29b523c6012d44c63c68ccf9690a0
Showing with 13 additions and 38 deletions.
  1. +13 −38 python/core/qgsfeature.sip
@@ -16,28 +16,24 @@ typedef QVector<QVariant> QgsAttributes;
// Create the list.
PyObject *l;

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

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

if ( v->isNull() )
{
Py_INCREF( Py_None );
tobj = Py_None;
delete v;
}
else if ((tobj = sipConvertFromNewType(v, sipType_QVariant,Py_None)) == NULL)
if ( ( tobj = sipConvertFromNewType( v, sipType_QVariant,Py_None ) ) == NULL )
{
Py_DECREF( l );
delete v;

return NULL;
}

PyList_SET_ITEM(l, i, tobj);
PyList_SET_ITEM( l, i, tobj );
}

return l;
@@ -132,17 +128,8 @@ class QgsFeature
}
else
{
QVariant* v = new QVariant(attrs.at(a0));
if ( v->isNull() )
{
delete v;
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
{
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
QVariant* v = new QVariant( attrs.at(a0) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End

@@ -156,14 +143,8 @@ class QgsFeature
}
else
{
QVariant v = sipCpp->attribute(fieldIdx);
if ( v.isNull() )
{
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
sipRes = sipConvertFromType( &v, sipType_QVariant, Py_None );
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End

@@ -404,14 +385,8 @@ class QgsFeature
}
else
{
QVariant v = sipCpp->attribute(fieldIdx);
if ( v.isNull() )
{
Py_INCREF( Py_None );
sipRes = Py_None;
}
else
sipRes = sipConvertFromType( &v, sipType_QVariant, Py_None );
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
}
%End
/** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.

0 comments on commit 52ab06e

Please sign in to comment.
You can’t perform that action at this time.