Skip to content
Permalink
Browse files

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++
  • Loading branch information
m-kuhn committed Jun 5, 2013
1 parent e21f160 commit dc860f75ed039981db5a916dfae9f2918111be2c
Showing with 28 additions and 3 deletions.
  1. +9 −2 python/core/qgsfeature.sip
  2. +9 −0 src/core/qgsfeature.cpp
  3. +10 −1 src/core/qgsfeature.h
@@ -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
@@ -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
{
@@ -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

0 comments on commit dc860f7

Please sign in to comment.
You can’t perform that action at this time.