@@ -118,6 +118,8 @@ class TestQgsLegendRenderer : public QObject
118
118
void testThreeColumns ();
119
119
void testFilterByMap ();
120
120
void testFilterByMapSameSymbol ();
121
+ void testColumns_data ();
122
+ void testColumns ();
121
123
void testRasterBorder ();
122
124
void testFilterByPolygon ();
123
125
void testFilterByExpression ();
@@ -131,6 +133,7 @@ class TestQgsLegendRenderer : public QObject
131
133
QgsVectorLayer* mVL3 ; // point
132
134
QgsRasterLayer* mRL ;
133
135
QString mReport ;
136
+ bool _testLegendColumns ( int itemCount, int columnCount, const QString& testName );
134
137
};
135
138
136
139
@@ -459,6 +462,65 @@ void TestQgsLegendRenderer::testFilterByMapSameSymbol()
459
462
QgsMapLayerRegistry::instance ()->removeMapLayer ( vl4 );
460
463
}
461
464
465
+ bool TestQgsLegendRenderer::_testLegendColumns ( int itemCount, int columnCount, const QString& testName )
466
+ {
467
+ QgsFillSymbol* sym = new QgsFillSymbol ();
468
+ sym->setColor ( Qt::cyan );
469
+
470
+ QgsLayerTreeGroup* root = new QgsLayerTreeGroup ();
471
+
472
+ QList< QgsVectorLayer* > layers;
473
+ for ( int i = 1 ; i <= itemCount; ++i )
474
+ {
475
+ QgsVectorLayer* vl = new QgsVectorLayer ( " Polygon" , QString ( " Layer %1" ).arg ( i ), " memory" );
476
+ QgsMapLayerRegistry::instance ()->addMapLayer ( vl );
477
+ vl->setRenderer ( new QgsSingleSymbolRenderer ( sym->clone () ) );
478
+ root->addLayer ( vl );
479
+ layers << vl;
480
+ }
481
+ delete sym;
482
+
483
+ QgsLayerTreeModel legendModel ( root );
484
+ QgsLegendSettings settings;
485
+ settings.setColumnCount ( columnCount );
486
+ _setStandardTestFont ( settings, " Bold" );
487
+ _renderLegend ( testName, &legendModel, settings );
488
+ bool result = _verifyImage ( testName, mReport );
489
+
490
+ Q_FOREACH ( QgsVectorLayer* l, layers )
491
+ {
492
+ QgsMapLayerRegistry::instance ()->removeMapLayer ( l );
493
+ }
494
+ return result;
495
+ }
496
+
497
+ void TestQgsLegendRenderer::testColumns_data ()
498
+ {
499
+ QTest::addColumn<QString>( " testName" );
500
+ QTest::addColumn<int >( " items" );
501
+ QTest::addColumn<int >( " columns" );
502
+
503
+ QTest::newRow ( " 2 items, 2 columns" ) << " legend_2_by_2" << 2 << 2 ;
504
+ QTest::newRow ( " 3 items, 2 columns" ) << " legend_3_by_2" << 3 << 2 ;
505
+ QTest::newRow ( " 4 items, 2 columns" ) << " legend_4_by_2" << 4 << 2 ;
506
+ QTest::newRow ( " 5 items, 2 columns" ) << " legend_5_by_2" << 5 << 2 ;
507
+ QTest::newRow ( " 3 items, 3 columns" ) << " legend_3_by_3" << 3 << 3 ;
508
+ QTest::newRow ( " 4 items, 3 columns" ) << " legend_4_by_3" << 4 << 3 ;
509
+ QTest::newRow ( " 5 items, 3 columns" ) << " legend_5_by_3" << 5 << 3 ;
510
+ QTest::newRow ( " 6 items, 3 columns" ) << " legend_6_by_3" << 6 << 3 ;
511
+ QTest::newRow ( " 7 items, 3 columns" ) << " legend_7_by_3" << 7 << 3 ;
512
+ }
513
+
514
+ void TestQgsLegendRenderer::testColumns ()
515
+ {
516
+ // test rendering legend with different combinations of columns and items
517
+
518
+ QFETCH ( QString, testName );
519
+ QFETCH ( int , items );
520
+ QFETCH ( int , columns );
521
+ QVERIFY ( _testLegendColumns ( items, columns, testName ) );
522
+ }
523
+
462
524
void TestQgsLegendRenderer::testRasterBorder ()
463
525
{
464
526
QString testName = " legend_raster_border" ;
0 commit comments