From 60f252c2f22d1ab89361d1381b1aacbe544fb756 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Fri, 25 Jan 2019 09:42:16 +1000 Subject: [PATCH] [layouts] Fix attribute table filtering not utilising expression context Fixes #21078 --- .../layout/qgslayoutitemattributetable.cpp | 1 + tests/src/core/testqgslayouttable.cpp | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/core/layout/qgslayoutitemattributetable.cpp b/src/core/layout/qgslayoutitemattributetable.cpp index b46a0caec8f..031decf3ee4 100644 --- a/src/core/layout/qgslayoutitemattributetable.cpp +++ b/src/core/layout/qgslayoutitemattributetable.cpp @@ -411,6 +411,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont { activeFilter = true; req.setFilterExpression( mFeatureFilter ); + req.setExpressionContext( context ); } } diff --git a/tests/src/core/testqgslayouttable.cpp b/tests/src/core/testqgslayouttable.cpp index 961aa2f8f59..cf6da2633da 100644 --- a/tests/src/core/testqgslayouttable.cpp +++ b/tests/src/core/testqgslayouttable.cpp @@ -240,6 +240,30 @@ void TestQgsLayoutTable::attributeTableFilterFeatures() //retrieve rows and check compareTable( table, expectedRows ); + + table->setFeatureFilter( QStringLiteral( "\"Class\"=@airplane_class" ) ); + table->setFilterFeatures( true ); + expectedRows.clear(); + compareTable( table, expectedRows ); + + QgsExpressionContextUtils::setLayoutVariable( &l, QStringLiteral( "airplane_class" ), QStringLiteral( "Biplane" ) ); + + row.clear(); + row << QStringLiteral( "Biplane" ) << QStringLiteral( "0" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "3" ) << QStringLiteral( "6" ); + expectedRows.append( row ); + row.clear(); + row << QStringLiteral( "Biplane" ) << QStringLiteral( "340" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "3" ) << QStringLiteral( "6" ); + expectedRows.append( row ); + row.clear(); + row << QStringLiteral( "Biplane" ) << QStringLiteral( "300" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "2" ) << QStringLiteral( "5" ); + expectedRows.append( row ); + row.clear(); + row << QStringLiteral( "Biplane" ) << QStringLiteral( "270" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "4" ) << QStringLiteral( "7" ); + expectedRows.append( row ); + row.clear(); + row << QStringLiteral( "Biplane" ) << QStringLiteral( "240" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "2" ) << QStringLiteral( "5" ); + expectedRows.append( row ); + compareTable( table, expectedRows ); } void TestQgsLayoutTable::attributeTableSetAttributes()