@@ -141,6 +141,7 @@ class TestQgsLegendRenderer : public QObject
141
141
void testTextOnSymbol ();
142
142
143
143
void testBasicJson ();
144
+ void testOpacityJson ();
144
145
145
146
private:
146
147
QgsLayerTree *mRoot = nullptr ;
@@ -927,6 +928,44 @@ void TestQgsLegendRenderer::testBasicJson()
927
928
QVERIFY ( _verifyImage ( test_name, mReport , 50 ) );
928
929
}
929
930
931
+ void TestQgsLegendRenderer::testOpacityJson ()
932
+ {
933
+ const int opacity = mVL3 ->opacity ();
934
+ mVL3 ->setOpacity ( 0.5 );
935
+ QgsLayerTreeModel legendModel ( mRoot );
936
+
937
+ QgsLegendSettings settings;
938
+ settings.setTitle ( QStringLiteral ( " Legend" ) );
939
+ _setStandardTestFont ( settings );
940
+ const QJsonObject json = _renderJsonLegend ( &legendModel, settings );
941
+
942
+ QCOMPARE ( json[ " title" ], " Legend" );
943
+
944
+ const QJsonArray root = json[" nodes" ].toArray ();
945
+
946
+ const QJsonObject point_layer = root[1 ].toObject ();
947
+ const QJsonArray point_layer_symbols = point_layer[" symbols" ].toArray ();
948
+
949
+ const QJsonObject point_layer_symbol_red = point_layer_symbols[0 ].toObject ();
950
+ const QImage point_layer_icon_red = _base64ToImage ( point_layer_symbol_red[" icon" ].toString () );
951
+ QString test_name = " point_layer_icon_red_opacity" ;
952
+ point_layer_icon_red.save ( _fileNameForTest ( test_name ) );
953
+ QVERIFY ( _verifyImage ( test_name, mReport , 50 ) );
954
+
955
+ const QJsonObject point_layer_symbol_green = point_layer_symbols[1 ].toObject ();
956
+ const QImage point_layer_icon_green = _base64ToImage ( point_layer_symbol_green[" icon" ].toString () );
957
+ test_name = " point_layer_icon_green_opacity" ;
958
+ point_layer_icon_green.save ( _fileNameForTest ( test_name ) );
959
+ QVERIFY ( _verifyImage ( test_name, mReport , 50 ) );
960
+
961
+ const QJsonObject point_layer_symbol_blue = point_layer_symbols[2 ].toObject ();
962
+ const QImage point_layer_icon_blue = _base64ToImage ( point_layer_symbol_blue[" icon" ].toString () );
963
+ test_name = " point_layer_icon_blue_opacity" ;
964
+ point_layer_icon_blue.save ( _fileNameForTest ( test_name ) );
965
+ QVERIFY ( _verifyImage ( test_name, mReport , 50 ) );
966
+
967
+ mVL3 ->setOpacity ( opacity );
968
+ }
930
969
931
970
QGSTEST_MAIN ( TestQgsLegendRenderer )
932
971
#include " testqgslegendrenderer.moc"
0 commit comments