@@ -232,12 +232,11 @@ class QgsFeature
232
232
*/
233
233
QgsFeature( const QgsFeature & rhs );
234
234
235
- //! Destructor
236
235
~QgsFeature();
237
236
238
237
/** Get the feature ID for this feature.
239
238
* @returns feature ID
240
- * @see setFeatureId
239
+ * @see setId()
241
240
*/
242
241
QgsFeatureId id() const;
243
242
@@ -252,6 +251,7 @@ class QgsFeature
252
251
* @returns list of feature's attributes
253
252
* @see setAttributes
254
253
* @note added in QGIS 2.9
254
+ * @note Alternatively in Python: iterate feature, eg. @code [attr for attr in feature] @endcode
255
255
*/
256
256
QgsAttributes attributes() const;
257
257
@@ -267,6 +267,7 @@ class QgsFeature
267
267
* @param attr the value of the attribute
268
268
* @return false, if the field index does not exist
269
269
* @note For Python: raises a KeyError exception instead of returning false
270
+ * @note Alternatively in Python: @code feature[field] = attr @endcode
270
271
* @see setAttributes
271
272
*/
272
273
bool setAttribute( int field, const QVariant& attr /GetWrapper/);
@@ -300,6 +301,7 @@ class QgsFeature
300
301
* @param field the index of the field
301
302
* @see setAttribute
302
303
* @note For Python: raises a KeyError exception if the field is not found
304
+ * @note Alternatively in Python: @code del feature[field] @endcode
303
305
*/
304
306
void deleteAttribute( int field );
305
307
%MethodCode
@@ -311,6 +313,7 @@ class QgsFeature
311
313
sipIsErr = 1;
312
314
}
313
315
%End
316
+
314
317
/** Returns the validity of this feature. This is normally set by
315
318
* the provider to indicate some problem that makes the feature
316
319
* invalid or to indicate a null feature.
@@ -372,6 +375,7 @@ class QgsFeature
372
375
* @param value The value to set
373
376
* @return false if attribute name could not be converted to index (C++ only)
374
377
* @note For Python: raises a KeyError exception instead of returning false
378
+ * @note Alternatively in Python: @code feature[name] = attr @endcode
375
379
* @see setFields
376
380
*/
377
381
void setAttribute( const QString& name, const QVariant& value /GetWrapper/ );
@@ -394,11 +398,13 @@ class QgsFeature
394
398
}
395
399
}
396
400
%End
401
+
397
402
/** Removes an attribute value by field name. Field map must be associated using @link setFields @endlink
398
403
* before this method can be used.
399
404
* @param name The name of the field to delete
400
405
* @return false if attribute name could not be converted to index (C++ only)
401
406
* @note For Python: raises a KeyError exception instead of returning false
407
+ * @note Alternatively in Python: @code del feature[name] @endcode
402
408
* @see setFields
403
409
*/
404
410
bool deleteAttribute( const QString& name );
@@ -416,11 +422,13 @@ class QgsFeature
416
422
sipRes = true;
417
423
}
418
424
%End
425
+
419
426
/** Lookup attribute value from attribute name. Field map must be associated using @link setFields @endlink
420
427
* before this method can be used.
421
428
* @param name The name of the attribute to get
422
429
* @return The value of the attribute (C++: Invalid variant if no such name exists )
423
- * @note For Python: raises a KeyError exception if field is not found
430
+ * @note For Python: raises a KeyError exception if the field is not found
431
+ * @note Alternatively in Python: @code feature[name] @endcode
424
432
* @see setFields
425
433
*/
426
434
SIP_PYOBJECT attribute( const QString& name ) const;
@@ -437,6 +445,31 @@ class QgsFeature
437
445
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
438
446
}
439
447
%End
448
+
449
+ /** Lookup attribute value from its index. Field map must be associated using @link setFields @endlink
450
+ * before this method can be used.
451
+ * @param fieldIdx The index of the attribute to get
452
+ * @return The value of the attribute (C++: Invalid variant if no such index exists )
453
+ * @note For Python: raises a KeyError exception if the field is not found
454
+ * @note Alternatively in Python: @code feature[fieldIdx] @endcode
455
+ * @see setFields
456
+ */
457
+ SIP_PYOBJECT attribute( int fieldIdx ) const;
458
+ %MethodCode
459
+ {
460
+ if (a0 < 0 || a0 >= sipCpp->attributes().count())
461
+ {
462
+ PyErr_SetString(PyExc_KeyError, QByteArray::number(a0));
463
+ sipIsErr = 1;
464
+ }
465
+ else
466
+ {
467
+ QVariant* v = new QVariant( sipCpp->attribute(a0) );
468
+ sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
469
+ }
470
+ }
471
+ %End
472
+
440
473
/** Utility method to get attribute index from name. Field map must be associated using @link setFields @endlink
441
474
* before this method can be used.
442
475
* @param fieldName name of field to get attribute index of
0 commit comments