File tree Expand file tree Collapse file tree 4 files changed +42
-0
lines changed
python/gui/editorwidgets/core Expand file tree Collapse file tree 4 files changed +42
-0
lines changed Original file line number Diff line number Diff line change @@ -266,6 +266,19 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
266
266
Will call the value() method to determine the emitted value
267
267
%End
268
268
269
+ virtual void resetConstraintWidgetStatus( bool editable );
270
+ %Docstring
271
+ It cleans background color (and any other style) in case the feature is not
272
+ editable. In case it is, it resets it to the stored constraint status.
273
+
274
+ This could be overwritten in subclasses in case individual widgets need other
275
+ behavior.
276
+
277
+ \param editable if editable or not
278
+
279
+ .. versionadded:: 3.0
280
+ %End
281
+
269
282
protected:
270
283
271
284
virtual void updateConstraintWidgetStatus( ConstraintResult status );
Original file line number Diff line number Diff line change @@ -101,8 +101,19 @@ void QgsEditorWidgetWrapper::valueChanged()
101
101
emit valueChanged ( value () );
102
102
}
103
103
104
+ void QgsEditorWidgetWrapper::resetConstraintWidgetStatus ( bool editable )
105
+ {
106
+ if ( editable )
107
+ updateConstraintWidgetStatus ( mConstraintResult );
108
+ else
109
+ widget ()->setStyleSheet ( QString () );
110
+ }
111
+
104
112
void QgsEditorWidgetWrapper::updateConstraintWidgetStatus ( ConstraintResult constraintResult )
105
113
{
114
+ // set the constraint result
115
+ mConstraintResult = constraintResult;
116
+
106
117
switch ( constraintResult )
107
118
{
108
119
case ConstraintResultPass:
Original file line number Diff line number Diff line change @@ -283,6 +283,19 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
283
283
*/
284
284
void valueChanged ();
285
285
286
+ /* *
287
+ * It cleans background color (and any other style) in case the feature is not
288
+ * editable. In case it is, it resets it to the stored constraint status.
289
+ *
290
+ * This could be overwritten in subclasses in case individual widgets need other
291
+ * behavior.
292
+ *
293
+ * \param editable if editable or not
294
+ *
295
+ * \since QGIS 3.0
296
+ */
297
+ virtual void resetConstraintWidgetStatus ( bool editable );
298
+
286
299
protected:
287
300
288
301
/* *
@@ -314,6 +327,9 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
314
327
// ! Contains the string explanation of why a constraint check failed
315
328
QString mConstraintFailureReason ;
316
329
330
+ // ! The current constraint result
331
+ ConstraintResult mConstraintResult ;
332
+
317
333
int mFieldIdx ;
318
334
QgsFeature mFeature ;
319
335
mutable QVariant mDefaultValue ; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
Original file line number Diff line number Diff line change @@ -968,6 +968,8 @@ void QgsAttributeForm::synchronizeEnabledState()
968
968
{
969
969
mFormEditorWidgets .value ( eww->fieldIdx () )->setConstraintResultVisibility ( isEditable );
970
970
971
+ eww->resetConstraintWidgetStatus ( isEditable );
972
+
971
973
bool enabled = isEditable && fieldIsEditable ( eww->fieldIdx () );
972
974
ww->setEnabled ( enabled );
973
975
You can’t perform that action at this time.
0 commit comments