QgsFieldConstraints class

Stores information about constraints which may be present on a field.

Public types

enum Constraint { ConstraintNotNull = 1, ConstraintUnique = 1 << 1, ConstraintExpression = 1 << 2 }
Constraints which may be present on a field.
enum ConstraintOrigin { ConstraintOriginNotSet = 0, ConstraintOriginProvider, ConstraintOriginLayer }
Origin of constraints.
enum ConstraintStrength { ConstraintStrengthNotSet = 0, ConstraintStrengthHard, ConstraintStrengthSoft }
Strength of constraints.

Constructors, destructors, conversion operators

QgsFieldConstraints()
Constructor for QgsFieldConstraints.

Public functions

auto constraintDescription() const -> QString
Returns the descriptive name for the constraint expression.
auto constraintExpression() const -> QString
Returns the constraint expression for the field, if set.
auto constraintOrigin(Constraint constraint) const -> ConstraintOrigin
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present on this field.
auto constraints() const -> Constraints
Returns any constraints which are present for the field.
auto constraintStrength(Constraint constraint) const -> ConstraintStrength
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not present on this field.
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
void setConstraint(Constraint constraint, ConstraintOrigin origin = ConstraintOriginLayer)
Sets a constraint on the field.
void setConstraintExpression(const QString& expression, const QString& description = QString())
Set the constraint expression for the field.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.

Enum documentation

enum QgsFieldConstraints::Constraint

Constraints which may be present on a field.

Enumerators
ConstraintNotNull

Field may not be null.

ConstraintUnique

Field must have a unique value.

ConstraintExpression

Field has an expression constraint set. See constraintExpression().

enum QgsFieldConstraints::ConstraintOrigin

Origin of constraints.

Enumerators
ConstraintOriginNotSet

Constraint is not set.

ConstraintOriginProvider

Constraint was set at data provider.

ConstraintOriginLayer

Constraint was set by layer.

enum QgsFieldConstraints::ConstraintStrength

Strength of constraints.

Enumerators
ConstraintStrengthNotSet

Constraint is not set.

ConstraintStrengthHard

Constraint must be honored before feature can be accepted.

ConstraintStrengthSoft

User is warned if constraint is violated but feature can still be accepted.

Function documentation

QString QgsFieldConstraints::constraintDescription() const

Returns the descriptive name for the constraint expression.

QString QgsFieldConstraints::constraintExpression() const

Returns the constraint expression for the field, if set.

ConstraintOrigin QgsFieldConstraints::constraintOrigin(Constraint constraint) const

Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present on this field.

Constraints QgsFieldConstraints::constraints() const

Returns any constraints which are present for the field.

ConstraintStrength QgsFieldConstraints::constraintStrength(Constraint constraint) const

Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not present on this field.

void QgsFieldConstraints::removeConstraint(Constraint constraint)

Removes a constraint from the field.

void QgsFieldConstraints::setConstraint(Constraint constraint, ConstraintOrigin origin = ConstraintOriginLayer)

Sets a constraint on the field.

void QgsFieldConstraints::setConstraintExpression(const QString& expression, const QString& description = QString())

Set the constraint expression for the field.

An optional descriptive name for the constraint can also be set. Setting an empty expression will clear any existing expression constraint.

void QgsFieldConstraints::setConstraintStrength(Constraint constraint, ConstraintStrength strength)

Sets the strength of a constraint.

Note that the strength of constraints which originate from a provider cannot be changed. Constraints default to ConstraintStrengthHard unless explicitly changed.