QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
Classes | Public Types | Public Member Functions | Static Public Member Functions | Properties | 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
 

Public Member Functions

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

Static Public Member Functions

static QIcon iconForFieldType (QMetaType::Type type, QMetaType::Type subType=QMetaType::Type::UnknownType, const QString &typeString=QString())
 Returns an icon corresponding to a field type.
 
static Q_DECL_DEPRECATED QIcon iconForFieldType (QVariant::Type type, QVariant::Type subType, const QString &typeString=QString())
 Returns an icon corresponding to a field type.
 

Properties

int count
 
bool isEmpty
 
QStringList names
 

Detailed Description

Container of fields for a vector layer.

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

Note
QgsFields objects are implicitly shared.

Definition at line 45 of file qgsfields.h.

Member Typedef Documentation

◆ Field

Constructor & Destructor Documentation

◆ QgsFields() [1/3]

QgsFields::QgsFields ( )

Constructor for an empty field container.

Definition at line 29 of file qgsfields.cpp.

◆ QgsFields() [2/3]

QgsFields::QgsFields ( const QgsFields other)

Copy constructor.

Definition at line 34 of file qgsfields.cpp.

◆ QgsFields() [3/3]

QgsFields::QgsFields ( const QList< QgsField > &  fields)

Construct QgsFields from a list of fields.

Since
QGIS 3.40

Definition at line 45 of file qgsfields.cpp.

◆ ~QgsFields()

QgsFields::~QgsFields ( )
virtual

Definition at line 54 of file qgsfields.cpp.

Member Function Documentation

◆ allAttributesList()

QgsAttributeList QgsFields::allAttributesList ( ) const

Utility function to get list of attribute indexes.

Definition at line 431 of file qgsfields.cpp.

◆ append() [1/3]

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

Appends a field.

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

The originIndex argument must be set to a value corresponding to the origin type:

Definition at line 69 of file qgsfields.cpp.

◆ append() [2/3]

bool QgsFields::append ( const QgsFields fields)

Appends another set of fields to these fields.

The fields must have unique names, otherwise it is rejected (returns false).

Since
QGIS 3.40

Definition at line 97 of file qgsfields.cpp.

◆ append() [3/3]

bool QgsFields::append ( const QList< QgsField > &  fields,
Qgis::FieldOrigin  origin = Qgis::FieldOrigin::Provider 
)

Appends a list of fields.

The fields must have unique names, otherwise it is rejected (returns false).

Since
QGIS 3.40

Definition at line 82 of file qgsfields.cpp.

◆ appendExpressionField()

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

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

Definition at line 130 of file qgsfields.cpp.

◆ at()

QgsField QgsFields::at ( int  i) const

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

Definition at line 203 of file qgsfields.cpp.

◆ begin() [1/2]

QgsFields::iterator QgsFields::begin ( )

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

Note
not available in Python bindings

Definition at line 297 of file qgsfields.cpp.

◆ begin() [2/2]

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

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

Note
not available in Python bindings

Definition at line 281 of file qgsfields.cpp.

◆ clear()

void QgsFields::clear ( )

Removes all fields.

Definition at line 57 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
not available in Python bindings

Definition at line 265 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
not available in Python bindings

Definition at line 273 of file qgsfields.cpp.

◆ count()

int QgsFields::count ( ) const

Returns number of items.

Definition at line 173 of file qgsfields.cpp.

◆ end() [1/2]

QgsFields::iterator QgsFields::end ( )

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

Note
not available in Python bindings

Definition at line 306 of file qgsfields.cpp.

