Subgroup: Default

Class: QgsDefaultValue

class qgis.core.QgsDefaultValue(expression: str = '', applyOnUpdate: bool = False)

Bases: sip.wrapper

Create a new default value with the given expression and applyOnUpdate flag.

QgsDefaultValue(QgsDefaultValue)

The QgsDefaultValue class provides a container for managing client

side default values for fields.

A QgsDefaultValue consists of an expression string that will be evaluated on the client when a defeault field value needs to be generated.

Usual values for such an expression are

  • now() for a timestamp for a record
  • @some_variable to insert a project or application level variable like

the username of the one digitizing a feature - $length to insert a derived attribute of a geometry

QgsDefaultValue also has a applyOnUpdate flag which will indicate that a default value should also be applied when a feature is updated. If this is not set, the default value will only be used when a feature is created.

New in version 3.0: Methods

applyOnUpdate The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it’s created.
expression The expression will be evaluated whenever a default value needs to be calculated for a field.
isValid Returns if this default value should be applied.
setApplyOnUpdate The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it’s created.
setExpression The expression will be evaluated whenever a default value needs to be calculated for a field.

Signals

Attributes

applyOnUpdate(self) → bool

The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it’s created.

expression(self) → str

The expression will be evaluated whenever a default value needs to be calculated for a field.

isValid(self) → bool

Returns if this default value should be applied.

Returns:false if the expression is a null string.
setApplyOnUpdate(self, applyOnUpdate: bool)

The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it’s created.

setExpression(self, expression: str)

The expression will be evaluated whenever a default value needs to be calculated for a field.