Skip to content
Permalink
Browse files

Merge pull request #5614 from signedav/constraintindicators

Constraint result not displayed in non editable mode
  • Loading branch information
m-kuhn committed Nov 20, 2017
2 parents eb2ef6a + 9950031 commit 30ed315392c8b03e01d01b6a18739769d810be31
@@ -172,6 +172,32 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
Add a hint text on the widget
\param hintText The hint text to display
.. versionadded:: 3.0
%End

ConstraintResult constraintResult() const;
%Docstring
Getter of constraintResult
It's the current result of the constraint on the widget influencing it's visualization.
.. versionadded:: 3.0
:rtype: ConstraintResult
%End

bool constraintResultVisible() const;
%Docstring
Getter of constraintResultVisible
Defines if the constraint result should be visualized on the widget (with color).
This will be disabled when the form is not editable.
.. versionadded:: 3.0
:rtype: bool
%End

void setConstraintResultVisible( bool constraintResultVisible );
%Docstring
Setter of constraintResultVisible
Defines if the constraint result should be visualized on the widget (with color).
This will be disabled when the form is not editable.
\param constraintResultVisible if constraintResult should be displayed (mostly editable status)
.. versionadded:: 3.0
%End

signals:
@@ -193,6 +219,11 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
\param status
%End

void constraintResultVisibleChanged( bool visible );
%Docstring
Emit this signal when the constraint result visibility changed.
%End

public slots:

virtual void setFeature( const QgsFeature &feature );
@@ -268,7 +299,7 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper

protected:

virtual void updateConstraintWidgetStatus( ConstraintResult status );
virtual void updateConstraintWidgetStatus();
%Docstring
This should update the widget with a visual cue if a constraint status
changed.
@@ -279,8 +310,6 @@ class QgsEditorWidgetWrapper : QgsWidgetWrapper
This can be overwritten in subclasses to allow individual widgets to
change the visual cue.

\param status The current constraint status.

.. versionadded:: 2.16
%End

@@ -51,7 +51,7 @@ class QgsRelationReferenceWidgetWrapper : QgsEditorWidgetWrapper

protected:

virtual void updateConstraintWidgetStatus( ConstraintResult status );
virtual void updateConstraintWidgetStatus();


};
@@ -101,6 +101,11 @@ class QgsAttributeFormEditorWidget : QWidget
Set the constraint status for this widget.
%End

void setConstraintResultVisible( bool editable );
%Docstring
Set the constraint result lable visible or invisible according to the layer editable status
%End

public slots:

void setIsMixed( bool mixed );
@@ -101,24 +101,53 @@ void QgsEditorWidgetWrapper::valueChanged()
emit valueChanged( value() );
}

void QgsEditorWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult constraintResult )
void QgsEditorWidgetWrapper::updateConstraintWidgetStatus()
{
switch ( constraintResult )
if ( !mConstraintResultVisible )
{
case ConstraintResultPass:
widget()->setStyleSheet( QString() );
break;
widget()->setStyleSheet( QString() );
}
else
{
switch ( mConstraintResult )
{
case ConstraintResultPass:
widget()->setStyleSheet( QString() );
break;

case ConstraintResultFailHard:
widget()->setStyleSheet( QStringLiteral( "background-color: #FFE0B2;" ) );
break;
case ConstraintResultFailHard:
widget()->setStyleSheet( QStringLiteral( "background-color: #FFE0B2;" ) );
break;

case ConstraintResultFailSoft:
widget()->setStyleSheet( QStringLiteral( "background-color: #FFECB3;" ) );
break;
case ConstraintResultFailSoft:
widget()->setStyleSheet( QStringLiteral( "background-color: #FFECB3;" ) );
break;
}
}
}

QgsEditorWidgetWrapper::ConstraintResult QgsEditorWidgetWrapper::constraintResult() const
{
return mConstraintResult;
}

bool QgsEditorWidgetWrapper::constraintResultVisible() const
{
return mConstraintResultVisible;
}

void QgsEditorWidgetWrapper::setConstraintResultVisible( bool constraintResultVisible )
{
if ( mConstraintResultVisible == constraintResultVisible )
return;

mConstraintResultVisible = constraintResultVisible;

updateConstraintWidgetStatus();

emit constraintResultVisibleChanged( mConstraintResultVisible );
}

