Class: QgsFields¶
- class qgis.core.QgsFields¶
Bases:
sip.wrapper
Constructor for an empty field container
QgsFields(other:
QgsFields
) Copy constructorContainer of fields for a vector layer.
In addition to storing a list of
QgsField
instances, it also:allows quick lookups of field names to index in the list
keeps track of where the field definition comes from (vector data provider, joined layer or newly added from an editing operation)
Note
QgsFields
objects are implicitly shared.Methods
Utility function to get list of attribute indexes
Appends a field.
Appends an expression field.
Gets field at particular index (must be in range 0..N-1)
Removes all fields
Returns number of items
Returns if a field index is valid
Extends with fields from another
QgsFields
containerGets field at particular index (must be in range 0..N-1)
Gets field’s origin (value from an enumeration)
Gets field’s origin index (its meaning is specific to each type of origin)
Returns an icon corresponding to a field index, based on the field’s type and source
Returns an icon corresponding to a field
type
Gets the field index from the field name.
Gets the field index from the field name.
Checks whether the container is empty
Looks up field’s index from the field name.
Returns a list with field names
Removes a field with the given index
Renames a name of field.
Returns number of items
Utility function to return a list of
QgsField
instancesAttributes
- class FieldOrigin¶
Bases:
int
- OriginEdit = 3¶
- OriginExpression = 4¶
- OriginJoin = 2¶
- OriginProvider = 1¶
- OriginUnknown = 0¶
- allAttributesList(self) → List[int]¶
Utility function to get list of attribute indexes
New in version 2.4.
- Return type
List[int]
- append(self, field: QgsField, origin: QgsFields.FieldOrigin = QgsFields.OriginProvider, originIndex: int = - 1) → bool¶
Appends a field. The field must have unique name, otherwise it is rejected (returns
False
)- Parameters
field (QgsField) –
origin (QgsFields.FieldOrigin = QgsFields.OriginProvider) –
originIndex (int = -1) –
- Return type
bool
- appendExpressionField(self, field: QgsField, originIndex: int) → bool¶
Appends an expression field. The field must have unique name, otherwise it is rejected (returns
False
)- Parameters
field (QgsField) –
originIndex (int) –
- Return type
bool
- at(self, i: int) → QgsField¶
Gets field at particular index (must be in range 0..N-1)
- Parameters
i (int) –
- Return type
- clear(self)¶
Removes all fields
- count(self) → int¶
Returns number of items
- Return type
int
- exists(self, i: int) → bool¶
Returns if a field index is valid
- Parameters
i (int) – Index of the field which needs to be checked
- Return type
bool
- Returns
True
if the field exists
- extend(self, other: QgsFields)¶
Extends with fields from another
QgsFields
container- Parameters
other (QgsFields) –
- field(self, fieldIdx: int) → QgsField¶
Gets field at particular index (must be in range 0..N-1)
field(self, name: str) -> QgsField Gets field with matching name
- Parameters
fieldIdx (int) –
- Return type
- fieldOrigin(self, fieldIdx: int) → QgsFields.FieldOrigin¶
Gets field’s origin (value from an enumeration)
- Parameters
fieldIdx (int) –
- Return type
- fieldOriginIndex(self, fieldIdx: int) → int¶
Gets field’s origin index (its meaning is specific to each type of origin)
- Parameters
fieldIdx (int) –
- Return type
int
- iconForField(self, fieldIdx: int, considerOrigin: bool = False) → QIcon¶
Returns an icon corresponding to a field index, based on the field’s type and source
- Parameters
fieldIdx (int) – the field index
considerOrigin (bool = False) – if
True
the icon will the origin of the field
New in version 2.14.
- Return type
QIcon
- iconForFieldType(type: QVariant.Type) → QIcon¶
Returns an icon corresponding to a field
type
New in version 3.16.
- Parameters
type (QVariant.Type) –
- Return type
QIcon
- indexFromName(self, fieldName: str) → int¶
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
fieldName (str) – The name of the field.
- Return type
int
- Returns
The field index if found or -1 in case it cannot be found.
See also
- indexOf(self, fieldName: str) → int¶
Gets the field index from the field name. This method is case sensitive and only matches the data source name of the field.
- Parameters
fieldName (str) – The name of the field.
- Return type
int
- Returns
The field index if found or -1 in case it cannot be found.
See also
New in version 3.0.
- isEmpty(self) → bool¶
Checks whether the container is empty
- Return type
bool
- lookupField(self, fieldName: str) → int¶
Looks up field’s index from the field name. This method matches in the following order:
The exact field name taking case sensitivity into account
Looks for the field name by case insensitive comparison
The field alias (case insensitive)
- Parameters
fieldName (str) – The name to look for.
- Return type
int
- Returns
The field index if found or -1 in case it cannot be found.
See also
New in version 2.4.
- names(self) → List[str]¶
Returns a list with field names
New in version 3.0.
- Return type
List[str]
- remove(self, fieldIdx: int)¶
Removes a field with the given index
- Parameters
fieldIdx (int) –
- rename(self, fieldIdx: int, name: str) → bool¶
Renames a name of field. The field must have unique name, otherwise change is rejected (returns
False
)New in version 3.6.
- Parameters
fieldIdx (int) –
name (str) –
- Return type
bool
- size(self) → int¶
Returns number of items
- Return type
int