Skip to content

Commit

Permalink
Only show failing constraint visual feedback when the attribute table…
Browse files Browse the repository at this point in the history
… is set to filter for invalid features
  • Loading branch information
nirvn committed Jan 14, 2023
1 parent cda8294 commit 77df5b8
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 1 deletion.
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion src/gui/attributetable/qgsattributetablemodel.cpp
Expand Up @@ -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 ) )
Expand Down
16 changes: 16 additions & 0 deletions src/gui/attributetable/qgsattributetablemodel.h
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -403,6 +417,8 @@ class GUI_EXPORT QgsAttributeTableModel: public QAbstractTableModel
//! TRUE if triggered by afterRollback()
bool mIsCleaningUpAfterRollback = false;

bool mShowValidityState = false;

friend class TestQgsAttributeTable;

};
Expand Down
2 changes: 2 additions & 0 deletions src/gui/attributetable/qgsdualview.cpp
Expand Up @@ -328,6 +328,7 @@ void QgsDualView::setFilterMode( QgsAttributeTableFilterModel::FilterMode filter
break;

case QgsAttributeTableFilterModel::ShowInvalid:
mMasterModel->setShowValidityState( false );
break;
}

Expand Down Expand Up @@ -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 );
Expand Down

0 comments on commit 77df5b8

Please sign in to comment.