QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgsfieldconstraints.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsfieldconstraints.h
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 
16 #ifndef QGSFIELDCONSTRAINTS_H
17 #define QGSFIELDCONSTRAINTS_H
18 
19 #include <QString>
20 #include <QHash>
21 #include <QObject>
22 
23 #include "qgis_core.h"
24 
32 class CORE_EXPORT QgsFieldConstraints
33 {
34  Q_GADGET
35 
36  Q_PROPERTY( Constraints constraints READ constraints )
37 
38  public:
39 
44  {
45  ConstraintNotNull = 1,
46  ConstraintUnique = 1 << 1,
47  ConstraintExpression = 1 << 2,
48  };
49  Q_DECLARE_FLAGS( Constraints, Constraint )
50 
51 
55  {
56  ConstraintOriginNotSet = 0,
59  };
60 
65  {
66  ConstraintStrengthNotSet = 0,
69  };
70 
75 
81  Constraints constraints() const { return mConstraints; }
82 
88  ConstraintOrigin constraintOrigin( Constraint constraint ) const;
89 
96  ConstraintStrength constraintStrength( Constraint constraint ) const;
97 
103  void setConstraintStrength( Constraint constraint, ConstraintStrength strength );
104 
110  void setConstraint( Constraint constraint, ConstraintOrigin origin = ConstraintOriginLayer );
111 
117  void removeConstraint( Constraint constraint ) { mConstraints &= ~constraint; }
118 
125  QString constraintExpression() const;
126 
133  QString constraintDescription() const { return mExpressionConstraintDescription; }
134 
142  void setConstraintExpression( const QString &expression, const QString &description = QString() );
143 
150  QString domainName() const { return mDomainName; }
151 
158  void setDomainName( const QString &domain ) { mDomainName = domain; }
159 
160  // TODO c++20 - replace with = default
161  bool operator==( const QgsFieldConstraints &other ) const;
162 
163  private:
164 
166  Constraints mConstraints;
167 
169  QHash< Constraint, ConstraintOrigin > mConstraintOrigins;
170 
172  QHash< Constraint, ConstraintStrength > mConstraintStrengths;
173 
175  QString mExpressionConstraint;
176 
178  QString mExpressionConstraintDescription;
179 
181  QString mDomainName;
182 };
183 
184 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsFieldConstraints::Constraints )
185 
186 #endif //QGSFIELDCONSTRAINTS_H
operator==
bool operator==(const QgsFeatureIterator &fi1, const QgsFeatureIterator &fi2)
Definition: qgsfeatureiterator.h:425
QgsFieldConstraints
Stores information about constraints which may be present on a field.
Definition: qgsfieldconstraints.h:32
QgsFieldConstraints::ConstraintStrengthSoft
@ ConstraintStrengthSoft
User is warned if constraint is violated but feature can still be accepted.
Definition: qgsfieldconstraints.h:68
QgsFieldConstraints::Constraint
Constraint
Constraints which may be present on a field.
Definition: qgsfieldconstraints.h:43
QgsFieldConstraints::domainName
QString domainName() const
Returns the associated field domain name, for providers which support field domains.
Definition: qgsfieldconstraints.h:150
QgsFieldConstraints::constraints
Constraints constraints() const
Returns any constraints which are present for the field.
Definition: qgsfieldconstraints.h:81
QgsFieldConstraints::removeConstraint
void removeConstraint(Constraint constraint)
Removes a constraint from the field.
Definition: qgsfieldconstraints.h:117
QgsFieldConstraints::ConstraintOrigin
ConstraintOrigin
Origin of constraints.
Definition: qgsfieldconstraints.h:54
QgsFieldConstraints::ConstraintOriginLayer
@ ConstraintOriginLayer
Constraint was set by layer.
Definition: qgsfieldconstraints.h:58
Q_DECLARE_OPERATORS_FOR_FLAGS
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.
QgsFieldConstraints::setDomainName
void setDomainName(const QString &domain)
Sets the associated field domain name, for providers which support field domains.
Definition: qgsfieldconstraints.h:158
QgsFieldConstraints::ConstraintStrengthHard
@ ConstraintStrengthHard
Constraint must be honored before feature can be accepted.
Definition: qgsfieldconstraints.h:67
QgsFieldConstraints::constraintDescription
QString constraintDescription() const
Returns the descriptive name for the constraint expression.
Definition: qgsfieldconstraints.h:133
QgsFieldConstraints::ConstraintOriginProvider
@ ConstraintOriginProvider
Constraint was set at data provider.
Definition: qgsfieldconstraints.h:57
QgsFieldConstraints::ConstraintStrength
ConstraintStrength
Strength of constraints.
Definition: qgsfieldconstraints.h:64