Class: QgsFieldModel¶
A model which displays the list of fields in widgets (optionally associated with a vector layer).
If allowed, expressions might be added to the end of the model. It can
be associated with a QgsMapLayerModel
to dynamically display
a layer and its fields.
Class Hierarchy¶
Base classes¶
Enums
Custom model roles. |
|
alias of |
Methods
Returns |
|
Returns |
|
Returns the fields currently shown in the model. |
|
Returns the index corresponding to a given fieldName. |
|
Returns |
|
Returns the layer associated with the model. |
|
Removes any custom expression from the model. |
|
Sets whether an optional empty field ("not set") option is present in the model. |
|
Sets whether custom expressions are accepted and displayed in the model. |
|
Sets a single expression to be added after the fields at the end of the model. |
|
Manually sets the fields to use for the model. |
|
Set the layer from which fields are displayed. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsFieldModel. See the FAQ for more details.
Called when the model must be updated. |
Static Methods
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias and type. |
|
Returns a HTML formatted tooltip string for a field, containing details like the field name, alias, type and expression. |
- class qgis.core.QgsFieldModel[source]¶
Bases:
QAbstractItemModel
- __init__(parent: QObject | None = None)
Constructor for QgsFieldModel - creates a model to display the fields of a given layer.
- Parameters:
parent (Optional[QObject] = None)
- class CustomRole(*values)¶
Bases:
IntEnum
Custom model roles.
Note
Prior to QGIS 3.36 this was available as QgsFieldModel.FieldRoles
Added in version 3.36.
FieldName
: Return field name if index corresponds to a fieldAvailable as
QgsFieldModel.FieldNameRole
in older QGIS releases.FieldIndex
: Return field index if index corresponds to a fieldAvailable as
QgsFieldModel.FieldIndexRole
in older QGIS releases.Expression
: Return field name or expressionAvailable as
QgsFieldModel.ExpressionRole
in older QGIS releases.IsExpression
: Return if index corresponds to an expressionAvailable as
QgsFieldModel.IsExpressionRole
in older QGIS releases.ExpressionValidity
: Return if expression is valid or notAvailable as
QgsFieldModel.ExpressionValidityRole
in older QGIS releases.FieldType
: Return the field type (if a field, return QVariant if expression)Available as
QgsFieldModel.FieldTypeRole
in older QGIS releases.FieldOrigin
: Return the field origin (if a field, returns QVariant if expression)Available as
QgsFieldModel.FieldOriginRole
in older QGIS releases.IsEmpty
: Return if the index corresponds to the empty valueAvailable as
QgsFieldModel.IsEmptyRole
in older QGIS releases.EditorWidgetType
: Editor widget typeJoinedFieldIsEditable
:True
if a joined field is editable (returns QVariant if not a joined field)FieldIsWidgetEditable
:True
if a is editable from the widget
- FieldRoles¶
alias of
CustomRole
- allowEmptyFieldName(self) bool [source]¶
Returns
True
if the model allows the empty field (“not set”) choice.See also
- Return type:
bool
- allowExpression(self) bool [source]¶
Returns
True
if the model allows custom expressions to be created and displayed.See also
- Return type:
bool
- static fieldToolTip(field: QgsField) str [source]¶
Returns a HTML formatted tooltip string for a
field
, containing details like the field name, alias and type.- Parameters:
field (QgsField)
- Return type:
str
- static fieldToolTipExtended(field: QgsField, layer: QgsVectorLayer | None) str [source]¶
Returns a HTML formatted tooltip string for a
field
, containing details like the field name, alias, type and expression.Added in version 3.14.
- Parameters:
field (QgsField)
layer (Optional[QgsVectorLayer])
- Return type:
str
- fields(self) QgsFields [source]¶
Returns the fields currently shown in the model.
This will either be fields from the associated
layer()
or the fields manually set by a call tosetFields()
.Added in version 3.14.
- Return type:
- indexFromName(self, fieldName: str | None) QModelIndex [source]¶
Returns the index corresponding to a given fieldName.
- Parameters:
fieldName (Optional[str])
- Return type:
QModelIndex
- isField(self, expression: str | None) bool [source]¶
Returns
True
if a string represents a field reference, orFalse
if it is an expression consisting of more than direct field reference.- Parameters:
expression (Optional[str])
- Return type:
bool
- layer(self) QgsVectorLayer | None [source]¶
Returns the layer associated with the model.
See also
- Return type:
Optional[QgsVectorLayer]
- setAllowEmptyFieldName(self, allowEmpty: bool)[source]¶
Sets whether an optional empty field (“not set”) option is present in the model.
See also
- Parameters:
allowEmpty (bool)
- setAllowExpression(self, allowExpression: bool)[source]¶
Sets whether custom expressions are accepted and displayed in the model.
See also
See also
- Parameters:
allowExpression (bool)
- setExpression(self, expression: str | None)[source]¶
Sets a single expression to be added after the fields at the end of the model.
See also
See also
See also
- Parameters:
expression (Optional[str])
- setFields(self, fields: QgsFields)[source]¶
Manually sets the
fields
to use for the model.This method should only be used when the model ISN’T associated with a
layer()
and needs to show the fields from an arbitrary field collection instead. CallingsetFields()
will automatically clear any existinglayer()
.See also
Added in version 3.14.
- Parameters:
fields (QgsFields)
- setLayer(self, layer: QgsVectorLayer | None)[source]¶
Set the layer from which fields are displayed.
See also
- Parameters:
layer (Optional[QgsVectorLayer])