QgsDefaultValue class

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.

Constructors, destructors, conversion operators

QgsDefaultValue(const QString& expression = QString(), bool applyOnUpdate = false) explicit
Create a new default value with the given expression and applyOnUpdate flag.
operator bool()
Checks if a default value is set.

Public functions

auto applyOnUpdate() const -> bool
The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it's created.
auto expression() const -> QString
The expression will be evaluated whenever a default value needs to be calculated for a field.
auto isValid() const -> bool
Returns if this default value should be applied.
void setApplyOnUpdate(bool applyOnUpdate)
The applyOnUpdate flag determines if this expression should also be applied when a feature is updated or only when it's created.
void setExpression(const QString& expression)
The expression will be evaluated whenever a default value needs to be calculated for a field.

Function documentation

QgsDefaultValue::QgsDefaultValue(const QString& expression = QString(), bool applyOnUpdate = false) explicit

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

QgsDefaultValue::operator bool()

Checks if a default value is set.

Returns false if the expression is a null string.

Alias for isValid().

bool QgsDefaultValue::isValid() const

Returns if this default value should be applied.

Returns false if the expression is a null string.