Skip to content
Permalink
Browse files

member variable for constraint result visability

...as we had it for for constraint result (status).
now the setter are called when setting the editable mode changes.
and the getter to have the current visibility status.
  • Loading branch information
signedav committed Nov 16, 2017
1 parent c2f68d6 commit 995003153ad2a0504e40e44839ead1ccb14b0427
@@ -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 );
@@ -266,22 +297,9 @@ 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 );
virtual void updateConstraintWidgetStatus();
%Docstring
This should update the widget with a visual cue if a constraint status
changed.
@@ -292,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,7 +101,7 @@ class QgsAttributeFormEditorWidget : QWidget
Set the constraint status for this widget.
%End

void setConstraintResultVisibility( bool editable );
void setConstraintResultVisible( bool editable );
%Docstring
Set the constraint result lable visible or invisible according to the layer editable status
%End
@@ -101,33 +101,51 @@ void QgsEditorWidgetWrapper::valueChanged()
emit valueChanged( value() );
}

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

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

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

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

switch ( constraintResult )
{
case ConstraintResultPass:
widget()->setStyleSheet( QString() );
break;
bool QgsEditorWidgetWrapper::constraintResultVisible() const
{
return mConstraintResultVisible;
}

case ConstraintResultFailHard:
widget()->setStyleSheet( QStringLiteral( "background-color: #FFE0B2;" ) );
break;
void QgsEditorWidgetWrapper::setConstraintResultVisible( bool constraintResultVisible )
{
if ( mConstraintResultVisible == constraintResultVisible )
return;

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

updateConstraintWidgetStatus();

emit constraintResultVisibleChanged( mConstraintResultVisible );
}

void QgsEditorWidgetWrapper::updateConstraint( const QgsFeature &ft, QgsFieldConstraints::ConstraintOrigin constraintOrigin )
@@ -221,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:

/**
@@ -283,19 +316,6 @@ 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:

/**
@@ -308,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:

@@ -330,6 +348,9 @@ class GUI_EXPORT QgsEditorWidgetWrapper : public QgsWidgetWrapper
//! 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;
};

0 comments on commit 9950031

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