24
24
QgsEditorWidgetWrapper::QgsEditorWidgetWrapper ( QgsVectorLayer* vl, int fieldIdx, QWidget* editor, QWidget* parent )
25
25
: QgsWidgetWrapper( vl, editor, parent )
26
26
, mValidConstraint( true )
27
+ , mIsBlockingCommit( false )
27
28
, mFieldIdx( fieldIdx )
28
29
{
29
30
}
@@ -98,12 +99,22 @@ void QgsEditorWidgetWrapper::valueChanged()
98
99
emit valueChanged ( value () );
99
100
}
100
101
101
- void QgsEditorWidgetWrapper::updateConstraintWidgetStatus ( bool constraintValid )
102
+ void QgsEditorWidgetWrapper::updateConstraintWidgetStatus ( ConstraintResult constraintResult )
102
103
{
103
- if ( constraintValid )
104
- widget ()->setStyleSheet ( QString () );
105
- else
106
- widget ()->setStyleSheet ( QStringLiteral ( " background-color: #dd7777;" ) );
104
+ switch ( constraintResult )
105
+ {
106
+ case ConstraintResultPass:
107
+ widget ()->setStyleSheet ( QString () );
108
+ break ;
109
+
110
+ case ConstraintResultFailHard:
111
+ widget ()->setStyleSheet ( QStringLiteral ( " background-color: #dd7777;" ) );
112
+ break ;
113
+
114
+ case ConstraintResultFailSoft:
115
+ widget ()->setStyleSheet ( QStringLiteral ( " background-color: #ffd85d;" ) );
116
+ break ;
117
+ }
107
118
}
108
119
109
120
void QgsEditorWidgetWrapper::updateConstraint ( const QgsFeature &ft, QgsFieldConstraints::ConstraintOrigin constraintOrigin )
@@ -150,7 +161,15 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft, QgsFieldCon
150
161
}
151
162
152
163
QStringList errors;
153
- mValidConstraint = QgsVectorLayerUtils::validateAttribute ( layer (), ft, mFieldIdx , errors, constraintOrigin );
164
+ bool hardConstraintsOk = QgsVectorLayerUtils::validateAttribute ( layer (), ft, mFieldIdx , errors, QgsFieldConstraints::ConstraintStrengthHard, constraintOrigin );
165
+
166
+ QStringList softErrors;
167
+ bool softConstraintsOk = QgsVectorLayerUtils::validateAttribute ( layer (), ft, mFieldIdx , softErrors, QgsFieldConstraints::ConstraintStrengthSoft, constraintOrigin );
168
+ errors << softErrors;
169
+
170
+ mValidConstraint = hardConstraintsOk && softConstraintsOk;
171
+ mIsBlockingCommit = !hardConstraintsOk;
172
+
154
173
mConstraintFailureReason = errors.join ( " , " );
155
174
156
175
if ( toEmit )
@@ -164,8 +183,10 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft, QgsFieldCon
164
183
else if ( !expressions.isEmpty () )
165
184
expressionDesc = expressions.at ( 0 );
166
185
167
- updateConstraintWidgetStatus ( mValidConstraint );
168
- emit constraintStatusChanged ( expressionDesc, description, errStr, mValidConstraint );
186
+ ConstraintResult result = !hardConstraintsOk ? ConstraintResultFailHard
187
+ : ( !softConstraintsOk ? ConstraintResultFailSoft : ConstraintResultPass );
188
+ updateConstraintWidgetStatus ( result );
189
+ emit constraintStatusChanged ( expressionDesc, description, errStr, result );
169
190
}
170
191
}
171
192
@@ -174,6 +195,11 @@ bool QgsEditorWidgetWrapper::isValidConstraint() const
174
195
return mValidConstraint ;
175
196
}
176
197
198
+ bool QgsEditorWidgetWrapper::isBlockingCommit () const
199
+ {
200
+ return mIsBlockingCommit ;
201
+ }
202
+
177
203
QString QgsEditorWidgetWrapper::constraintFailureReason () const
178
204
{
179
205
return mConstraintFailureReason ;
0 commit comments