Class: QgsFieldMappingModel

class qgis.gui.QgsFieldMappingModel(sourceFields: QgsFields = QgsFields(), destinationFields: QgsFields = QgsFields(), expressions: Dict[str, str] = {}, parent: QObject = None)

Bases: PyQt5.QtCore.QAbstractTableModel

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.

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

New in version 3.14.

Parameters
  • sourceFields (QgsFields = QgsFields()) –

  • destinationFields (QgsFields = QgsFields()) –

  • expressions (Dict[str) –

  • parent

class ColumnDataIndex

Bases: enum.IntEnum

The ColumnDataIndex enum represents the column index for the view

  • SourceExpression: Expression

  • DestinationName: Destination field name

  • DestinationType: Destination field QVariant::Type casted to (int)

  • DestinationLength: Destination field length

  • DestinationPrecision: Destination field precision

  • DestinationConstraints: Destination field constraints

DestinationConstraints = 5
DestinationLength = 3
DestinationName = 1
DestinationPrecision = 4
DestinationType = 2
SourceExpression = 0
baseClass

alias of QgsFieldMappingModel

class Field

Bases: sip.wrapper

QgsFieldMappingModel.Field(QgsFieldMappingModel.Field)

expression
field
originalName
appendField(self, field: QgsField, expression: str = '')

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

Parameters
  • field (QgsField) –

  • expression (str = '') –

beginInsertColumns()
beginInsertRows()
beginMoveColumns()
beginMoveRows()
beginRemoveColumns()
beginRemoveRows()
beginResetModel()
changePersistentIndex()
changePersistentIndexList()
childEvent()
columnCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

int

connectNotify()
contextGenerator(self)QgsExpressionContextGenerator

Returns the context generator with the source fields

Return type

QgsExpressionContextGenerator

createIndex()
customEvent()
data(self, index: QModelIndex, role: int) → Any
Parameters
  • index (QModelIndex) –

  • role (int) –

Return type

Any

dataTypes(self) → Dict[QVariant.Type, str]

Returns a static map of supported data types

Return type

Dict[QVariant.Type, str]

decodeData()
destinationEditable(self) → bool

Returns True if the destination fields are editable

Return type

bool

disconnectNotify()
encodeData()
endInsertColumns()
endInsertRows()
endMoveColumns()
endMoveRows()
endRemoveColumns()
endRemoveRows()
endResetModel()
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]

flags(self, index: QModelIndex) → Qt.ItemFlags
Parameters

index (QModelIndex) –

Return type

Qt.ItemFlags

headerData(self, section: int, orientation: Qt.Orientation, role: int) → Any
Parameters
  • section (int) –

  • orientation (Qt.Orientation) –

  • role (int) –

Return type

Any

isSignalConnected()
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

Moves up the field at index

Parameters

index (QModelIndex) –

Return type

bool

moveUp(self, index: QModelIndex) → bool

Moves down the field at index

Parameters

index (QModelIndex) –

Return type

bool

persistentIndexList()
receivers()
removeField(self, index: QModelIndex) → bool

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

Parameters

index (QModelIndex) –

Return type

bool

resetInternalData()
rowCount(self, parent: QModelIndex = QModelIndex()) → int
Parameters

parent (QModelIndex = QModelIndex()) –

Return type

int

sender()
senderSignalIndex()
setData(self, index: QModelIndex, value: Any, role: int) → bool
Parameters
  • index (QModelIndex) –

  • value (Any) –

  • role (int) –

Return type

bool

setDestinationEditable(self, editable: bool)

Sets the destination fields editable state to editable

Parameters

editable (bool) –

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

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[str) –

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

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

Parameters

map (Dict[str) –

setSourceFields(self, sourceFields: QgsFields)

Set source fields to sourceFields

Parameters

sourceFields (QgsFields) –

sourceFields(self)QgsFields

Returns a list of source fields

Return type

QgsFields

timerEvent()