Class: QgsFieldModel¶
- class qgis.core.QgsFieldModel¶
Bases:
PyQt5.QtCore.QAbstractItemModel
The
QgsFieldModel
class is a model to display 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 aQgsMapLayerModel
to dynamically display a layer and its fields.QgsFieldModel(parent: QObject = None) Constructor for
QgsFieldModel
- creates a model to display the fields of a given layer.Enums
Bases:
enum.IntEnum
alias of
CustomRole
Methods
Returns
True
if the model allows the empty field ("not set") choice.Returns
True
if the model allows custom expressions to be created and displayed.- param parent:
- param index:
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.Returns the fields currently shown in the model.
- param row:
Returns the index corresponding to a given fieldName.
Returns
True
if a string represents a field reference, orFalse
if it is an expression consisting of more than direct field reference.Returns the layer associated with the model.
- param child:
Removes any custom expression from the model.
- param parent:
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.
Called when the model must be updated.
- class CustomRole(value)¶
Bases:
enum.IntEnum
Custom model roles.
Note
Prior to QGIS 3.36 this was available as QgsFieldModel.FieldRoles
New in version 3.36.
FieldNameRole
: Return field name if index corresponds to a fieldFieldIndexRole
: Return field index if index corresponds to a fieldExpressionRole
: Return field name or expressionIsExpressionRole
: Return if index corresponds to an expressionExpressionValidityRole
: Return if expression is valid or notFieldTypeRole
: Return the field type (if a field, return QVariant if expression)FieldOriginRole
: Return the field origin (if a field, returns QVariant if expression)IsEmptyRole
: Return if the index corresponds to the empty valueEditorWidgetType
: 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
- baseClass¶
alias of
QgsFieldModel
- FieldRoles¶
alias of
CustomRole
- allowEmptyFieldName(self) bool ¶
Returns
True
if the model allows the empty field (“not set”) choice.See also
- Return type:
bool
- allowExpression(self) bool ¶
Returns
True
if the model allows custom expressions to be created and displayed.See also
- Return type:
bool
- beginInsertColumns(self, QModelIndex, int, int)¶
- beginInsertRows(self, QModelIndex, int, int)¶
- beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) bool ¶
- beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) bool ¶
- beginRemoveColumns(self, QModelIndex, int, int)¶
- beginRemoveRows(self, QModelIndex, int, int)¶
- beginResetModel(self)¶
- changePersistentIndex(self, QModelIndex, QModelIndex)¶
- changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])¶
- childEvent(self, QChildEvent)¶
- columnCount(self, parent: QModelIndex) int ¶
- Parameters:
parent (QModelIndex) –
- Return type:
int
- connectNotify(self, QMetaMethod)¶
- createIndex(self, int, int, object: object = 0) QModelIndex ¶
- customEvent(self, QEvent)¶
- data(self, index: QModelIndex, role: int) Any ¶
- Parameters:
index (QModelIndex) –
role (int) –
- Return type:
Any
- decodeData(self, int, int, QModelIndex, QDataStream) bool ¶
- disconnectNotify(self, QMetaMethod)¶
- encodeData(self, Iterable[QModelIndex], QDataStream)¶
- endInsertColumns(self)¶
- endInsertRows(self)¶
- endMoveColumns(self)¶
- endMoveRows(self)¶
- endRemoveColumns(self)¶
- endRemoveRows(self)¶
- endResetModel(self)¶
- fieldToolTip(field: QgsField) str ¶
Returns a HTML formatted tooltip string for a
field
, containing details like the field name, alias and type.- Parameters:
field (QgsField) –
- Return type:
str
- fieldToolTipExtended(field: QgsField, layer: QgsVectorLayer) str ¶
Returns a HTML formatted tooltip string for a
field
, containing details like the field name, alias, type and expression.New in version 3.14.
- Parameters:
field (QgsField) –
layer (QgsVectorLayer) –
- Return type:
str
- fields(self) QgsFields ¶
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()
.New in version 3.14.
- Return type:
- index(self, row: int, column: int, parent: QModelIndex = QModelIndex()) QModelIndex ¶
- Parameters:
row (int) –
column (int) –
parent (QModelIndex = QModelIndex()) –
- Return type:
QModelIndex
- indexFromName(self, fieldName: str) QModelIndex ¶
Returns the index corresponding to a given fieldName.
- Parameters:
fieldName (str) –
- Return type:
QModelIndex
- isField(self, expression: str) bool ¶
Returns
True
if a string represents a field reference, orFalse
if it is an expression consisting of more than direct field reference.- Parameters:
expression (str) –
- Return type:
bool
- isSignalConnected(self, QMetaMethod) bool ¶
- layer(self) QgsVectorLayer ¶
Returns the layer associated with the model.
See also
- Return type:
- parent(self, child: QModelIndex) QModelIndex ¶
- Parameters:
child (QModelIndex) –
- Return type:
QModelIndex
- persistentIndexList(self) List[QModelIndex] ¶
- receivers(self, PYQT_SIGNAL) int ¶
- removeExpression(self)¶
Removes any custom expression from the model.
See also
See also
- resetInternalData(self)¶
- rowCount(self, parent: QModelIndex = QModelIndex()) int ¶
- Parameters:
parent (QModelIndex = QModelIndex()) –
- Return type:
int
- sender(self) QObject ¶
- senderSignalIndex(self) int ¶
- setAllowEmptyFieldName(self, allowEmpty: bool)¶
Sets whether an optional empty field (“not set”) option is present in the model.
See also
- Parameters:
allowEmpty (bool) –
- setAllowExpression(self, allowExpression: bool)¶
Sets whether custom expressions are accepted and displayed in the model.
See also
See also
- Parameters:
allowExpression (bool) –
- setExpression(self, expression: str)¶
Sets a single expression to be added after the fields at the end of the model.
See also
See also
See also
- Parameters:
expression (str) –
- setFields(self, fields: QgsFields)¶
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
New in version 3.14.
- Parameters:
fields (QgsFields) –
- setLayer(self, layer: QgsVectorLayer)¶
Set the layer from which fields are displayed.
See also
- Parameters:
layer (QgsVectorLayer) –
- timerEvent(self, QTimerEvent)¶
- updateModel(self)¶
Called when the model must be updated.