Skip to content

Commit

Permalink
python: represent NULL attributes as QPyNullVariant
Browse files Browse the repository at this point in the history
  • Loading branch information
m-kuhn committed Aug 28, 2013
1 parent 7aec0d4 commit 52ab06e
Showing 1 changed file with 13 additions and 38 deletions.
51 changes: 13 additions & 38 deletions python/core/qgsfeature.sip
Expand Up @@ -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;
Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 52ab06e

Please sign in to comment.