Skip to content

Commit de0aede

Browse files
committedFeb 28, 2019
[layouts] Fix attribute table filtering not utilising expression context
Fixes #21078
1 parent 8ba90fc commit de0aede

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed
 

‎src/core/layout/qgslayoutitemattributetable.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ bool QgsLayoutItemAttributeTable::getTableContents( QgsLayoutTableContents &cont
411411
{
412412
activeFilter = true;
413413
req.setFilterExpression( mFeatureFilter );
414+
req.setExpressionContext( context );
414415
}
415416
}
416417

‎tests/src/core/testqgslayouttable.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,30 @@ void TestQgsLayoutTable::attributeTableFilterFeatures()
241241

242242
//retrieve rows and check
243243
compareTable( table, expectedRows );
244+
245+
table->setFeatureFilter( QStringLiteral( "\"Class\"=@airplane_class" ) );
246+
table->setFilterFeatures( true );
247+
expectedRows.clear();
248+
compareTable( table, expectedRows );
249+
250+
QgsExpressionContextUtils::setLayoutVariable( &l, QStringLiteral( "airplane_class" ), QStringLiteral( "Biplane" ) );
251+
252+
row.clear();
253+
row << QStringLiteral( "Biplane" ) << QStringLiteral( "0" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "3" ) << QStringLiteral( "6" );
254+
expectedRows.append( row );
255+
row.clear();
256+
row << QStringLiteral( "Biplane" ) << QStringLiteral( "340" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "3" ) << QStringLiteral( "6" );
257+
expectedRows.append( row );
258+
row.clear();
259+
row << QStringLiteral( "Biplane" ) << QStringLiteral( "300" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "2" ) << QStringLiteral( "5" );
260+
expectedRows.append( row );
261+
row.clear();
262+
row << QStringLiteral( "Biplane" ) << QStringLiteral( "270" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "4" ) << QStringLiteral( "7" );
263+
expectedRows.append( row );
264+
row.clear();
265+
row << QStringLiteral( "Biplane" ) << QStringLiteral( "240" ) << QStringLiteral( "1" ) << QStringLiteral( "3" ) << QStringLiteral( "2" ) << QStringLiteral( "5" );
266+
expectedRows.append( row );
267+
compareTable( table, expectedRows );
244268
}
245269

246270
void TestQgsLayoutTable::attributeTableSetAttributes()

0 commit comments

Comments
 (0)
Please sign in to comment.