Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
signedav committed Nov 13, 2017
1 parent 53d642c commit c2f68d6
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 0 deletions.
13 changes: 13 additions & 0 deletions python/gui/editorwidgets/core/qgseditorwidgetwrapper.sip
Expand Up @@ -266,6 +266,19 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
Will call the value() method to determine the emitted value
%End

virtual void resetConstraintWidgetStatus( bool editable );
%Docstring
It cleans background color (and any other style) in case the feature is not
editable. In case it is, it resets it to the stored constraint status.

This could be overwritten in subclasses in case individual widgets need other
behavior.

\param editable if editable or not

.. versionadded:: 3.0
%End

protected:

virtual void updateConstraintWidgetStatus( ConstraintResult status );
Expand Down
11 changes: 11 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.cpp
Expand Up @@ -101,8 +101,19 @@ void QgsEditorWidgetWrapper::valueChanged()
emit valueChanged( value() );
}

void QgsEditorWidgetWrapper::resetConstraintWidgetStatus( bool editable )
{
if ( editable )
updateConstraintWidgetStatus( mConstraintResult );
else
widget()->setStyleSheet( QString() );
}

void QgsEditorWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult constraintResult )
{
//set the constraint result
mConstraintResult = constraintResult;

switch ( constraintResult )
{
case ConstraintResultPass:
Expand Down
16 changes: 16 additions & 0 deletions src/gui/editorwidgets/core/qgseditorwidgetwrapper.h
Expand Up @@ -283,6 +283,19 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
void valueChanged();

/**
* It cleans background color (and any other style) in case the feature is not
* editable. In case it is, it resets it to the stored constraint status.
*
* This could be overwritten in subclasses in case individual widgets need other
* behavior.
*
* \param editable if editable or not
*
* \since QGIS 3.0
*/
virtual void resetConstraintWidgetStatus( bool editable );

protected:

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

//! The current constraint result
ConstraintResult mConstraintResult;

int mFieldIdx;
QgsFeature mFeature;
mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsattributeform.cpp
Expand Up @@ -968,6 +968,8 @@ void QgsAttributeForm::synchronizeEnabledState()
{
mFormEditorWidgets.value( eww->fieldIdx() )->setConstraintResultVisibility( isEditable );

eww->resetConstraintWidgetStatus( isEditable );

bool enabled = isEditable && fieldIsEditable( eww->fieldIdx() );
ww->setEnabled( enabled );

Expand Down

0 comments on commit c2f68d6

Please sign in to comment.