◆ end() [2/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
not available in Python bindings

Definition at line 289 of file qgsfields.cpp.

◆ exists()

bool QgsFields::exists ( int  i) const

Returns 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 193 of file qgsfields.cpp.

◆ extend()

void QgsFields::extend ( const QgsFields other)

Extends with fields from another QgsFields container.

Definition at line 154 of file qgsfields.cpp.

◆ field() [1/2]

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

Returns the field with matching name.

Definition at line 213 of file qgsfields.cpp.

◆ field() [2/2]

QgsField QgsFields::field ( int  fieldIdx) const

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

Definition at line 208 of file qgsfields.cpp.

◆ fieldOrigin()

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

Returns the field's origin (value from an enumeration).

Definition at line 229 of file qgsfields.cpp.

◆ fieldOriginIndex()

int QgsFields::fieldOriginIndex ( int  fieldIdx) const

Returns the field's origin index (its meaning is specific to each type of origin).

Definition at line 237 of file qgsfields.cpp.

◆ iconForField()

QIcon QgsFields::iconForField ( int  fieldIdx,
bool  considerOrigin = false 
) const

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

Parameters
fieldIdxthe field index
considerOriginif true the icon will the origin of the field

Definition at line 315 of file qgsfields.cpp.

◆ iconForFieldType() [1/2]

QIcon QgsFields::iconForFieldType ( QMetaType::Type  type,
QMetaType::Type  subType = QMetaType::Type::UnknownType,
const QString &  typeString = QString() 
)
static

Returns an icon corresponding to a field type.

Since QGIS 3.24, the optional subType argument can be used to specify the type of variant list or map values. Since QGIS 3.30, the optional typeString argument can be used to specify field type strings for handling user field types.

Since
QGIS 3.16

Definition at line 334 of file qgsfields.cpp.

◆ iconForFieldType() [2/2]

QIcon QgsFields::iconForFieldType ( QVariant::Type  type,
QVariant::Type  subType,
const QString &  typeString = QString() 
)
static

Returns an icon corresponding to a field type.

Since QGIS 3.24, the optional subType argument can be used to specify the type of variant list or map values. Since QGIS 3.30, the optional typeString argument can be used to specify field type strings for handling user field types.

Since
QGIS 3.16
Deprecated:
since QGIS 3.38, use the method with a QMetaType::Type argument instead

Definition at line 393 of file qgsfields.cpp.

◆ indexFromName()

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

Gets the field index from the field name.

This method 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 242 of file qgsfields.cpp.

◆ indexOf()

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

Gets the field index from the field name.

This method 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.

Definition at line 247 of file qgsfields.cpp.

◆ isEmpty()

bool QgsFields::isEmpty ( ) const

Checks whether the container is empty.

Definition at line 168 of file qgsfields.cpp.

◆ lookupField()

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

Looks 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.

Definition at line 404 of file qgsfields.cpp.

◆ names()

QStringList QgsFields::names ( ) const

Returns a list with field names.

Definition at line 183 of file qgsfields.cpp.

◆ operator QVariant()

QgsFields::operator QVariant ( ) const
inline

Allows direct construction of QVariants from fields.

Definition at line 491 of file qgsfields.h.

◆ operator!=()

bool QgsFields::operator!= ( const QgsFields other) const
inline

Definition at line 437 of file qgsfields.h.

◆ operator=()

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

Assignment operator.

Definition at line 39 of file qgsfields.cpp.

◆ operator==()

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

Definition at line 260 of file qgsfields.cpp.

◆ operator[]() [1/2]

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

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

Definition at line 198 of file qgsfields.cpp.

◆ operator[]() [2/2]

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

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

Definition at line 224 of file qgsfields.cpp.

◆ remove()

void QgsFields::remove ( int  fieldIdx)

Removes the field with the given index.

Definition at line 141 of file qgsfields.cpp.

◆ rename()

bool QgsFields::rename ( int  fieldIdx,
const QString &  name 
)

Renames a name of field.

The field must have unique name, otherwise change is rejected (returns false)

Since
QGIS 3.6

Definition at line 112 of file qgsfields.cpp.

◆ size()

int QgsFields::size ( ) const

Returns number of items.

Definition at line 178 of file qgsfields.cpp.

◆ toList()

QList< QgsField > QgsFields::toList ( ) const

Utility function to return a list of QgsField instances.

Definition at line 252 of file qgsfields.cpp.

Property Documentation

◆ count

int QgsFields::count
read

Definition at line 50 of file qgsfields.h.

◆ isEmpty

bool QgsFields::isEmpty
read

Definition at line 49 of file qgsfields.h.

◆ names

QStringList QgsFields::names
read

Definition at line 51 of file qgsfields.h.


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