Skip to content
Permalink
Browse files
Test rendered legend image (with label entry) against reference image
  • Loading branch information
mhugent committed May 13, 2021
1 parent b46fb25 commit f12dfada27355b4ce6d08baec8099a64cbaf2e46
@@ -205,7 +205,8 @@ class TestQgsLegendRenderer : public QObject
void testBasicJson();
void testOpacityJson();
void testBigMarkerJson();
void testLabelLegendJson();

void testLabelLegend();

private:
QgsLayerTree *mRoot = nullptr;
@@ -1546,8 +1547,9 @@ void TestQgsLegendRenderer::testBigMarkerJson()
QVERIFY( _verifyImage( test_name, mReport, 50 ) );
}

void TestQgsLegendRenderer::testLabelLegendJson()
void TestQgsLegendRenderer::testLabelLegend()
{
const QString testName( "test_label_legend" );
QgsPalLayerSettings *labelSettings = new QgsPalLayerSettings();
labelSettings->fieldName = QStringLiteral( "test_attr" );
QgsRuleBasedLabeling::Rule *rootRule = new QgsRuleBasedLabeling::Rule( nullptr ); //root rule
@@ -1569,17 +1571,23 @@ void TestQgsLegendRenderer::testLabelLegendJson()
QgsLayerTreeModel legendModel( mRoot );
QgsLegendSettings settings;

//first test if label legend nodes are present in json
const QJsonObject json = _renderJsonLegend( &legendModel, settings );
const QJsonArray nodes = json["nodes"].toArray();
const QJsonObject point_layer = nodes[1].toObject();
const QJsonArray point_layer_symbols = point_layer["symbols"].toArray();
const QJsonObject point_layer_labeling_symbol = point_layer_symbols[3].toObject();
QString labelTitle = point_layer_labeling_symbol["title"].toString();

QVERIFY( labelTitle == "labelingRule" );

//test rendered legend agains reference image
_setStandardTestFont( settings, QStringLiteral( "Bold" ) );
_renderLegend( testName, &legendModel, settings );
QVERIFY( _verifyImage( testName, mReport ) );

vLayerLegend->setShowLabelLegend( bkLabelLegendEnabled );
mVL3->setLabelsEnabled( bkLabelsEnabled );

QVERIFY( labelTitle == "labelingRule" );
}


Binary file not shown.

0 comments on commit f12dfad

Please sign in to comment.