Class: QgsFieldMappingModel

Holds mapping information for 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.

The model can be optionally set “editable” allowing to modify all the fields, by default only the mapping expression is editable.

Added in version 3.14.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFieldMappingModel

Base classes

QAbstractTableModel

QAbstractItemModel

QObject

Enums

ColumnDataIndex

The ColumnDataIndex enum represents the column index for the view

Methods

appendField

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

contextGenerator

Returns the context generator with the source fields

dataTypes

Returns a static map of supported data types

destinationEditable

Returns True if the destination fields are editable

fieldPropertyMap

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

mapping

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

moveDown

Moves up the field at index

moveUp

Moves down the field at index

removeField

Removes the field at index from the model, returns True on success

setBaseExpressionContextGenerator

Sets the base expression context generator, which will generate the expression contexts for expression based widgets used by the model.

setDestinationEditable

Sets the destination fields editable state to editable

setDestinationFields

Set destination fields to 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.

setFieldPropertyMap

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

setNativeTypes

Sets the list of nativeTypes supported by a data provider.

setSourceFields

Set source fields to sourceFields

sourceFields

Returns a list of source fields

supportedDataTypes

Returns a static list of supported data types

class qgis.gui.QgsFieldMappingModel[source]

Bases: QAbstractTableModel

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

Constructs a QgsFieldMappingModel 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 be also specified.

Parameters:
  • sourceFields (QgsFields = QgsFields())

  • destinationFields (QgsFields = QgsFields())

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

  • parent (Optional[QObject] = None)

class ColumnDataIndex(*values)

Bases: IntEnum

The ColumnDataIndex enum represents the column index for the view

  • SourceExpression: Expression

  • DestinationName: Destination field name

  • DestinationType: Destination field type string

  • DestinationLength: Destination field length

  • DestinationPrecision: Destination field precision

  • DestinationConstraints: Destination field constraints

  • DestinationAlias: Destination alias

  • DestinationComment: Destination comment

DestinationAlias = 6
DestinationComment = 7
DestinationConstraints = 5
DestinationLength = 3
DestinationName = 1
DestinationPrecision = 4
DestinationType = 2
SourceExpression = 0
class Field

Bases: object

The Field struct holds information about a mapped field

expression: str

The expression for the mapped field from the source fields

field: QgsField

The field in its current status (it might have been renamed)

originalName: str

The original name of the field

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

contextGenerator(self) QgsExpressionContextGenerator | None[source]

Returns the context generator with the source fields

Return type:

Optional[QgsExpressionContextGenerator]

dataTypes() Dict[QMetaType.Type, str]

Returns a static map of supported data types

Deprecated since version 3.24: Use supportedDataTypes() instead.

Return type:

Dict[QMetaType.Type, str]

destinationEditable(self) bool[source]

Returns True if the destination fields are editable

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 model.

Return type:

Dict[str, QgsProperty]

mapping(self) List[QgsFieldMappingModel.Field]

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

Return type:

List[QgsFieldMappingModel.Field]

moveDown(self, index: QModelIndex) bool[source]

Moves up the field at index

Parameters:

index (QModelIndex)

Return type:

bool

moveUp(self, index: QModelIndex) bool[source]

Moves down the field at index

Parameters:

index (QModelIndex)

Return type:

bool

removeField(self, index: QModelIndex) bool[source]

Removes the field at index from the model, returns True on success

Parameters:

index (QModelIndex)

Return type:

bool

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

Sets the base expression context generator, which will generate the expression contexts for expression based widgets used by the model.

Parameters:

generator (Optional[QgsExpressionContextGenerator])

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, 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 to sourceFields

Parameters:

sourceFields (QgsFields)

sourceFields(self) QgsFields[source]

Returns a list of source fields

Return type:

QgsFields

supportedDataTypes() List[QgsVectorDataProvider.NativeType]

Returns a static list of supported data types

Added in version 3.24.

Return type:

List[QgsVectorDataProvider.NativeType]