@@ -55,6 +55,7 @@ class TestQgsLayoutTable : public QObject
55
55
void attributeTableFilterFeatures (); // test filtering attribute table rows
56
56
void attributeTableSetAttributes (); // test subset of attributes in table
57
57
void attributeTableVisibleOnly (); // test displaying only visible attributes
58
+ void attributeTableInsideAtlasOnly ();
58
59
void attributeTableRender (); // test rendering attribute table
59
60
void manualColumnWidth (); // test setting manual column widths
60
61
void attributeTableEmpty (); // test empty modes for attribute table
@@ -347,6 +348,67 @@ void TestQgsLayoutTable::attributeTableVisibleOnly()
347
348
compareTable ( table, expectedRows );
348
349
}
349
350
351
+ void TestQgsLayoutTable::attributeTableInsideAtlasOnly ()
352
+ {
353
+ // test displaying only visible attributes inside the atlas feature
354
+ QgsLayout l ( QgsProject::instance () );
355
+ l.initializeDefaults ();
356
+ QgsLayoutItemAttributeTable *table = new QgsLayoutItemAttributeTable ( &l );
357
+ table->setVectorLayer ( mVectorLayer );
358
+
359
+ QgsLayoutItemMap *map = new QgsLayoutItemMap ( &l );
360
+ map->attemptSetSceneRect ( QRectF ( 20 , 20 , 200 , 100 ) );
361
+ map->setFrameEnabled ( true );
362
+ map->setExtent ( QgsRectangle ( -95.537 , 32.736 , -84.389 , 42.2920 ) );
363
+ l.addLayoutItem ( map );
364
+
365
+ table->setMap ( map );
366
+ table->setFilterToAtlasFeature ( true );
367
+
368
+ // no atlas feature
369
+ QVector<QStringList> expectedRows;
370
+ compareTable ( table, expectedRows );
371
+
372
+ // setup atlas
373
+ std::unique_ptr< QgsVectorLayer > atlasLayer = qgis::make_unique< QgsVectorLayer >( QStringLiteral ( " Polygon?crs=EPSG:3857" ), QStringLiteral ( " atlas" ), QStringLiteral ( " memory" ) );
374
+ QVERIFY ( atlasLayer->isValid () );
375
+ QgsGeometry atlasGeom ( QgsGeometry::fromWkt ( QStringLiteral ( " Polygon ((-8863916.31126776337623596 4621257.48816855065524578, -9664269.45078738406300545 5097056.938785120844841, -10049249.44194872118532658 3765399.75924854446202517, -8985488.94005555473268032 3458599.17133777122944593, -8863916.31126776337623596 4621257.48816855065524578))" ) ) );
376
+ QgsFeature f;
377
+ f.setGeometry ( atlasGeom );
378
+ atlasLayer->dataProvider ()->addFeature ( f );
379
+ l.reportContext ().setLayer ( atlasLayer.get () );
380
+
381
+ QgsFeatureIterator it = atlasLayer->getFeatures ();
382
+ it.nextFeature ( f );
383
+ l.reportContext ().setFeature ( f );
384
+
385
+ QStringList row;
386
+ row << QStringLiteral ( " Biplane" ) << QStringLiteral ( " 0" ) << QStringLiteral ( " 1" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 6" );
387
+ expectedRows.append ( row );
388
+ row.clear ();
389
+ row << QStringLiteral ( " Jet" ) << QStringLiteral ( " 90" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 1" ) << QStringLiteral ( " 0" ) << QStringLiteral ( " 1" );
390
+ expectedRows.append ( row );
391
+ row.clear ();
392
+ row << QStringLiteral ( " Biplane" ) << QStringLiteral ( " 340" ) << QStringLiteral ( " 1" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 6" );
393
+ expectedRows.append ( row );
394
+
395
+ // retrieve rows and check
396
+ compareTable ( table, expectedRows );
397
+
398
+ // combination of atlas and map extent visibility
399
+ table->setDisplayOnlyVisibleFeatures ( true );
400
+ expectedRows.clear ();
401
+ row.clear ();
402
+ row << QStringLiteral ( " Jet" ) << QStringLiteral ( " 90" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 1" ) << QStringLiteral ( " 0" ) << QStringLiteral ( " 1" );
403
+ expectedRows.append ( row );
404
+ row.clear ();
405
+ row << QStringLiteral ( " Biplane" ) << QStringLiteral ( " 340" ) << QStringLiteral ( " 1" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 3" ) << QStringLiteral ( " 6" );
406
+ expectedRows.append ( row );
407
+
408
+ // retrieve rows and check
409
+ compareTable ( table, expectedRows );
410
+ }
411
+
350
412
void TestQgsLayoutTable::attributeTableRender ()
351
413
{
352
414
QgsLayout l ( QgsProject::instance () );
0 commit comments