From 7d60afc11762c2075c1ffad22b61fa9280f78e87 Mon Sep 17 00:00:00 2001 From: bdm-oslandia Date: Fri, 20 Dec 2024 09:08:08 +0100 Subject: [PATCH] fix(QgsMapBoxGlStyleConverter): also handle text-rotate from property field --- .../vectortile/qgsmapboxglstyleconverter.cpp | 13 +++++++++ tests/src/python/test_qgsmapboxglconverter.py | 27 +++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/core/vectortile/qgsmapboxglstyleconverter.cpp b/src/core/vectortile/qgsmapboxglstyleconverter.cpp index 4df3a2075114..9b5719f00daa 100644 --- a/src/core/vectortile/qgsmapboxglstyleconverter.cpp +++ b/src/core/vectortile/qgsmapboxglstyleconverter.cpp @@ -1713,6 +1713,19 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer, break; } + case QMetaType::Type::QVariantMap: + { + QVariantMap rotateMap = jsonTextRotate.toMap(); + if ( rotateMap.contains( QStringLiteral( "property" ) ) && rotateMap[QStringLiteral( "type" )].toString() == QStringLiteral( "identity" ) ) + { + const QgsProperty property = QgsProperty::fromExpression( rotateMap[QStringLiteral( "property" )].toString() ); + ddLabelProperties.setProperty( QgsPalLayerSettings::Property::LabelRotation, property ); + } + else + context.pushWarning( QObject::tr( "%1: Skipping unsupported text-rotate map content (%2)" ).arg( context.layerId(), QString( QJsonDocument::fromVariant( rotateMap ).toJson() ) ) ); + break; + } + default: context.pushWarning( QObject::tr( "%1: Skipping unsupported text-rotate type (%2)" ).arg( context.layerId(), QMetaType::typeName( static_cast( jsonTextRotate.userType() ) ) ) ); break; diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index 8f4640eb89c0..c4a2eb87368d 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -2203,6 +2203,33 @@ def testLabelRotation(self): '"direction"', ) + context = QgsMapBoxGlStyleConversionContext() + style = { + "layout": { + "visibility": "visible", + "text-field": "{substance}", + "text-rotate": { + "property": "label_angle1", + "default": 0, + "type": "identity", + }, + }, + "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) + ls = labeling_style.labelSettings() + ddp = ls.dataDefinedProperties() + self.assertEqual( + ddp.property(QgsPalLayerSettings.Property.LabelRotation).asExpression(), + "label_angle1", + ) + def test_parse_visibility(self): context = QgsMapBoxGlStyleConversionContext() style = {