QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
qgsfieldconstraints.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldconstraints.cpp
3  -----------------------
4  Date : November 2016
5  Copyright : (C) 2016 by Nyall Dawson
6  email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 #include "qgsfieldconstraints.h"
16 
18 
20 {
21  if ( !( mConstraints & constraint ) )
23 
24  return mConstraintOrigins.value( constraint, ConstraintOriginNotSet );
25 }
26 
28 {
29  if ( !( mConstraints & constraint ) )
31 
32  // defaults to hard strength unless explicitly set
33  return mConstraintStrengths.value( constraint, ConstraintStrengthHard );
34 }
35 
37 {
38  if ( strength == ConstraintStrengthNotSet )
39  {
40  mConstraintStrengths.remove( constraint );
41  }
42  else
43  {
44  mConstraintStrengths.insert( constraint, strength );
45  }
46 }
47 
49 {
50  if ( origin == ConstraintOriginNotSet )
51  {
52  mConstraints &= ~constraint;
53  mConstraintOrigins.remove( constraint );
54  mConstraintStrengths.remove( constraint );
55  }
56  else
57  {
58  mConstraints |= constraint;
59  mConstraintOrigins.insert( constraint, origin );
60  if ( !mConstraintStrengths.contains( constraint ) )
61  {
62  mConstraintStrengths.insert( constraint, ConstraintStrengthHard );
63  }
64  }
65 }
66 
68 {
69  return ( mConstraints & QgsFieldConstraints::ConstraintExpression ) ? mExpressionConstraint : QString();
70 }
71 
72 void QgsFieldConstraints::setConstraintExpression( const QString &expression, const QString &description )
73 {
74  if ( expression.isEmpty() )
76  else
77  {
80  }
81 
82  mExpressionConstraint = expression;
83  mExpressionConstraintDescription = description;
84 }
85 
87 {
88  return mConstraints == other.mConstraints && mConstraintOrigins == other.mConstraintOrigins
89  && mExpressionConstraint == other.mExpressionConstraint && mExpressionConstraintDescription == other.mExpressionConstraintDescription
90  && mConstraintStrengths == other.mConstraintStrengths;
91 }
QgsFieldConstraints::setConstraintExpression
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
Definition: qgsfieldconstraints.cpp:72
QgsFieldConstraints::setConstraint
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
Definition: qgsfieldconstraints.cpp:48
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:33
QgsFieldConstraints::constraintExpression
QString constraintExpression() const
Returns the constraint expression for the field, if set.
Definition: qgsfieldconstraints.cpp:67
QgsFieldConstraints::QgsFieldConstraints
QgsFieldConstraints()
Constructor for QgsFieldConstraints.
QgsFieldConstraints::Constraint
Constraint
Constraints which may be present on a field.
Definition: qgsfieldconstraints.h:44
QgsFieldConstraints::setConstraintStrength
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
Definition: qgsfieldconstraints.cpp:36
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:55
QgsFieldConstraints::operator==
bool operator==(const QgsFieldConstraints &other) const
Definition: qgsfieldconstraints.cpp:86
QgsFieldConstraints::ConstraintOriginLayer
@ ConstraintOriginLayer
Constraint was set by layer.
Definition: qgsfieldconstraints.h:58
QgsFieldConstraints::ConstraintStrengthNotSet
@ ConstraintStrengthNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:66
QgsFieldConstraints::ConstraintStrengthHard
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
Definition: qgsfieldconstraints.h:67
QgsFieldConstraints::constraintStrength
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
Definition: qgsfieldconstraints.cpp:27
QgsFieldConstraints::ConstraintOriginNotSet
@ ConstraintOriginNotSet
Constraint is not set.
Definition: qgsfieldconstraints.h:56
QgsFieldConstraints::ConstraintExpression
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
Definition: qgsfieldconstraints.h:47
qgsfieldconstraints.h
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:65
QgsFieldConstraints::constraintOrigin
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
Definition: qgsfieldconstraints.cpp:19