Class: QgsDefaultValue¶
-
class
qgis.core.
QgsDefaultValue
(expression: str = '', applyOnUpdate: bool = False)¶ Bases:
sip.wrapper
Create a new default value with the given
expression
andapplyOnUpdate
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 default 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.
- Parameters
expression (str = '') –
applyOnUpdate –
-
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.
- Return type
bool
-
expression
(self) → str¶ The expression will be evaluated whenever a default value needs to be calculated for a field.
- Return type
str
-
isValid
(self) → bool¶ Returns if this default value should be applied.
- Return type
bool
- 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.
- Parameters
applyOnUpdate (bool) –
-
setExpression
(self, expression: str)¶ The expression will be evaluated whenever a default value needs to be calculated for a field.
- Parameters
expression (str) –