From c567e2005ec7c1b2e67029fd40eb98d917bd2bec Mon Sep 17 00:00:00 2001 From: Mathieu Pellerin Date: Tue, 19 Nov 2024 11:10:58 +0700 Subject: [PATCH] [vector tiles] Handle 'to-boolean' mapboxgl expressions when importing styles --- src/core/vectortile/qgsmapboxglstyleconverter.cpp | 4 ++++ tests/src/python/test_qgsmapboxglconverter.py | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/core/vectortile/qgsmapboxglstyleconverter.cpp b/src/core/vectortile/qgsmapboxglstyleconverter.cpp index 2f269e1907f2..35a960d3ec05 100644 --- a/src/core/vectortile/qgsmapboxglstyleconverter.cpp +++ b/src/core/vectortile/qgsmapboxglstyleconverter.cpp @@ -3428,6 +3428,10 @@ QString QgsMapBoxGlStyleConverter::parseExpression( const QVariantList &expressi { return QStringLiteral( "to_string(%1)" ).arg( parseExpression( expression.value( 1 ).toList(), context ) ); } + else if ( op == QLatin1String( "to-boolean" ) ) + { + return QStringLiteral( "to_bool(%1)" ).arg( parseExpression( expression.value( 1 ).toList(), context ) ); + } else if ( op == QLatin1String( "case" ) ) { QString caseString = QStringLiteral( "CASE" ); diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index e5082049f68f..92c784fdd74f 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -529,6 +529,9 @@ def testParseExpression(self): conversion_context), '''"name"''') + self.assertEqual(QgsMapBoxGlStyleConverter.parseExpression(["to-boolean", ["get", "name"]], + conversion_context), + '''to_bool("name")''') self.assertEqual(QgsMapBoxGlStyleConverter.parseExpression(["to-string", ["get", "name"]], conversion_context), '''to_string("name")''')