QGIS API Documentation  2.99.0-Master (e077efd)
Classes | Public Types | Public Member Functions | List of all members
QgsFields Class Reference

Container of fields for a vector layer. More...

#include <qgsfields.h>

Classes

struct  Field
 

Public Types

typedef struct QgsFields::Field Field
 
enum  FieldOrigin {
  OriginUnknown, OriginProvider, OriginJoin, OriginEdit,
  OriginExpression
}
 

Public Member Functions

 QgsFields ()
 Constructor for an empty field container. More...
 
 QgsFields (const QgsFields &other)
 Copy constructor. More...
 
virtual ~QgsFields ()
 
QgsAttributeList allAttributesList () const
 Utility function to get list of attribute indexes. More...
 
bool append (const QgsField &field, FieldOrigin origin=OriginProvider, int originIndex=-1)
 Append a field. The field must have unique name, otherwise it is rejected (returns false) More...
 
bool appendExpressionField (const QgsField &field, int originIndex)
 Append an expression field. The field must have unique name, otherwise it is rejected (returns false) More...
 
QgsField at (int i) const
 Get field at particular index (must be in range 0..N-1) More...
 
const_iterator begin () const noexcept
 Returns a const STL-style iterator pointing to the first item in the list. More...
 
iterator begin ()
 Returns an STL-style iterator pointing to the first item in the list. More...
 
void clear ()
 Remove all fields. More...
 
const_iterator constBegin () const noexcept
 Returns a const STL-style iterator pointing to the first item in the list. More...
 
const_iterator constEnd () const noexcept
 Returns a const STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
int count () const
 Return number of items. More...
 
const_iterator end () const noexcept
 Returns a const STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
iterator end ()
 Returns an STL-style iterator pointing to the imaginary item after the last item in the list. More...
 
bool exists (int i) const
 Return if a field index is valid. More...
 
void extend (const QgsFields &other)
 Extend with fields from another QgsFields container. More...
 
QgsField field (int fieldIdx) const
 Get field at particular index (must be in range 0..N-1) More...
 
QgsField field (const QString &name) const
 Get field with matching name. More...
 
FieldOrigin fieldOrigin (int fieldIdx) const
 Get field's origin (value from an enumeration) More...
 
int fieldOriginIndex (int fieldIdx) const
 Get field's origin index (its meaning is specific to each type of origin) More...
 
QIcon iconForField (int fieldIdx) const
 Returns an icon corresponding to a field index, based on the field's type and source. More...
 
int indexFromName (const QString &fieldName) const
 Get the field index from the field name. More...
 
int indexOf (const QString &fieldName) const
 Get the field index from the field name. More...
 
bool isEmpty () const
 Check whether the container is empty. More...
 
int lookupField (const QString &fieldName) const
 Look up field's index from the field name. More...
 
 operator QVariant () const
 Allows direct construction of QVariants from fields. More...
 
bool operator!= (const QgsFields &other) const
 
QgsFieldsoperator= (const QgsFields &other)
 Assignment operator. More...
 
bool operator== (const QgsFields &other) const
 
QgsField operator[] (int i) const
 Get field at particular index (must be in range 0..N-1) More...
 
QgsFieldoperator[] (int i)
 Get field at particular index (must be in range 0..N-1) More...
 
void remove (int fieldIdx)
 Remove a field with the given index. More...
 
int size () const
 Return number of items. More...
 
QList< QgsFieldtoList () const
 Utility function to return a list of QgsField instances. More...
 

Detailed Description

Container of fields for a vector layer.

In addition to storing a list of QgsField instances, it also:

Definition at line 36 of file qgsfields.h.

Member Typedef Documentation

§ Field

Member Enumeration Documentation

§ FieldOrigin

Enumerator
OriginUnknown 

It has not been specified where the field comes from.

OriginProvider 

