QGIS API Documentation 3.41.0-Master (45a0abf3bec)
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#include "moc_qgsfieldconstraints.cpp"
17
19
21{
22 if ( !( mConstraints & constraint ) )
24
25 return mConstraintOrigins.value( constraint, ConstraintOriginNotSet );
26}
27
29{
30 if ( !( mConstraints & constraint ) )
32
33 // defaults to not set for all but expressions (which does not use strength)
34 return mConstraintStrengths.value( constraint, constraint == ConstraintExpression ? ConstraintStrengthHard : ConstraintStrengthNotSet );
35}
36
38{
39 if ( strength == ConstraintStrengthNotSet )
40 {
41 mConstraintStrengths.remove( constraint );
42 }
43 else
44 {
45 mConstraintStrengths.insert( constraint, strength );
46 }
47}
48
50{
51 if ( origin == ConstraintOriginNotSet )
52 {
53 mConstraints &= ~constraint;
54 mConstraintOrigins.remove( constraint );
55 mConstraintStrengths.remove( constraint );
56 }
57 else
58 {
59 mConstraints |= constraint;
60 mConstraintOrigins.insert( constraint, origin );
61 if ( !mConstraintStrengths.contains( constraint ) )
62 {
63 mConstraintStrengths.insert( constraint, ConstraintStrengthHard );
64 }
65 }
66}
67
69{
70 return ( mConstraints & QgsFieldConstraints::ConstraintExpression ) ? mExpressionConstraint : QString();
71}
72
73void QgsFieldConstraints::setConstraintExpression( const QString &expression, const QString &description )
74{
75 if ( expression.isEmpty() )
77 else
78 {
81 }
82
83 mExpressionConstraint = expression;
84 mExpressionConstraintDescription = description;
85}
86
88{
89 return mConstraints == other.mConstraints && mConstraintOrigins == other.mConstraintOrigins
90 && mExpressionConstraint == other.mExpressionConstraint && mExpressionConstraintDescription == other.mExpressionConstraintDescription
91 && mConstraintStrengths == other.mConstraintStrengths
92 && mDomainName == other.mDomainName;
93}
Stores information about constraints which may be present on a field.
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.