Showing with 63 additions and 4 deletions.
  1. +3 −1 python/analysis/analysis.sip
  2. +3 −1 python/core/core.sip
  3. +54 −0 python/core/qgsfeature.sip
  4. +3 −2 python/gui/gui.sip
4 changes: 3 additions & 1 deletion python/analysis/analysis.sip
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%Module qgis.analysis 0
%Module(name=qgis.analysis,
version=0,
keyword_arguments="Optional")

%Import QtCore/QtCoremod.sip
%Import QtGui/QtGuimod.sip
Expand Down
4 changes: 3 additions & 1 deletion python/core/core.sip
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
%Module qgis.core 0
%Module(name=qgis.core,
version=0,
keyword_arguments="Optional")

%Import QtCore/QtCoremod.sip
%Import QtGui/QtGuimod.sip
Expand Down
54 changes: 54 additions & 0 deletions python/core/qgsfeature.sip
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,60 @@ class QgsFeature

public:

SIP_PYOBJECT __getattr__(const QString& name);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
QString altname = QString(*a0).replace("_"," ");
int altfieldIdx = sipCpp->fieldNameIndex(altname);

if (fieldIdx >= 0)
{
QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
else if( altfieldIdx >= 0 )
{
QVariant* v = new QVariant( sipCpp->attribute(altfieldIdx) );
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
}
else
{
PyObject* key = PyString_FromString(a0->toStdString().c_str());
sipRes = PyObject_GenericGetAttr(sipSelf, key );
}
%End

void __setattr__(const QString& key, QVariant value);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
QString altname = QString(*a0).replace("_"," ");
int altfieldIdx = sipCpp->fieldNameIndex(altname);

if (fieldIdx >= 0)
{
sipCpp->setAttribute(fieldIdx, *a1);
}
else if( altfieldIdx >= 0 )
{
sipCpp->setAttribute(altfieldIdx, *a1);
}
else
{
PyObject* key = PyString_FromString(a0->toStdString().c_str());
PyObject* value = sipConvertFromType( a1, sipType_QVariant, sipSelf);
PyObject_GenericSetAttr(sipSelf, key, value);
}
%End

void __delattr__(const QString& key);
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex(*a0);
if (fieldIdx == -1)
PyErr_SetString(PyExc_KeyError, a0->toAscii());
else
sipCpp->deleteAttribute(fieldIdx);
%End

SIP_PYOBJECT __getitem__(int key);
%MethodCode
const QgsAttributes& attrs = sipCpp->attributes();
Expand Down
5 changes: 3 additions & 2 deletions python/gui/gui.sip
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@

%Module qgis.gui 0
%Module(name=qgis.gui,
version=0,
keyword_arguments="Optional")

%Import QtCore/QtCoremod.sip
%Import QtGui/QtGuimod.sip
Expand Down