@@ -104,7 +104,7 @@ typedef QMap<int, QgsField> QgsFieldMap;
104
104
/** \ingroup core
105
105
* The feature class encapsulates a single feature including its id,
106
106
* geometry and a list of field/values attributes.
107
- *
107
+ * \note QgsFeature objects are implicitly shared.
108
108
* @author Gary E.Sherman
109
109
*/
110
110
class QgsFeature
@@ -218,42 +218,57 @@ class QgsFeature
218
218
sipCpp->deleteAttribute(fieldIdx);
219
219
%End
220
220
221
- //! Constructor
221
+ /** Constructor for QgsFeature
222
+ * @param id feature id
223
+ */
222
224
QgsFeature( qint64 id = 0 );
223
225
226
+ /** Constructor for QgsFeature
227
+ * @param fields feature's fields
228
+ * @param id feature id
229
+ */
224
230
QgsFeature( const QgsFields& fields, qint64 id = 0 );
225
231
226
- /** copy ctor needed due to internal pointer */
232
+ /** Copy constructor
233
+ */
227
234
QgsFeature( const QgsFeature & rhs );
228
235
229
236
//! Destructor
230
237
~QgsFeature();
231
238
232
- /**
233
- * Get the feature id for this feature
234
- * @return Feature id
239
+ /** Get the feature ID for this feature.
240
+ * @returns feature ID
241
+ * @see setFeatureId
235
242
*/
236
243
qint64 id() const;
237
244
238
- /**
239
- * Set the feature id for this feature
240
- * @param id Feature id
245
+ /** Sets the feature ID for this feature.
246
+ * @param id feature id
247
+ * @see id
241
248
*/
242
249
void setFeatureId( qint64 id );
243
250
251
+ /** Returns the feature's attributes.
252
+ * @link attributes @endlink method.
253
+ * @returns list of feature's attributes
254
+ * @see setAttributes
255
+ * @note added in QGIS 2.9
256
+ */
244
257
QgsAttributes attributes() const;
245
258
259
+ /** Sets the feature's attributes.
260
+ * @param attrs attribute list
261
+ * @see setAttribute
262
+ * @see attributes
263
+ */
246
264
void setAttributes( const QgsAttributes& attrs );
247
265
248
- /**
249
- * Set an attribute by id
250
- *
251
- * @param field The index of the field to set
252
- * @param attr The value of the attribute
253
- *
254
- * @return false, if the field id does not exist
255
- *
266
+ /** Set an attribute's value by field index.
267
+ * @param field the index of the field to set
268
+ * @param attr the value of the attribute
269
+ * @return false, if the field index does not exist
256
270
* @note For Python: raises a KeyError exception instead of returning false
271
+ * @see setAttributes
257
272
*/
258
273
bool setAttribute( int field, const QVariant& attr /GetWrapper/);
259
274
%MethodCode
@@ -275,17 +290,14 @@ class QgsFeature
275
290
}
276
291
%End
277
292
278
- /**
279
- * Initialize this feature with the given number of fields. Discard any previously set attribute data.
293
+ /** Initialize this feature with the given number of fields. Discard any previously set attribute data.
280
294
* @param fieldCount Number of fields to initialize
281
295
*/
282
296
void initAttributes( int fieldCount );
283
297
284
- /**
285
- * Deletes an attribute and its value
286
- *
287
- * @param field The index of the field
288
- *
298
+ /** Deletes an attribute and its value.
299
+ * @param field the index of the field
300
+ * @see setAttribute
289
301
* @note For Python: raises a KeyError exception if the field is not found
290
302
*/
291
303
void deleteAttribute( int field );
@@ -298,92 +310,123 @@ class QgsFeature
298
310
sipIsErr = 1;
299
311
}
300
312
%End
301
- /**
302
- * Return the validity of this feature. This is normally set by
313
+ /** Returns the validity of this feature. This is normally set by
303
314
* the provider to indicate some problem that makes the feature
304
315
* invalid or to indicate a null feature.
316
+ * @see setValid
305
317
*/
306
318
bool isValid() const;
307
319
308
- /**
309
- * Set the validity of the feature.
320
+ /** Sets the validity of the feature.
321
+ * @param validity set to true if feature is valid
322
+ * @see isValid
310
323
*/
311
324
void setValid( bool validity );
312
325
313
- /**
314
- * Get the geometry object associated with this feature
326
+ /** Get the geometry object associated with this feature. If the geometry
327
+ * is not going to be modified than calling the const @link constGeometry @endlink
328
+ * method is preferable as it avoids a potentially expensive detach operation.
315
329
*
316
330
* It is possible to modify the geometry in place but this will
317
331
* be removed in 3.0 and therefore @link setGeometry @endlink should be called explicitly.
318
332
*
319
333
* @note will be modified to return by value in QGIS 3.0: `QgsGeometry geometry() const;`
334
+ *
335
+ * @returns pointer to feature's geometry
336
+ * @see constGeometry
337
+ * @see geometryAndOwnership
338
+ * @see setGeometry
320
339
*/
321
340
QgsGeometry* geometry();
322
341
323
- /** Gets a const pointer to the geometry object associated with this feature.
342
+ /** Gets a const pointer to the geometry object associated with this feature. If the geometry
343
+ * is not going to be modified than this method is preferable to the non-const
344
+ * @link geometry @endlink method.
324
345
* @note this is a temporary method for 2.x release cycle. Will be removed in QGIS 3.0.
346
+ * @returns const pointer to feature's geometry
347
+ * @see geometry
348
+ * @see geometryAndOwnership
349
+ * @see setGeometry
325
350
* @note added in QGIS 2.9
326
351
* @note will be removed in QGIS 3.0
327
352
*/
328
353
const QgsGeometry* constGeometry() const;
329
354
330
- /**
331
- * Get the geometry object associated with this feature
332
- * The caller assumes responsibility for the QgsGeometry*'s destruction.
333
- * @deprecated will be removed in QGIS 3.0
355
+ /** Get the geometry object associated with this feature, and transfer ownership of the
356
+ * geometry to the caller. The caller assumes responsibility for the QgsGeometry*'s destruction.
357
+ * @returns pointer to feature's geometry
358
+ * @see geometry
359
+ * @see setGeometry
334
360
*/
335
361
QgsGeometry *geometryAndOwnership() /Factory,Deprecated/;
336
362
337
- /** Set this feature's geometry from another QgsGeometry object (deep copy)
363
+ /** Set this feature's geometry from another QgsGeometry object. This method performs a deep copy
364
+ * of the geometry.
365
+ * @param geom new feature geometry
366
+ * @see geometry
367
+ * @see constGeometry
368
+ * @see geometryAndOwnership
369
+ * @see setGeometryAndOwnership
338
370
*/
339
371
void setGeometry( const QgsGeometry& geom );
340
372
341
- /** Set this feature's geometry (takes geometry ownership)
342
- *
373
+ /** Set this feature's geometry from a QgsGeometry pointer. Ownership of the geometry is transferred
374
+ * to the feature.
375
+ * @param geom new feature geometry
343
376
* @note not available in python bindings
377
+ * @see geometry
378
+ * @see constGeometry
379
+ * @see geometryAndOwnership
380
+ * @see setGeometryAndOwnership
344
381
* @deprecated will be removed in QGIS 3.0
345
382
*/
346
383
// void setGeometry( QgsGeometry* geom /Transfer/ );
347
384
348
- /**
349
- * Set this feature's geometry from WKB
350
- *
351
- * This feature assumes responsibility for destroying geom.
352
- *
385
+ /** Set this feature's geometry from WKB. This feature assumes responsibility for destroying the
386
+ * created geometry.
387
+ * @param geom geometry as WKB
388
+ * @param length size of WKB
389
+ * @see setGeometry
390
+ * @see geometry
391
+ * @see constGeometry
392
+ * @see geometryAndOwnership
353
393
* @deprecated will be removed in QGIS 3.0
354
394
*/
355
395
void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length );
356
396
357
- /** Assign a field map with the feature to allow attribute access by attribute name
358
- *
359
- * @param fields The attribute fields which this feature holds. When used from python, make sure
360
- * a copy of the fields is held by python, as ownership stays there.
361
- * I.e. Do not call feature.setFields( myDataProvider.fields() ) but instead call
362
- * myFields = myDataProvider.fields()
363
- * feature.setFields( myFields )
397
+ /** Assign a field map with the feature to allow attribute access by attribute name.
398
+ * @param fields The attribute fields which this feature holds
364
399
* @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
365
400
* C++: Defaults to false
366
401
* Python: Defaults to true
367
- *
368
- * TODO: QGIS3 - take reference, not pointer
402
+ * @deprecated use setFields( const QgsFields& fields, bool initAttributes = false ) instead
403
+ * @note not available in Python bindings
369
404
*/
370
- void setFields( const QgsFields* fields, bool initAttributes = true );
405
+ // void setFields( const QgsFields* fields, bool initAttributes = true );
371
406
372
- /** Get associated field map.
373
- *
374
- * TODO: QGIS 3 - return reference or value, not pointer
407
+ /** Assign a field map with the feature to allow attribute access by attribute name.
408
+ * @param fields The attribute fields which this feature holds
409
+ * @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
410
+ * C++: Defaults to false
411
+ * Python: Defaults to true
412
+ * @note added in QGIS 2.9
413
+ * @see fields
414
+ */
415
+ void setFields( const QgsFields& fields, bool initAttributes = true );
416
+
417
+ /** Returns the field map associated with the feature.
418
+ * @see setFields
419
+ * TODO: QGIS 3 - return value, not pointer
375
420
*/
376
421
const QgsFields* fields() const;
377
422
378
423
/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
379
- * Field map must be associated to make this work.
380
- *
424
+ * Field map must be associated using @link setFields @endlink before this method can be used.
381
425
* @param name The name of the field to set
382
426
* @param value The value to set
383
- *
384
427
* @return false if attribute name could not be converted to index (C++ only)
385
- *
386
428
* @note For Python: raises a KeyError exception instead of returning false
429
+ * @see setFields
387
430
*/
388
431
void setAttribute( const QString& name, QVariant value /GetWrapper/ );
389
432
%MethodCode
@@ -405,15 +448,12 @@ class QgsFeature
405
448
}
406
449
}
407
450
%End
408
- /** Remove an attribute value.
409
- * Returns false if attribute name could not be converted to index.
410
- * Field map must be associated to make this work.
411
- *
451
+ /** Removes an attribute value by field name. Field map must be associated using @link setFields @endlink
452
+ * before this method can be used.
412
453
* @param name The name of the field to delete
413
- *
414
454
* @return false if attribute name could not be converted to index (C++ only)
415
- *
416
455
* @note For Python: raises a KeyError exception instead of returning false
456
+ * @see setFields
417
457
*/
418
458
bool deleteAttribute( const QString& name );
419
459
%MethodCode
@@ -428,15 +468,12 @@ class QgsFeature
428
468
sipCpp->deleteAttribute( fieldIdx );
429
469
}
430
470
%End
431
- /** Lookup attribute value from attribute name.
432
- * Returns invalid variant if attribute name could not be converted to index (C++ only)
433
- * Field map must be associated to make this work.
434
- *
471
+ /** Lookup attribute value from attribute name. Field map must be associated using @link setFields @endlink
472
+ * before this method can be used.
435
473
* @param name The name of the attribute to get
436
- *
437
474
* @return The value of the attribute (C++: Invalid variant if no such name exists )
438
- *
439
475
* @note For Python: raises a KeyError exception if field is not found
476
+ * @see setFields
440
477
*/
441
478
SIP_PYOBJECT attribute( const QString& name ) const;
442
479
%MethodCode
@@ -452,8 +489,11 @@ class QgsFeature
452
489
sipRes = sipConvertFromNewType( v, sipType_QVariant, Py_None );
453
490
}
454
491
%End
455
- /** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.
456
- * Field map must be associated to make this work.
492
+ /** Utility method to get attribute index from name. Field map must be associated using @link setFields @endlink
493
+ * before this method can be used.
494
+ * @param fieldName name of field to get attribute index of
495
+ * @returns -1 if field does not exist or field map is not associated.
496
+ * @see setFields
457
497
*/
458
498
int fieldNameIndex( const QString& fieldName ) const;
459
499
0 commit comments