python: represent NULL attributes as QPyNullVariant

This commit is contained in:
Matthias Kuhn 2013-08-28 12:09:11 +02:00
parent 7aec0d4019
commit 52ab06e295

View File

@ -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.