When calling setFields, automatically initalize attributes

That what you want most of the time when creating a new feature within a plugin.
Therefore defaults to true when used from python, but to false when used from C++
This commit is contained in:
Matthias Kuhn 2013-06-05 11:59:50 +02:00
parent e21f160a76
commit dc860f75ed
3 changed files with 28 additions and 3 deletions

View File

@ -158,10 +158,17 @@ class QgsFeature
*/
void setGeometryAndOwnership( unsigned char * geom /Transfer/, size_t length );
/** Assign a field map with the feature to allow attribute access by attribute name
/** Assign a field map with the feature to allow attribute access by
* attribute name
*
* @param fields The attribute fields which this feature holds
* @param initAttributes If true, attributes are initialized. Clears any
* data previously assigned.
* C++: Defaults to false
* Python: Defaults to true
* @note added in 2.0
*/
void setFields( const QgsFields* fields );
void setFields( const QgsFields* fields, bool initAttributes = true );
/** Get associated field map. may be NULL
* @note added in 2.0

View File

@ -159,6 +159,15 @@ void QgsFeature::setGeometryAndOwnership( unsigned char *geom, size_t length )
setGeometry( g );
}
void QgsFeature::setFields( const QgsFields* fields, bool initAttributes )
{
mFields = fields;
if ( initAttributes )
{
this->initAttributes( fields->count() );
}
}
bool QgsFeature::isValid() const
{

View File

@ -189,9 +189,18 @@ class CORE_EXPORT QgsFeature
void setGeometryAndOwnership( unsigned char * geom, size_t length );
/** Assign a field map with the feature to allow attribute access by attribute name
*
* @param fields The attribute fields which this feature holds. When used from python, make sure
* a copy of the fields is held by python, as ownership stays there.
* I.e. Do not call feature.setFields( myDataProvider.fields() ) but instead call
* myFields = myDataProvider.fields()
* feature.setFields( myFields )
* @param initAttributes If true, attributes are initialized. Clears any data previously assigned.
* C++: Defaults to false
* Python: Defaults to true
* @note added in 2.0
*/
void setFields( const QgsFields* fields ) { mFields = fields; }
void setFields( const QgsFields* fields, bool initAttributes = false );
/** Get associated field map. may be NULL
* @note added in 2.0