mirror of
https://github.com/qgis/QGIS.git
synced 2025-11-22 00:14:55 -05:00
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:
parent
e21f160a76
commit
dc860f75ed
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user