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