@@ -30,6 +30,60 @@ class QgsFeature
30
30
31
31
public:
32
32
33
+ SIP_PYOBJECT __getattr__(const QString& name);
34
+ %MethodCode
35
+ int fieldIdx = sipCpp->fieldNameIndex(*a0);
36
+ QString altname = QString(*a0).replace("_"," ");
37
+ int altfieldIdx = sipCpp->fieldNameIndex(altname);
38
+
39
+ if (fieldIdx >= 0)
40
+ {
41
+ QVariant* v = new QVariant( sipCpp->attribute(fieldIdx) );
42
+ sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
43
+ }
44
+ else if( altfieldIdx >= 0 )
45
+ {
46
+ QVariant* v = new QVariant( sipCpp->attribute(altfieldIdx) );
47
+ sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
48
+ }
49
+ else
50
+ {
51
+ PyObject* key = PyString_FromString(a0->toStdString().c_str());
52
+ sipRes = PyObject_GenericGetAttr(sipSelf, key );
53
+ }
54
+ %End
55
+
56
+ void __setattr__(const QString& key, QVariant value);
57
+ %MethodCode
58
+ int fieldIdx = sipCpp->fieldNameIndex(*a0);
59
+ QString altname = QString(*a0).replace("_"," ");
60
+ int altfieldIdx = sipCpp->fieldNameIndex(altname);
61
+
62
+ if (fieldIdx >= 0)
63
+ {
64
+ sipCpp->setAttribute(fieldIdx, *a1);
65
+ }
66
+ else if( altfieldIdx >= 0 )
67
+ {
68
+ sipCpp->setAttribute(altfieldIdx, *a1);
69
+ }
70
+ else
71
+ {
72
+ PyObject* key = PyString_FromString(a0->toStdString().c_str());
73
+ PyObject* value = sipConvertFromType( a1, sipType_QVariant, sipSelf);
74
+ PyObject_GenericSetAttr(sipSelf, key, value);
75
+ }
76
+ %End
77
+
78
+ void __delattr__(const QString& key);
79
+ %MethodCode
80
+ int fieldIdx = sipCpp->fieldNameIndex(*a0);
81
+ if (fieldIdx == -1)
82
+ PyErr_SetString(PyExc_KeyError, a0->toAscii());
83
+ else
84
+ sipCpp->deleteAttribute(fieldIdx);
85
+ %End
86
+
33
87
SIP_PYOBJECT __getitem__(int key);
34
88
%MethodCode
35
89
const QgsAttributes& attrs = sipCpp->attributes();
0 commit comments