Only show failing constraint visual feedback when the attribute table is set to filter for invalid features

This commit is contained in:
Mathieu Pellerin 2023-01-14 11:37:11 +07:00
parent cda82949f2
commit 77df5b8d8a
4 changed files with 35 additions and 1 deletions

View File

@ -247,6 +247,22 @@ Any extra columns need to be implemented by proxy models in front of this model.
%Docstring
Empty extra columns to announce from this model.
Any extra columns need to be implemented by proxy models in front of this model.
%End
bool showValidityState() const;
%Docstring
Returns whether the attribute table will add a visual feedback to cells when an attribute
constraint is not met.
.. versionadded:: 3.30
%End
void setShowValidityState( const bool &show );
%Docstring
Sets whether the attribute table will add a visual feedback to cells when an attribute constraint
is not met.
.. versionadded:: 3.30
%End
public slots:

View File

@ -774,7 +774,7 @@ QVariant QgsAttributeTableModel::data( const QModelIndex &index, int role ) cons
const QgsConditionalStyle rowstyle = QgsConditionalStyle::compressStyles( styles );
QgsConditionalStyle constraintstyle;
if ( QgsVectorLayerUtils::attributeHasConstraints( mLayer, fieldId ) )
if ( mShowValidityState && QgsVectorLayerUtils::attributeHasConstraints( mLayer, fieldId ) )
{
if ( mConstraintStylesMap.contains( mFeat.id() ) &&
mConstraintStylesMap[mFeat.id()].contains( fieldId ) )

View File

@ -256,6 +256,20 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
*/
void setExtraColumns( int extraColumns );
/**
* Returns whether the attribute table will add a visual feedback to cells when an attribute
* constraint is not met.
* \since QGIS 3.30
*/
bool showValidityState() const { return mShowValidityState; }
/**
* Sets whether the attribute table will add a visual feedback to cells when an attribute constraint
* is not met.
* \since QGIS 3.30
*/
void setShowValidityState( const bool &show ) { mShowValidityState = show; }
public slots:
/**
@ -403,6 +417,8 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
//! TRUE if triggered by afterRollback()
bool mIsCleaningUpAfterRollback = false;
bool mShowValidityState = false;
friend class TestQgsAttributeTable;
};

View File

@ -328,6 +328,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
break;
case QgsAttributeTableFilterModel::ShowInvalid:
mMasterModel->setShowValidityState( false );
break;
}
@ -368,6 +369,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
case QgsAttributeTableFilterModel::ShowInvalid:
{
mMasterModel->setShowValidityState( true );
const QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
filterFeatures( QStringLiteral( "is_feature_valid() = false" ), context );
connect( mFilterModel, &QgsAttributeTableFilterModel::featuresFiltered, this, &QgsDualView::filterChanged );