QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
Public Types | Public Member Functions | Properties | List of all members
QgsFieldConstraints Class Reference

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

#include <qgsfieldconstraints.h>

Public Types

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

Public Member Functions

 QgsFieldConstraints ()
 Constructor for QgsFieldConstraints. More...
 
QString constraintDescription () const
 Returns the descriptive name for the constraint expression. More...
 
QString constraintExpression () const
 Returns the constraint expression for the field, if set. More...
 
ConstraintOrigin constraintOrigin (Constraint constraint) const
 Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present on this field. More...
 
Constraints constraints () const
 Returns any constraints which are present for the field. More...
 
ConstraintStrength constraintStrength (Constraint constraint) const
 Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not present on this field. More...
 
QString domainName () const
 Returns the associated field domain name, for providers which support field domains. More...
 
bool operator== (const QgsFieldConstraints &other) const
 
void removeConstraint (Constraint constraint)
 Removes a constraint from the field. More...
 
void setConstraint (Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
 Sets a constraint on the field. More...
 
void setConstraintExpression (const QString &expression, const QString &description=QString())
 Set the constraint expression for the field. More...
 
void setConstraintStrength (Constraint constraint, ConstraintStrength strength)
 Sets the strength of a constraint. More...
 
void setDomainName (const QString &domain)
 Sets the associated field domain name, for providers which support field domains. More...
 

Properties

Q_GADGET Constraints constraints
 

Detailed Description

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

Since
QGIS 3.0

Definition at line 32 of file qgsfieldconstraints.h.

Member Enumeration Documentation

◆ Constraint

Constraints which may be present on a field.

Enumerator
ConstraintNotNull 

Field may not be null.

ConstraintUnique 

Field must have a unique value.

ConstraintExpression 

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

Definition at line 43 of file qgsfieldconstraints.h.

◆ ConstraintOrigin

Origin of constraints.

Enumerator
ConstraintOriginNotSet 

Constraint is not set.

ConstraintOriginProvider 

Constraint was set at data provider.

ConstraintOriginLayer 

Constraint was set by layer.

Definition at line 54 of file qgsfieldconstraints.h.

◆ ConstraintStrength

Strength of constraints.

Enumerator
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.

Definition at line 64 of file qgsfieldconstraints.h.

Constructor & Destructor Documentation

◆ QgsFieldConstraints()

QgsFieldConstraints::QgsFieldConstraints ( )
default

Constructor for QgsFieldConstraints.

Member Function Documentation

◆ constraintDescription()

QString QgsFieldConstraints::constraintDescription ( ) const
inline

Returns the descriptive name for the constraint expression.

See also
constraints()
constraintExpression()
setConstraintExpression()

Definition at line 133 of file qgsfieldconstraints.h.

◆ constraintExpression()

QString QgsFieldConstraints::constraintExpression ( ) const

Returns the constraint expression for the field, if set.

See also
constraints()
constraintDescription()
setConstraintExpression()

Definition at line 67 of file qgsfieldconstraints.cpp.

◆ constraintOrigin()

QgsFieldConstraints::ConstraintOrigin QgsFieldConstraints::constraintOrigin ( QgsFieldConstraints::Constraint  constraint) const

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

See also
constraints()

Definition at line 19 of file qgsfieldconstraints.cpp.

◆ constraints()

Constraints QgsFieldConstraints::constraints ( ) const
inline

Returns any constraints which are present for the field.

See also
setConstraint()
constraintOrigin()

Definition at line 81 of file qgsfieldconstraints.h.

◆ constraintStrength()

QgsFieldConstraints::ConstraintStrength QgsFieldConstraints::constraintStrength ( QgsFieldConstraints::Constraint  constraint) const

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

See also
constraints()
setConstraintStrength()

Definition at line 27 of file qgsfieldconstraints.cpp.

◆ domainName()

QString QgsFieldConstraints::domainName ( ) const
inline

Returns the associated field domain name, for providers which support field domains.

See also
setDomainName()
Since
QGIS 3.26

Definition at line 150 of file qgsfieldconstraints.h.

◆ operator==()

bool QgsFieldConstraints::operator== ( const QgsFieldConstraints other) const

Definition at line 86 of file qgsfieldconstraints.cpp.

◆ removeConstraint()

void QgsFieldConstraints::removeConstraint ( Constraint  constraint)
inline

Removes a constraint from the field.

See also
setConstraint()
constraints()

Definition at line 117 of file qgsfieldconstraints.h.

◆ setConstraint()

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

Sets a constraint on the field.

See also
constraints()
removeConstraint()

Definition at line 48 of file qgsfieldconstraints.cpp.

◆ setConstraintExpression()

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.

See also
constraintExpression()
constraintDescription()
constraints()

Definition at line 72 of file qgsfieldconstraints.cpp.

◆ setConstraintStrength()

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

Sets the strength of a constraint.

Constraints default to ConstraintStrengthHard unless explicitly changed.

See also
constraintStrength()

Definition at line 36 of file qgsfieldconstraints.cpp.

◆ setDomainName()

void QgsFieldConstraints::setDomainName ( const QString &  domain)
inline

Sets the associated field domain name, for providers which support field domains.

See also
domainName()
Since
QGIS 3.26

Definition at line 158 of file qgsfieldconstraints.h.

Property Documentation

◆ constraints

Q_GADGET Constraints QgsFieldConstraints::constraints
read

Definition at line 34 of file qgsfieldconstraints.h.


The documentation for this class was generated from the following files: