QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
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
17#include "moc_qgsfieldconstraints.cpp"
18
20
22{
23 if ( !( mConstraints & constraint ) )
25
26 return mConstraintOrigins.value( constraint, ConstraintOriginNotSet );
27}
28
30{
31 if ( !( mConstraints & constraint ) )
33
34 // defaults to not set for all but expressions (which does not use strength)
35 return mConstraintStrengths.value( constraint, constraint == ConstraintExpression ? ConstraintStrengthHard : ConstraintStrengthNotSet );
36}
37
39{
40 if ( strength == ConstraintStrengthNotSet )
41 {
42 mConstraintStrengths.remove( constraint );
43 }
44 else
45 {
46 mConstraintStrengths.insert( constraint, strength );
47 }
48}
49
51{
52 if ( origin == ConstraintOriginNotSet )
53 {
54 mConstraints &= ~constraint;
55 mConstraintOrigins.remove( constraint );
56 mConstraintStrengths.remove( constraint );
57 }
58 else
59 {
60 mConstraints |= constraint;
61 mConstraintOrigins.insert( constraint, origin );
62 if ( !mConstraintStrengths.contains( constraint ) )
63 {
64 mConstraintStrengths.insert( constraint, ConstraintStrengthHard );
65 }
66 }
67}
68
70{
71 return ( mConstraints & QgsFieldConstraints::ConstraintExpression ) ? mExpressionConstraint : QString();
72}
73
74void QgsFieldConstraints::setConstraintExpression( const QString &expression, const QString &description )
75{
76 if ( expression.isEmpty() )
78 else
79 {
82 }
83
84 mExpressionConstraint = expression;
85 mExpressionConstraintDescription = description;
86}
87
89{
90 return mConstraints == other.mConstraints && mConstraintOrigins == other.mConstraintOrigins
91 && mExpressionConstraint == other.mExpressionConstraint && mExpressionConstraintDescription == other.mExpressionConstraintDescription
92 && mConstraintStrengths == other.mConstraintStrengths
93 && mDomainName == other.mDomainName;
94}
ConstraintStrength
Strength of constraints.
@ ConstraintStrengthNotSet
Constraint is not set.
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
void setConstraintStrength(Constraint constraint, ConstraintStrength strength)
Sets the strength of a constraint.
void setConstraintExpression(const QString &expression, const QString &description=QString())
Set the constraint expression for the field.
ConstraintOrigin
Origin of constraints.
@ ConstraintOriginNotSet
Constraint is not set.
@ ConstraintOriginLayer
Constraint was set by layer.
ConstraintStrength constraintStrength(Constraint constraint) const
Returns the strength of a field constraint, or ConstraintStrengthNotSet if the constraint is not pres...
ConstraintOrigin constraintOrigin(Constraint constraint) const
Returns the origin of a field constraint, or ConstraintOriginNotSet if the constraint is not present ...
QString constraintExpression() const
Returns the constraint expression for the field, if set.
bool operator==(const QgsFieldConstraints &other) const
Constraint
Constraints which may be present on a field.
@ ConstraintExpression
Field has an expression constraint set. See constraintExpression().
void setConstraint(Constraint constraint, ConstraintOrigin origin=ConstraintOriginLayer)
Sets a constraint on the field.
QgsFieldConstraints()
Constructor for QgsFieldConstraints.