def testDataDefinedIconRotate(self): """ Test icon-rotate property that depends on a data attribute """ context = QgsMapBoxGlStyleConversionContext() image = QImage(QSize(1, 1), QImage.Format_ARGB32) context.setSprites(image, { "foo": { "x": 0, "y": 0, "width": 1, "height": 1, "pixelRatio": 1 } }) style = { "layout": { "icon-image": "{foo}", "icon-rotate": ["get", "ROTATION"], "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertTrue(has_renderer) self.assertFalse(has_labeling) dd_props = renderer.symbol().symbolLayers()[0].dataDefinedProperties() prop = dd_props.property(QgsSymbolLayer.PropertyAngle) self.assertEqual(prop.asExpression(), '"ROTATION"')
def testLabelWithField(self): context = QgsMapBoxGlStyleConversionContext() style = { "layout": { "visibility": "visible", "text-field": "{substance}", }, "paint": { "text-color": "rgba(47, 47, 47, 1)", }, "type": "symbol" } rendererStyle, has_renderer, labeling_style, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertTrue(has_labeling) self.assertFalse(labeling_style.labelSettings().isExpression) self.assertEqual(labeling_style.labelSettings().fieldName, 'substance')
def testConvertLabels(self): context = QgsMapBoxGlStyleConversionContext() style = { "layout": { "text-field": "{name_en}", "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, 'name_en') self.assertFalse(labeling.labelSettings().isExpression) style = { "layout": { "text-field": "name_en", "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)" }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, 'name_en') self.assertFalse(labeling.labelSettings().isExpression) style = { "layout": { "text-field": [ "format", "foo", { "font-scale": 1.2 }, "bar", { "font-scale": 0.8 } ], "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, 'concat("foo","bar")') self.assertTrue(labeling.labelSettings().isExpression) style = { "layout": { "text-field": "{name_en} - {name_fr}", "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, '''concat("name_en",' - ',"name_fr")''') self.assertTrue(labeling.labelSettings().isExpression) style = { "layout": { "text-field": [ "format", "{name_en} - {name_fr}", { "font-scale": 1.2 }, "bar", { "font-scale": 0.8 } ], "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual( labeling.labelSettings().fieldName, '''concat(concat("name_en",' - ',"name_fr"),"bar")''') self.assertTrue(labeling.labelSettings().isExpression) style = { "layout": { "text-field": ["to-string", ["get", "name"]], "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, '''to_string("name")''') self.assertTrue(labeling.labelSettings().isExpression) # text-transform style = { "layout": { "text-field": "name_en", "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-transform": "uppercase", "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual(labeling.labelSettings().fieldName, 'upper("name_en")') self.assertTrue(labeling.labelSettings().isExpression) style = { "layout": { "text-field": [ "format", "{name_en} - {name_fr}", { "font-scale": 1.2 }, "bar", { "font-scale": 0.8 } ], "text-font": ["Open Sans Semibold", "Arial Unicode MS Bold"], "text-transform": "lowercase", "text-max-width": 8, "text-anchor": "top", "text-size": 11, "icon-size": 1 }, "type": "symbol", "id": "poi_label", "paint": { "text-color": "#666", "text-halo-width": 1.5, "text-halo-color": "rgba(255,255,255,0.95)", "text-halo-blur": 1 }, "source-layer": "poi_label" } renderer, has_renderer, labeling, has_labeling = QgsMapBoxGlStyleConverter.parseSymbolLayer( style, context) self.assertFalse(has_renderer) self.assertTrue(has_labeling) self.assertEqual( labeling.labelSettings().fieldName, '''lower(concat(concat("name_en",' - ',"name_fr"),"bar"))''') self.assertTrue(labeling.labelSettings().isExpression)