Class: QgsFieldMappingModel

class qgis.gui.QgsFieldMappingModel

Bases: PyQt5.QtCore.QAbstractTableModel

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.

QgsFieldMappingModel(sourceFields: QgsFields = QgsFields(), destinationFields: QgsFields = QgsFields(), expressions: Dict[str, str] = {}, parent: QObject = 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.

Enums

ColumnDataIndex

Bases: enum.IntEnum

Methods

appendField

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

beginInsertColumns

beginInsertRows

beginMoveColumns

beginMoveRows

beginRemoveColumns

beginRemoveRows

beginResetModel

changePersistentIndex

changePersistentIndexList

childEvent

columnCount

param parent:

connectNotify

contextGenerator

Returns the context generator with the source fields

createIndex

customEvent

data

param index:

dataTypes

Returns a static map of supported data types

decodeData

destinationEditable

Returns True if the destination fields are editable

disconnectNotify

encodeData

endInsertColumns

endInsertRows

endMoveColumns

endMoveRows

endRemoveColumns

endRemoveRows

endResetModel

fieldPropertyMap

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

flags

param index:

headerData

param section:

isSignalConnected

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

persistentIndexList

receivers

removeField

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

resetInternalData

rowCount

param parent:

sender

senderSignalIndex

setBaseExpressionContextGenerator

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

setData

param index:

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.

setSourceFields

Set source fields to sourceFields

sourceFields

Returns a list of source fields

timerEvent

class ColumnDataIndex(value)

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
class Field(QgsFieldMappingModel.Field)

Bases: sip.wrapper

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

QgsFieldMappingModel.beginInsertColumns(self, QModelIndex, int, int)
QgsFieldMappingModel.beginInsertRows(self, QModelIndex, int, int)
QgsFieldMappingModel.beginMoveColumns(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsFieldMappingModel.beginMoveRows(self, QModelIndex, int, int, QModelIndex, int) -> bool
QgsFieldMappingModel.beginRemoveColumns(self, QModelIndex, int, int)
QgsFieldMappingModel.beginRemoveRows(self, QModelIndex, int, int)
beginResetModel(self)
QgsFieldMappingModel.changePersistentIndex(self, QModelIndex, QModelIndex)
changePersistentIndexList(self, Iterable[QModelIndex], Iterable[QModelIndex])
childEvent(self, QChildEvent)
columnCount(self, parent: QModelIndex = QModelIndex()) int
Parameters:

parent (QModelIndex = QModelIndex()) –

Return type:

int

connectNotify(self, QMetaMethod)
contextGenerator(self) QgsExpressionContextGenerator

Returns the context generator with the source fields

Return type:

QgsExpressionContextGenerator

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

dataTypes() Dict[QVariant.Type, str]

Returns a static map of supported data types

Return type:

Dict[QVariant.Type, str]

QgsFieldMappingModel.decodeData(self, int, int, QModelIndex, QDataStream) -> bool
destinationEditable(self) bool

Returns True if the destination fields are editable

Return type:

bool

disconnectNotify(self, QMetaMethod)
encodeData(self, Iterable[QModelIndex], QDataStream)
endInsertColumns(self)
endInsertRows(self)
endMoveColumns(self)
endMoveRows(self)
endRemoveColumns(self)
endRemoveRows(self)
endResetModel(self)
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(self, QMetaMethod) bool
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(self) List[QModelIndex]
receivers(self, PYQT_SIGNAL) int
removeField(self, index: QModelIndex) bool

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

Parameters:

index (QModelIndex) –

Return type:

bool

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

parent (QModelIndex = QModelIndex()) –

Return type:

int

sender(self) QObject
senderSignalIndex(self) int
setBaseExpressionContextGenerator(self, generator: QgsExpressionContextGenerator)

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

Parameters:

generator (QgsExpressionContextGenerator) –

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(self, QTimerEvent)