53 changes: 51 additions & 2 deletions src/core/qgsfeature.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,32 @@ class CORE_EXPORT QgsFeature
const QgsAttributes& attributes() const { return mAttributes; }
QgsAttributes& attributes() { return mAttributes; }
void setAttributes( const QgsAttributes& attrs ) { mAttributes = attrs; }

/**
* Set an attribute by id
*
* @param field The index of the field to set
* @param attr The value of the attribute
*
* @return false, if the field id does not exist
*
* @note For Python: raises a KeyError exception instead of returning false
*/
bool setAttribute( int field, const QVariant& attr );

/**
* Initialize this feature with the given number of fields. Discard any previously set attribute data.
* @param fieldCount Number of fields to initialize
*/
void initAttributes( int fieldCount );

/**Deletes an attribute and its value*/
/**
* Deletes an attribute and its value
*
* @param field The index of the field
*
* @note For Python: raises a KeyError exception if the field is not found
*/
void deleteAttribute( int field );

/**
Expand Down Expand Up @@ -209,29 +231,56 @@ class CORE_EXPORT QgsFeature

/** Insert a value into attribute. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
*
* @param name The name of the field to set
* @param value The value to set
*
* @return false if attribute name could not be converted to index (C++ only)
*
* @note For Python: raises a KeyError exception instead of returning false
* @note added in 2.0
*/
bool setAttribute( const QString& name, QVariant value );

/** Remove an attribute value. Returns false if attribute name could not be converted to index.
* Field map must be associated to make this work.
*
* @param name The name of the field to delete
*
* @return false if attribute name could not be converted to index (C++ only)
*
* @note For Python: raises a KeyError exception instead of returning false
* @note added in 2.0
*/
bool deleteAttribute( const QString& name );

/** Lookup attribute value from attribute name. Returns invalid variant if attribute name could not be converted to index.
/** Lookup attribute value from attribute name.
* Returns invalid variant if attribute name could not be converted to index (C++ only)
* Field map must be associated to make this work.
*
* @param name The name of the attribute to get
*
* @return The value of the attribute (C++: Invalid variant if no such name exists )
*
* @note For Python: raises a KeyError exception if field is not found
* @note added in 2.0
*/
QVariant attribute( const QString& name ) const;

/** Lookup attribute value from its index. Returns invalid variant if the index does not exist.
*
* @param fieldIdx The index of the attribute to get
*
* @return The value of the attribute (C++: Invalid variant if no such index exists )
*
* @note For Python: raises a KeyError exception if field is not found
* @note added in 2.0
*/
QVariant attribute( int fieldIdx ) const;

/** Utility method to get attribute index from name. Returns -1 if field does not exist or field map is not associated.
* Field map must be associated to make this work.
*
* @note added in 2.0
*/
int fieldNameIndex( const QString& fieldName ) const;
Expand Down