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