Class: QgsFields¶
-
class
qgis.core.
QgsFields
¶ Bases:
sip.wrapper
Constructor for an empty field container
QgsFields(other: QgsFields) Copy constructor
Container 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.
Enums
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 container
Gets 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
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 instances
Signals
Attributes
-
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.
-
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)
-
appendExpressionField
(self, field: QgsField, originIndex: int) → bool¶ Appends an expression field. The field must have unique name, otherwise it is rejected (returns false)
-
at
(self, i: int) → QgsField¶ Gets field at particular index (must be in range 0..N-1)
-
clear
(self)¶ Removes all fields
-
count
(self) → int¶ Returns number of items
-
exists
(self, i: int) → bool¶ Returns if a field index is valid
- Parameters
i – Index of the field which needs to be checked
- Returns
True if the field exists
-
extend
(self, other: QgsFields)¶ Extends with fields from another QgsFields container
-
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
-
fieldOrigin
(self, fieldIdx: int) → QgsFields.FieldOrigin¶ Gets field’s origin (value from an enumeration)
-
fieldOriginIndex
(self, fieldIdx: int) → int¶ Gets field’s origin index (its meaning is specific to each type of origin)
-
iconForField
(self, fieldIdx: int) → QIcon¶ Returns an icon corresponding to a field index, based on the field’s type and source
New in version 2.14.
-
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 – The name of the field.
- 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 – The name of the field.
- 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
-
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 – The name to look for.
- 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.
-
remove
(self, fieldIdx: int)¶ Removes a field with the given index
-
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.
-
size
(self) → int¶ Returns number of items
-
toList
(self) → object¶ Utility function to return a list of QgsField instances
-
class