From c0813b1f1dd62f25a21f6994f369bef7a7204311 Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Thu, 12 Sep 2024 08:57:59 +0700 Subject: [PATCH] Add test coverage --- tests/src/python/test_qgsmapboxglconverter.py | 46 ++++++++++++++++++- 1 file changed, 44 insertions(+), 2 deletions(-) diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index 89b1aec40a5c..643f831dee66 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -14,7 +14,8 @@ from qgis.PyQt.QtCore import ( Qt, QCoreApplication, - QSize + QSize, + QSizeF, ) from qgis.PyQt.QtGui import QColor, QImage from qgis.core import ( @@ -23,6 +24,7 @@ QgsMapBoxGlStyleConversionContext, QgsMapBoxGlStyleConverter, QgsMapBoxGlStyleRasterSource, + QgsPalLayerSettings, QgsRasterLayer, QgsRasterPipe, QgsSettings, @@ -808,7 +810,7 @@ def testDataDefinedIconRotate(self): self.assertEqual(prop.asExpression(), '"ROTATION"') def testScaledIcon(self): - """ Test icon-rotate property that depends on a data attribute """ + """ Test icon-size property that depends on a data attribute """ context = QgsMapBoxGlStyleConversionContext() image = QImage(QSize(1, 1), QImage.Format.Format_ARGB32) @@ -829,6 +831,46 @@ def testScaledIcon(self): size = renderer.symbol().symbolLayers()[0].size() self.assertEqual(size, 4) + def testScaledLabelShieldIcon(self): + """ Test icon-size property for label shields that depends on a data attribute """ + context = QgsMapBoxGlStyleConversionContext() + + image = QImage(QSize(1, 1), QImage.Format.Format_ARGB32) + context.setSprites(image, {"foo": {"x": 0, "y": 0, "width": 2, "height": 2, "pixelRatio": 1}}) + style = { + "layout": { + "visibility": "visible", + "symbol-placement": "line", + "text-field": "{texte}", + "text-size": 11, + "text-rotation-alignment": "viewport", + "icon-rotation-alignment": "viewport", + "icon-image": "{foo}", + "icon-size": { + "stops": [[13, 0.25], [16, 0.45], [17, 0.7]] + } + }, + "paint": { + "text-color": "rgba(47, 47, 47, 1)", + }, + "type": "symbol", + "id": "poi_label", + "source-layer": "poi_label" + } + renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer(style, context) + self.assertTrue(has_renderer) + size = renderer.symbol().symbolLayers()[0].size() + self.assertEqual(size, 0.5) + dd_properties = renderer.symbol().symbolLayers()[0].dataDefinedProperties() + self.assertEqual(dd_properties.property(QgsSymbolLayer.Property.PropertyWidth).asExpression(), + "with_variable('marker_size',CASE WHEN \"foo\" = 'foo' THEN 2 END,(CASE WHEN @vector_tile_zoom >= 13 AND @vector_tile_zoom <= 16 THEN scale_linear(@vector_tile_zoom,13,16,0.25,0.45) WHEN @vector_tile_zoom > 16 AND @vector_tile_zoom <= 17 THEN scale_linear(@vector_tile_zoom,16,17,0.45,0.7) WHEN @vector_tile_zoom > 17 THEN 0.7 END)*@marker_size)") + self.assertTrue(has_labeling) + ls = labeling.labelSettings() + tf = ls.format() + self.assertEqual(tf.background().size(), QSizeF(1, 1)) + self.assertEqual(ls.dataDefinedProperties().property(QgsPalLayerSettings.Property.ShapeSizeX).asExpression(), + "with_variable('marker_size',CASE WHEN \"foo\" = 'foo' THEN 2 END,(CASE WHEN @vector_tile_zoom >= 13 AND @vector_tile_zoom <= 16 THEN scale_linear(@vector_tile_zoom,13,16,0.25,0.45) WHEN @vector_tile_zoom > 16 AND @vector_tile_zoom <= 17 THEN scale_linear(@vector_tile_zoom,16,17,0.45,0.7) WHEN @vector_tile_zoom > 17 THEN 0.7 END)*@marker_size)") + def testCircleLayer(self): context = QgsMapBoxGlStyleConversionContext() style = {