Field comes from the underlying data provider of the vector layer (originIndex = index in provider's fields)

OriginJoin 

Field comes from a joined layer (originIndex / 1000 = index of the join, originIndex % 1000 = index within the join)

OriginEdit 

Field has been temporarily added in editing mode (originIndex = index in the list of added attributes)

OriginExpression 

Field is calculated from an expression.

Definition at line 40 of file qgsfields.h.

Constructor & Destructor Documentation

§ QgsFields() [1/2]

QgsFields::QgsFields ( )

Constructor for an empty field container.

Definition at line 28 of file qgsfields.cpp.

§ QgsFields() [2/2]

QgsFields::QgsFields ( const QgsFields other)

Copy constructor.

Definition at line 33 of file qgsfields.cpp.

§ ~QgsFields()

QgsFields::~QgsFields ( )
virtual

Definition at line 44 of file qgsfields.cpp.

Member Function Documentation

§ allAttributesList()

QgsAttributeList QgsFields::allAttributesList ( ) const

Utility function to get list of attribute indexes.

Note
added in 2.4

Definition at line 318 of file qgsfields.cpp.

§ append()

bool QgsFields::append ( const QgsField field,
FieldOrigin  origin = OriginProvider,
int  originIndex = -1 
)

Append a field. The field must have unique name, otherwise it is rejected (returns false)

Definition at line 61 of file qgsfields.cpp.

§ appendExpressionField()

bool QgsFields::appendExpressionField ( const QgsField field,
int  originIndex 
)

Append an expression field. The field must have unique name, otherwise it is rejected (returns false)

Definition at line 74 of file qgsfields.cpp.

§ at()

QgsField QgsFields::at ( int  i) const

Get field at particular index (must be in range 0..N-1)

Definition at line 137 of file qgsfields.cpp.

§ begin() [1/2]

QgsFields::const_iterator QgsFields::begin ( ) const
noexcept

Returns a const STL-style iterator pointing to the first item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 215 of file qgsfields.cpp.

§ begin() [2/2]

QgsFields::iterator QgsFields::begin ( )

Returns an STL-style iterator pointing to the first item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 231 of file qgsfields.cpp.

§ clear()

void QgsFields::clear ( )

Remove all fields.

Definition at line 49 of file qgsfields.cpp.

§ constBegin()

QgsFields::const_iterator QgsFields::constBegin ( ) const
noexcept

Returns a const STL-style iterator pointing to the first item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 199 of file qgsfields.cpp.

§ constEnd()

QgsFields::const_iterator QgsFields::constEnd ( ) const
noexcept

Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 207 of file qgsfields.cpp.

§ count()

int QgsFields::count ( ) const

Return number of items.

Definition at line 117 of file qgsfields.cpp.

§ end() [1/2]

QgsFields::const_iterator QgsFields::end ( ) const
noexcept

Returns a const STL-style iterator pointing to the imaginary item after the last item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 223 of file qgsfields.cpp.

§ end() [2/2]

QgsFields::iterator QgsFields::end ( )

Returns an STL-style iterator pointing to the imaginary item after the last item in the list.

Note
added in 2.16
not available in Python bindings

Definition at line 240 of file qgsfields.cpp.

§ exists()

bool QgsFields::exists ( int  i) const

Return if a field index is valid.

Parameters
iIndex of the field which needs to be checked
Returns
True if the field exists

Definition at line 127 of file qgsfields.cpp.

§ extend()

void QgsFields::extend ( const QgsFields other)

Extend with fields from another QgsFields container.

Definition at line 98 of file qgsfields.cpp.

§ field() [1/2]

QgsField QgsFields::field ( int  fieldIdx) const

Get field at particular index (must be in range 0..N-1)

Definition at line 142 of file qgsfields.cpp.

§ field() [2/2]

QgsField QgsFields::field ( const QString &  name) const

Get field with matching name.

Definition at line 147 of file qgsfields.cpp.

§ fieldOrigin()

QgsFields::FieldOrigin QgsFields::fieldOrigin ( int  fieldIdx) const

Get field's origin (value from an enumeration)

Definition at line 163 of file qgsfields.cpp.

§ fieldOriginIndex()

int QgsFields::fieldOriginIndex ( int  fieldIdx) const

Get field's origin index (its meaning is specific to each type of origin)

Definition at line 171 of file qgsfields.cpp.

§ iconForField()

QIcon QgsFields::iconForField ( int  fieldIdx) const

Returns an icon corresponding to a field index, based on the field's type and source.

Note
added in QGIS 2.14

Definition at line 249 of file qgsfields.cpp.

§ indexFromName()

int QgsFields::indexFromName ( const QString &  fieldName) const

Get the field index from the field name.

This method takes is case sensitive and only matches the data source name of the field. Alias for indexOf

Parameters
fieldNameThe name of the field.
Returns
The field index if found or -1 in case it cannot be found.
See also
lookupField For a more tolerant alternative.

Definition at line 176 of file qgsfields.cpp.

§ indexOf()

int QgsFields::indexOf ( const QString &  fieldName) const

Get the field index from the field name.

This method takes is case sensitive and only matches the data source name of the field.

Parameters
fieldNameThe name of the field.
Returns
The field index if found or -1 in case it cannot be found.
See also
lookupField For a more tolerant alternative.
Note
Added in QGIS 3.0

Definition at line 181 of file qgsfields.cpp.

§ isEmpty()

bool QgsFields::isEmpty ( ) const

Check whether the container is empty.

Definition at line 112 of file qgsfields.cpp.

§ lookupField()

int QgsFields::lookupField ( const QString &  fieldName) const

Look up field's index from the field name.

This method matches in the following order:

  1. The exact field name taking case sensitivity into account
  2. Looks for the field name by case insensitive comparison
  3. The field alias (case insensitive)
Parameters
fieldNameThe name to look for.
Returns
The field index if found or -1 in case it cannot be found.
See also
indexFromName For a more performant and precise but less tolerant alternative.
Note
added in 2.4

Definition at line 291 of file qgsfields.cpp.

§ operator QVariant()

QgsFields::operator QVariant ( ) const
inline

Allows direct construction of QVariants from fields.

Definition at line 183 of file qgsfields.h.

§ operator!=()

bool QgsFields::operator!= ( const QgsFields other) const
inline
Note
added in 2.6

Definition at line 175 of file qgsfields.h.

§ operator=()

QgsFields & QgsFields::operator= ( const QgsFields other)

Assignment operator.

Definition at line 38 of file qgsfields.cpp.

§ operator==()

bool QgsFields::operator== ( const QgsFields other) const
Note
added in 2.6

Definition at line 194 of file qgsfields.cpp.

§ operator[]() [1/2]

QgsField QgsFields::operator[] ( int  i) const

Get field at particular index (must be in range 0..N-1)

Definition at line 158 of file qgsfields.cpp.

§ operator[]() [2/2]

QgsField & QgsFields::operator[] ( int  i)

Get field at particular index (must be in range 0..N-1)

Definition at line 132 of file qgsfields.cpp.

§ remove()

void QgsFields::remove ( int  fieldIdx)

Remove a field with the given index.

Definition at line 85 of file qgsfields.cpp.

§ size()

int QgsFields::size ( ) const

Return number of items.

Definition at line 122 of file qgsfields.cpp.

§ toList()

QList< QgsField > QgsFields::toList ( ) const

Utility function to return a list of QgsField instances.

Definition at line 186 of file qgsfields.cpp.


The documentation for this class was generated from the following files: