Skip to content
Permalink
Browse files

Don't report legend filter by expression as enabled if the expression…

… is empty
  • Loading branch information
github-actions authored and nyalldawson committed Jul 23, 2020
1 parent b7edc01 commit 82f4d26bbe89a13e684e1f3bcd4f0c0faea89ccc
Showing with 6 additions and 5 deletions.
  1. +4 −3 src/core/layertree/qgslayertreeutils.cpp
  2. +2 −2 src/gui/qgslegendfilterbutton.cpp
@@ -429,14 +429,15 @@ void QgsLayerTreeUtils::updateEmbeddedGroupsProjectPath( QgsLayerTreeGroup *grou
void QgsLayerTreeUtils::setLegendFilterByExpression( QgsLayerTreeLayer &layer, const QString &expr, bool enabled )
{
layer.setCustomProperty( QStringLiteral( "legend/expressionFilter" ), expr );
layer.setCustomProperty( QStringLiteral( "legend/expressionFilterEnabled" ), enabled );
layer.setCustomProperty( QStringLiteral( "legend/expressionFilterEnabled" ), enabled && !expr.isEmpty() );
}

QString QgsLayerTreeUtils::legendFilterByExpression( const QgsLayerTreeLayer &layer, bool *enabled )
{
const QString expression = layer.customProperty( QStringLiteral( "legend/expressionFilter" ), QString() ).toString();
if ( enabled )
*enabled = layer.customProperty( QStringLiteral( "legend/expressionFilterEnabled" ), "" ).toBool();
return layer.customProperty( QStringLiteral( "legend/expressionFilter" ), "" ).toString();
*enabled = !expression.isEmpty() && layer.customProperty( QStringLiteral( "legend/expressionFilterEnabled" ), QString() ).toBool();
return expression;
}

bool QgsLayerTreeUtils::hasLegendFilterExpression( const QgsLayerTreeGroup &group )
@@ -92,12 +92,12 @@ void QgsLegendFilterButton::updateMenu()
if ( !mExpression.isEmpty() )
{
mClearExpressionAction->setEnabled( true );
mSetExpressionAction->setText( QString( tr( "Edit filter expression (current: %1)" ) ).arg( mExpression ) );
mSetExpressionAction->setText( tr( "Edit Filter Expression (current: %1)" ).arg( mExpression ) );
}
else
{
mClearExpressionAction->setEnabled( false );
mSetExpressionAction->setText( tr( "Edit filter expression" ) );
mSetExpressionAction->setText( tr( "Edit Filter Expression" ) );
}
}

0 comments on commit 82f4d26

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