Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
also comment methods
fix comment starting on first line of block
  • Loading branch information
3nids committed Mar 30, 2017
1 parent a3bdd44 commit b0564be
Show file tree
Hide file tree
Showing 4 changed files with 1,367 additions and 65 deletions.
156 changes: 154 additions & 2 deletions python/core/qgsfeature.sip
Expand Up @@ -103,12 +103,11 @@ typedef QVector<QVariant> QgsAttributes;
class QgsFeature
{
%Docstring
\ingroup core
The feature class encapsulates a single feature including its id,
geometry and a list of field/values attributes.
\note QgsFeature objects are implicitly shared.
@author Gary E.Sherman


%End

%TypeHeaderCode
Expand Down Expand Up @@ -223,10 +222,22 @@ class QgsFeature
%End

QgsFeature( qint64 id = 0 );
%Docstring
Constructor for QgsFeature
@param id feature id
%End

QgsFeature( const QgsFields &fields, qint64 id = 0 );
%Docstring
Constructor for QgsFeature
@param fields feature's fields
@param id feature id
%End

QgsFeature( const QgsFeature &rhs );
%Docstring
Copy constructor
%End

// QgsFeature &operator=( const QgsFeature &rhs ); // SIP_SKIP

Expand All @@ -240,14 +251,49 @@ class QgsFeature
virtual ~QgsFeature();

QgsFeatureId id() const;
%Docstring
Get the feature ID for this feature.
@returns feature ID
@see setId()
%End

void setId( QgsFeatureId id );
%Docstring
Sets the feature ID for this feature.
@param id feature id
@see id
%End

QgsAttributes attributes() const;
%Docstring
Returns the feature's attributes.
@link attributes @endlink method.
@returns list of feature's attributes
@see setAttributes
@note added in QGIS 2.9
@note Alternatively in Python: iterate feature, eg. @code [attr for attr in feature] @endcode
%End

void setAttributes( const QgsAttributes &attrs );
%Docstring
Sets the feature's attributes.
The feature will be valid after.
@param attrs attribute list
@see setAttribute
@see attributes
%End

bool setAttribute( int field, const QVariant &attr /GetWrapper/ );
%Docstring
Set an attribute's value by field index.
The feature will be valid if it was successful.
@param field the index of the field to set
@param attr the value of the attribute
@return false, if the field index does not exist
@note For Python: raises a KeyError exception instead of returning false
@note Alternatively in Python: @code feature[field] = attr @endcode
@see setAttributes
%End
%MethodCode
bool rv;

Expand All @@ -270,8 +316,19 @@ class QgsFeature
%End

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

void deleteAttribute( int field );
%Docstring
Deletes an attribute and its value.
@param field the index of the field
@see setAttribute
@note For Python: raises a KeyError exception if the field is not found
@note Alternatively in Python: @code del feature[field] @endcode
%End
%MethodCode
if ( a0 >= 0 && a0 < sipCpp->attributes().count() )
sipCpp->deleteAttribute( a0 );
Expand All @@ -283,22 +340,80 @@ class QgsFeature
%End

bool isValid() const;
%Docstring
Returns the validity of this feature. This is normally set by
the provider to indicate some problem that makes the feature
invalid or to indicate a null feature.
@see setValid
%End

void setValid( bool validity );
%Docstring
Sets the validity of the feature.
@param validity set to true if feature is valid
@see isValid
%End

bool hasGeometry() const;
%Docstring
Returns true if the feature has an associated geometry.
@see geometry()
@note added in QGIS 3.0.
%End

QgsGeometry geometry() const;
%Docstring
Returns the geometry associated with this feature. If the feature has no geometry,
an empty QgsGeometry object will be returned.
@see hasGeometry()
@see setGeometry()
%End

void setGeometry( const QgsGeometry &geometry );
%Docstring
Set the feature's geometry. The feature will be valid after.
@param geometry new feature geometry
@see geometry()
@see clearGeometry()
%End

void clearGeometry();
%Docstring
Removes any geometry associated with the feature.
@see setGeometry()
@see hasGeometry()
@note added in QGIS 3.0
%End

void setFields( const QgsFields &fields, bool initAttributes = true );
%Docstring
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 QGIS 2.9
@see fields
%End

QgsFields fields() const;
%Docstring
Returns the field map associated with the feature.
@see setFields
%End

void setAttribute( const QString &name, const QVariant &value /GetWrapper/ );
%Docstring
Insert a value into attribute. Returns false if attribute name could not be converted to index.
Field map must be associated using @link setFields @endlink before this method can be used.
The feature will be valid if it was successful
@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 Alternatively in Python: @code feature[name] = attr @endcode
@see setFields
%End
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex( *a0 );
if ( fieldIdx == -1 )
Expand All @@ -320,6 +435,15 @@ class QgsFeature
%End

bool deleteAttribute( const QString &name );
%Docstring
Removes an attribute value by field name. Field map must be associated using @link setFields @endlink
before this method can be used.
@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 Alternatively in Python: @code del feature[name] @endcode
@see setFields
%End
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex( *a0 );
if ( fieldIdx == -1 )
Expand All @@ -336,6 +460,15 @@ class QgsFeature
%End

SIP_PYOBJECT attribute( const QString &name ) const;
%Docstring
Lookup attribute value from attribute name. Field map must be associated using @link setFields @endlink
before this method can be used.
@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 the field is not found
@note Alternatively in Python: @code feature[name] @endcode
@see setFields
%End
%MethodCode
int fieldIdx = sipCpp->fieldNameIndex( *a0 );
if ( fieldIdx == -1 )
Expand All @@ -351,6 +484,15 @@ class QgsFeature
%End

SIP_PYOBJECT attribute( int fieldIdx ) const;
%Docstring
Lookup attribute value from its index. Field map must be associated using @link setFields @endlink
before this method can be used.
@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 the field is not found
@note Alternatively in Python: @code feature[fieldIdx] @endcode
@see setFields
%End
%MethodCode
{
if ( a0 < 0 || a0 >= sipCpp->attributes().count() )
Expand All @@ -367,8 +509,18 @@ class QgsFeature
%End

int fieldNameIndex( const QString &fieldName ) const;
%Docstring
Utility method to get attribute index from name. Field map must be associated using @link setFields @endlink
before this method can be used.
@param fieldName name of field to get attribute index of
@returns -1 if field does not exist or field map is not associated.
@see setFields
%End

operator QVariant() const;
%Docstring
Allows direct construction of QVariants from features.
%End

}; // class QgsFeature

Expand Down

0 comments on commit b0564be

Please sign in to comment.