Skip to content
Permalink
Browse files

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 12, 2017
1 parent 53d642c commit c2f68d6f7b3be724546b9df40937443da47255f0
@@ -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 );
@@ -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:
@@ -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:

/**
@@ -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
@@ -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 );

0 comments on commit c2f68d6

Please sign in to comment.
You can’t perform that action at this time.