Class: QgsFieldCalculator

A dialog that provides calculation of new fields using existing fields, values and a set of operators.

Sample usage of the QgsFieldCalculator class:

uri = "point?crs=epsg:4326&field=id:integer"
layer = QgsVectorLayer(uri, "Scratch point layer",  "memory")
layer.startEditing()
dialog = QgsFieldCalculator(layer)
dialog.exec()
QgsFieldCalculator

QgsFieldCalculator

List of all members, including inherited members

Class Hierarchy

Inheritance diagram of qgis.gui.QgsFieldCalculator

Base classes

QDialog

QWidget

QObject

QPaintDevice

Methods

changedAttributeId

Returns the field index of the field for which new attribute values were calculated.

class qgis.gui.QgsFieldCalculator[source]

Bases: QDialog

__init__(vl: QgsVectorLayer | None, parent: QWidget | None = None, fieldIndex: int = -1)

Constructor for QgsFieldCalculator, with the specified parent widget.

The target layer must be specified using the vl argument.

Since QGIS 4.2, the optional fieldIndex argument can be used to automatically select the existing field with the specified index in the dialog.

Parameters:
changedAttributeId(self) int[source]

Returns the field index of the field for which new attribute values were calculated.

Return type:

int

Returns:

The field index if attribute values were calculated or -1, e.g. in case of geometry changes.