3
3
// key = field index, value = field value
4
4
typedef QMap<int, QVariant> QgsAttributeMap;
5
5
6
+ typedef QVector<QVariant> QgsAttributes;
7
+
6
8
// key = feature id, value = changed attributes
7
9
typedef QMap<qint64, QMap<int, QVariant> > QgsChangedAttributesMap;
8
10
@@ -30,13 +32,12 @@ class QgsFeature
30
32
31
33
SIP_PYOBJECT __getitem__(int key);
32
34
%MethodCode
33
- const QgsAttributeMap& attrMap = sipCpp->attributeMap();
34
- QgsAttributeMap::const_iterator it = attrMap.find(a0);
35
- if (it == attrMap.end())
35
+ const QgsAttributes& attrs = sipCpp->attributes();
36
+ if (a0 < 0 || a0 >= attrs.count())
36
37
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
37
38
else
38
39
{
39
- QVariant* v = new QVariant(it.value() );
40
+ QVariant* v = new QVariant(attrs[a0] );
40
41
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
41
42
}
42
43
%End
@@ -48,14 +49,14 @@ class QgsFeature
48
49
PyErr_SetString(PyExc_KeyError, a0->toAscii());
49
50
else
50
51
{
51
- QVariant* v = new QVariant( sipCpp->attributeMap().value (fieldIdx) );
52
+ QVariant* v = new QVariant( sipCpp->attribute (fieldIdx) );
52
53
sipRes = sipConvertFromInstance(v, sipClass_QVariant, Py_None);
53
54
}
54
55
%End
55
56
56
57
void __setitem__(int key, QVariant value);
57
58
%MethodCode
58
- sipCpp->addAttribute (a0, *a1);
59
+ sipCpp->setAttribute (a0, *a1);
59
60
%End
60
61
61
62
void __setitem__(const QString& key, QVariant value);
@@ -65,13 +66,13 @@ class QgsFeature
65
66
PyErr_SetString(PyExc_KeyError, a0->toAscii());
66
67
else
67
68
{
68
- sipCpp->addAttribute (fieldIdx, *a1);
69
+ sipCpp->setAttribute (fieldIdx, *a1);
69
70
}
70
71
%End
71
72
72
73
void __delitem__(int key);
73
74
%MethodCode
74
- if (sipCpp->attributeMap ().contains(a0 ))
75
+ if (a0 >= 0 && a0 < sipCpp->attributes ().count( ))
75
76
sipCpp->deleteAttribute(a0);
76
77
else
77
78
PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
@@ -107,34 +108,15 @@ class QgsFeature
107
108
*/
108
109
void setFeatureId( qint64 id );
109
110
110
- /**
111
- * Get the attributes for this feature.
112
- * @return A std::map containing the field name/value mapping
113
- */
114
- const QMap<int, QVariant> & attributeMap() const;
115
-
116
-
117
- /**Sets all the attributes in one go*/
118
- void setAttributeMap( const QMap<int, QVariant> & attributeMap );
119
-
120
- /** Clear attribute map
121
- * added in 1.5
122
- */
123
- void clearAttributeMap();
124
-
125
- /**
126
- * Add an attribute to the map
127
- */
128
- void addAttribute( int field, QVariant attr );
111
+ const QgsAttributes& attributes() const;
112
+ //QgsAttributes& attributes();
113
+ void setAttributes(const QgsAttributes& attrs);
114
+ void setAttribute( int field, const QVariant& attr );
115
+ void initAttributes( int fieldCount );
129
116
130
117
/**Deletes an attribute and its value*/
131
118
void deleteAttribute( int field );
132
119
133
- /**Changes an existing attribute value
134
- @param field index of the field
135
- @param attr attribute name and value to be set */
136
- void changeAttribute( int field, QVariant attr );
137
-
138
120
/**
139
121
* Return the validity of this feature. This is normally set by
140
122
* the provider to indicate some problem that makes the feature
@@ -188,13 +170,7 @@ class QgsFeature
188
170
* Field map must be associated to make this work.
189
171
* @note added in 2.0
190
172
*/
191
- bool addAttribute( const QString& name, QVariant value );
192
-
193
- /** Change a value of an attribute. Returns false if attribute name could not be converted to index.
194
- * Field map must be associated to make this work.
195
- * @note added in 2.0
196
- */
197
- bool changeAttribute( const QString& name, QVariant value );
173
+ bool setAttribute( const QString& name, QVariant value );
198
174
199
175
/** Remove an attribute value. Returns false if attribute name could not be converted to index.
200
176
* Field map must be associated to make this work.
0 commit comments