Class: QgsFieldMappingWidget

The QgsFieldMappingWidget class creates a mapping from one set of QgsFields to another, for each set of “destination” fields an expression defines how to obtain the values of the “destination” fields.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFieldMappingWidget

Base classes

QgsPanelWidget

Base class for any widget that can be shown as a inline panel

QWidget

QObject

QPaintDevice

Methods

appendField

Appends a new field to the model, with an optional expression

destinationEditable

Returns True if the destination fields are editable in the model

fieldPropertyMap

Returns a map of destination field name to QgsProperty definition for field value, representing the current status of the widget.

invertSelection

Invert the field selection state.

mapping

Returns a list of Field objects representing the current status of the underlying mapping model

model

Returns the underlying mapping model

moveSelectedFieldsDown

Moves down the currently selected field

moveSelectedFieldsUp

Moves up currently selected field

registerExpressionContextGenerator

Register an expression context generator class that will be used to retrieve an expression context for the widget.

removeSelectedFields

Removes the currently selected field from the model

scrollTo

Scroll the fields view to index

selectionModel

Returns the selection model

setDestinationEditable

Sets the destination fields editable state to editable

setDestinationFields

Set destination fields to destinationFields in the underlying model, initial values for the expressions can be optionally specified through expressions which is a map from the original field name to the corresponding expression.

setFieldPropertyMap

Sets a map of destination field name to QgsProperty definition for field value.

setSourceFields

Set source fields of the underlying mapping model to sourceFields

setSourceLayer

Sets a source layer to use when generating expression previews in the widget.

sourceLayer

Returns the source layer for use when generating expression previews.

Signals

changed

Emitted when the fields defined in the widget are changed.

class qgis.gui.QgsFieldMappingWidget[source]

Bases: QgsPanelWidget

__init__(parent: QWidget | None = None, sourceFields: QgsFields = QgsFields(), destinationFields: QgsFields = QgsFields(), expressions: Dict[str | None, str | None] = {})

Constructs a QgsFieldMappingWidget from a set of sourceFields and destinationFields, initial values for the expressions can be optionally specified through expressions which is a map from the original field name to the corresponding expression. A parent object can also be specified.

Parameters:
  • parent (Optional[QWidget] = None)

  • sourceFields (QgsFields = QgsFields())

  • destinationFields (QgsFields = QgsFields())

  • expressions (Dict[Optional[str], Optional[str]] = {})

appendField(self, field: QgsField, expression: str | None = '')[source]

Appends a new field to the model, with an optional expression

Parameters:
  • field (QgsField)

  • expression (Optional[str] = '')

signal changed[source]

Emitted when the fields defined in the widget are changed.

destinationEditable(self) bool[source]

Returns True if the destination fields are editable in the model

Return type:

bool

fieldPropertyMap(self) Dict[str, QgsProperty]

Returns a map of destination field name to QgsProperty definition for field value, representing the current status of the widget.

Return type:

Dict[str, QgsProperty]

invertSelection(self)[source]

Invert the field selection state.

Added in version 3.32.

mapping(self) List[QgsFieldMappingModel.Field]

Returns a list of Field objects representing the current status of the underlying mapping model

Return type:

List[QgsFieldMappingModel.Field]

model(self) QgsFieldMappingModel | None[source]

Returns the underlying mapping model

Return type:

Optional[QgsFieldMappingModel]

moveSelectedFieldsDown(self) bool[source]

Moves down the currently selected field

Return type:

bool

moveSelectedFieldsUp(self) bool[source]

Moves up currently selected field

Return type:

bool

registerExpressionContextGenerator(self, generator: QgsExpressionContextGenerator | None)[source]

Register an expression context generator class that will be used to retrieve an expression context for the widget.

Parameters:

generator (Optional[QgsExpressionContextGenerator])

removeSelectedFields(self) bool[source]

Removes the currently selected field from the model

Return type:

bool

scrollTo(self, index: QModelIndex)[source]

Scroll the fields view to index

Parameters:

index (QModelIndex)

selectionModel(self) QItemSelectionModel | None[source]

Returns the selection model

Return type:

Optional[QItemSelectionModel]

setDestinationEditable(self, editable: bool)[source]

Sets the destination fields editable state to editable

Parameters:

editable (bool)

setDestinationFields(self, destinationFields: QgsFields, expressions: Dict[str | None, str | None] = {})[source]

Set destination fields to destinationFields in the underlying model, initial values for the expressions can be optionally specified through expressions which is a map from the original field name to the corresponding expression.

Parameters:
  • destinationFields (QgsFields)

  • expressions (Dict[Optional[str], Optional[str]] = {})

setFieldPropertyMap(self, map: Dict[str | None, QgsProperty])[source]

Sets a map of destination field name to QgsProperty definition for field value.

Parameters:

map (Dict[Optional[str], QgsProperty])

setSourceFields(self, sourceFields: QgsFields)[source]

Set source fields of the underlying mapping model to sourceFields

Parameters:

sourceFields (QgsFields)

setSourceLayer(self, layer: QgsVectorLayer | None)[source]

Sets a source layer to use when generating expression previews in the widget.

Added in version 3.16.

Parameters:

layer (Optional[QgsVectorLayer])

sourceLayer(self) QgsVectorLayer | None[source]

Returns the source layer for use when generating expression previews.

Returned value may be None.

Added in version 3.16.

Return type:

Optional[QgsVectorLayer]