Skip to content

Commit c2f68d6

Browse files
committedNov 13, 2017
background color on constraint fields reset on toggle edit
if editable, the backgroundcolor should be set according the constraint result if not editable, the backgroundcolor should be empty anyway so it has to be reseted when synchronizeEditableState...
1 parent 53d642c commit c2f68d6

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed
 

‎python/gui/editorwidgets/core/qgseditorwidgetwrapper.sip

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,19 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
266266
Will call the value() method to determine the emitted value
267267
%End
268268

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+
269282
protected:
270283

271284
virtual void updateConstraintWidgetStatus( ConstraintResult status );

‎src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,19 @@ void QgsEditorWidgetWrapper::valueChanged()
101101
emit valueChanged( value() );
102102
}
103103

104+
void QgsEditorWidgetWrapper::resetConstraintWidgetStatus( bool editable )
105+
{
106+
if ( editable )
107+
updateConstraintWidgetStatus( mConstraintResult );
108+
else
109+
widget()->setStyleSheet( QString() );
110+
}
111+
104112
void QgsEditorWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult constraintResult )
105113
{
114+
//set the constraint result
115+
mConstraintResult = constraintResult;
116+
106117
switch ( constraintResult )
107118
{
108119
case ConstraintResultPass:

‎src/gui/editorwidgets/core/qgseditorwidgetwrapper.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,19 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
283283
*/
284284
void valueChanged();
285285

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+
286299
protected:
287300

288301
/**
@@ -314,6 +327,9 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
314327
//! Contains the string explanation of why a constraint check failed
315328
QString mConstraintFailureReason;
316329

330+
//! The current constraint result
331+
ConstraintResult mConstraintResult;
332+
317333
int mFieldIdx;
318334
QgsFeature mFeature;
319335
mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly

‎src/gui/qgsattributeform.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -968,6 +968,8 @@ void QgsAttributeForm::synchronizeEnabledState()
968968
{
969969
mFormEditorWidgets.value( eww->fieldIdx() )->setConstraintResultVisibility( isEditable );
970970

971+
eww->resetConstraintWidgetStatus( isEditable );
972+
971973
bool enabled = isEditable && fieldIsEditable( eww->fieldIdx() );
972974
ww->setEnabled( enabled );
973975

0 commit comments

Comments
 (0)
Please sign in to comment.