void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft, QgsFieldConstraints::ConstraintOrigin constraintOrigin )
{
updateConstraint( layer(), mFieldIdx, ft, constraintOrigin );
@@ -210,7 +239,9 @@ void QgsEditorWidgetWrapper::updateConstraint( const QgsVectorLayer *layer, int

ConstraintResult result = !hardConstraintsOk ? ConstraintResultFailHard
: ( !softConstraintsOk ? ConstraintResultFailSoft : ConstraintResultPass );
updateConstraintWidgetStatus( result );
//set the constraint result
mConstraintResult = result;
updateConstraintWidgetStatus();
emit constraintStatusChanged( expressionDesc, description, errStr, result );
}
}
@@ -42,6 +42,10 @@ class QgsField;
class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
{
Q_OBJECT

Q_PROPERTY( bool constraintResultVisible READ constraintResultVisible WRITE setConstraintResultVisible NOTIFY constraintResultVisibleChanged )
Q_PROPERTY( ConstraintResult constraintResult READ constraintResult NOTIFY constraintStatusChanged )

public:

/**
@@ -185,6 +189,30 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
virtual void setHint( const QString &hintText );

/**
* Getter of constraintResult
* It's the current result of the constraint on the widget influencing it's visualization.
* \since QGIS 3.0
*/
ConstraintResult constraintResult() const;

/**
* Getter of constraintResultVisible
* Defines if the constraint result should be visualized on the widget (with color).
* This will be disabled when the form is not editable.
* \since QGIS 3.0
*/
bool constraintResultVisible() const;

/**
* Setter of constraintResultVisible
* Defines if the constraint result should be visualized on the widget (with color).
* This will be disabled when the form is not editable.
* \param constraintResultVisible if constraintResult should be displayed (mostly editable status)
* \since QGIS 3.0
*/
void setConstraintResultVisible( bool constraintResultVisible );

signals:

/**
@@ -204,6 +232,11 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
*/
void constraintStatusChanged( const QString &constraint, const QString &desc, const QString &err, ConstraintResult status );

/**
* Emit this signal when the constraint result visibility changed.
*/
void constraintResultVisibleChanged( bool visible );

public slots:

/**
@@ -295,11 +328,9 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
* This can be overwritten in subclasses to allow individual widgets to
* change the visual cue.
*
* \param status The current constraint status.
*
* \since QGIS 2.16
*/
virtual void updateConstraintWidgetStatus( ConstraintResult status );
virtual void updateConstraintWidgetStatus();

private:

@@ -314,6 +345,12 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
//! Contains the string explanation of why a constraint check failed
QString mConstraintFailureReason;

//! The current constraint result
ConstraintResult mConstraintResult;

//! The current constraint result
bool mConstraintResultVisible;

int mFieldIdx;
QgsFeature mFeature;
mutable QVariant mDefaultValue; // Cache default value, we don't want to retrieve different serial numbers if called repeatedly
@@ -80,7 +80,7 @@ void QgsColorWidgetWrapper::setValue( const QVariant &value )
mColorButton->setColor( !value.isNull() ? QColor( value.toString() ) : QColor() );
}

void QgsColorWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult /*constraintValid*/ )
void QgsColorWidgetWrapper::updateConstraintWidgetStatus()
{
// nothing
}
@@ -49,7 +49,7 @@ class GUI_EXPORT QgsColorWidgetWrapper : public QgsEditorWidgetWrapper
void setValue( const QVariant &value ) override;

private:
void updateConstraintWidgetStatus( ConstraintResult status ) override;
void updateConstraintWidgetStatus() override;

QgsColorButton *mColorButton = nullptr;
};
@@ -233,23 +233,30 @@ void QgsExternalResourceWidgetWrapper::setEnabled( bool enabled )
mQgsWidget->setReadOnly( !enabled );
}

void QgsExternalResourceWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult status )
void QgsExternalResourceWidgetWrapper::updateConstraintWidgetStatus()
{
if ( mLineEdit )
{
switch ( status )
if ( !constraintResultVisible() )
{
case ConstraintResultPass:
mLineEdit->setStyleSheet( QString() );
break;
widget()->setStyleSheet( QString() );
}
else
{
switch ( constraintResult() )
{
case ConstraintResultPass:
mLineEdit->setStyleSheet( QString() );
break;

case ConstraintResultFailHard:
mLineEdit->setStyleSheet( QStringLiteral( "QgsFilterLineEdit { background-color: #dd7777; }" ) );
break;
case ConstraintResultFailHard:
mLineEdit->setStyleSheet( QStringLiteral( "QgsFilterLineEdit { background-color: #dd7777; }" ) );
break;

case ConstraintResultFailSoft:
mLineEdit->setStyleSheet( QStringLiteral( "QgsFilterLineEdit { background-color: #ffd85d; }" ) );
break;
case ConstraintResultFailSoft:
mLineEdit->setStyleSheet( QStringLiteral( "QgsFilterLineEdit { background-color: #ffd85d; }" ) );
break;
}
}
}
}
@@ -59,7 +59,7 @@ class GUI_EXPORT QgsExternalResourceWidgetWrapper : public QgsEditorWidgetWrappe
void setEnabled( bool enabled ) override;

private:
void updateConstraintWidgetStatus( ConstraintResult status ) override;
void updateConstraintWidgetStatus() override;

QLineEdit *mLineEdit = nullptr;
QLabel *mLabel = nullptr;
@@ -72,7 +72,7 @@ void QgsKeyValueWidgetWrapper::setValue( const QVariant &value )
mWidget->setMap( value.toMap() );
}

void QgsKeyValueWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult /*constraintValid*/ )
void QgsKeyValueWidgetWrapper::updateConstraintWidgetStatus()
{
// Nothing
}
@@ -56,7 +56,7 @@ class GUI_EXPORT QgsKeyValueWidgetWrapper : public QgsEditorWidgetWrapper
void onValueChanged();

private:
void updateConstraintWidgetStatus( ConstraintResult status ) override;
void updateConstraintWidgetStatus() override;

QgsKeyValueWidget *mWidget = nullptr;
};
@@ -87,7 +87,7 @@ void QgsListWidgetWrapper::onValueChanged()
emit valueChanged( value() );
}

void QgsListWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult /*constraintValid*/ )
void QgsListWidgetWrapper::updateConstraintWidgetStatus()
{
// Nothing
}
@@ -56,7 +56,7 @@ class GUI_EXPORT QgsListWidgetWrapper : public QgsEditorWidgetWrapper
void onValueChanged();

private:
void updateConstraintWidgetStatus( ConstraintResult status ) override;
void updateConstraintWidgetStatus() override;

QgsListWidget *mWidget = nullptr;
};
@@ -145,23 +145,30 @@ void QgsRelationReferenceWidgetWrapper::foreignKeyChanged( QVariant value )
emit valueChanged( value );
}

void QgsRelationReferenceWidgetWrapper::updateConstraintWidgetStatus( ConstraintResult status )
void QgsRelationReferenceWidgetWrapper::updateConstraintWidgetStatus()
{
if ( mWidget )
{
switch ( status )
if ( !constraintResultVisible() )
{
case ConstraintResultPass:
mWidget->setStyleSheet( QString() );
break;

case ConstraintResultFailHard:
mWidget->setStyleSheet( QStringLiteral( ".QComboBox { background-color: #dd7777; }" ) );
break;

case ConstraintResultFailSoft:
mWidget->setStyleSheet( QStringLiteral( ".QComboBox { background-color: #ffd85d; }" ) );
break;
widget()->setStyleSheet( QString() );
}
else
{
switch ( constraintResult() )
{
case ConstraintResultPass:
mWidget->setStyleSheet( QString() );
break;

case ConstraintResultFailHard:
mWidget->setStyleSheet( QStringLiteral( ".QComboBox { background-color: #dd7777; }" ) );
break;

case ConstraintResultFailSoft:
mWidget->setStyleSheet( QStringLiteral( ".QComboBox { background-color: #ffd85d; }" ) );
break;
}
}
}
}
@@ -66,7 +66,7 @@ class GUI_EXPORT QgsRelationReferenceWidgetWrapper : public QgsEditorWidgetWrapp

protected:

void updateConstraintWidgetStatus( ConstraintResult status ) override;
void updateConstraintWidgetStatus() override;

private:
QgsRelationReferenceWidget *mWidget = nullptr;

0 comments on commit 30ed315

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