Class: QgsFieldMappingWidget

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 an inline panel.

QWidget

QObject

QPaintDevice

class qgis.gui.QgsFieldMappingWidget[source]

Bases: QgsPanelWidget

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

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.

Since QGIS 3.44, the nativeTypes argument can be used to specify the list of field types natively supported by a data provider. If this list is non-empty, then the destination field types will be populated accordingly. If the list is empty, then a set of default native types will be used instead.

Parameters:
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]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

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])

setNativeTypes(self, nativeTypes: Iterable[QgsVectorDataProvider.NativeType])[source]

Sets the list of nativeTypes supported by a data provider.

If this list is non-empty, then the destination field types will be populated accordingly. If the list is empty, then a set of default native types will be used instead.

Added in version 3.44.

Parameters:

nativeTypes (Iterable[QgsVectorDataProvider.NativeType])

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]