From bbad2859abf0ba7b2dbb8b61783793571a443c61 Mon Sep 17 00:00:00 2001 From: Denis Rouzaud Date: Tue, 17 Sep 2024 14:52:48 +0200 Subject: [PATCH] fix halo size + add test --- .../vectortile/qgsmapboxglstyleconverter.cpp | 18 +++++++++++++----- tests/src/python/test_qgsmapboxglconverter.py | 6 +++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/core/vectortile/qgsmapboxglstyleconverter.cpp b/src/core/vectortile/qgsmapboxglstyleconverter.cpp index f6dcbaa98f0a..15273873b0cb 100644 --- a/src/core/vectortile/qgsmapboxglstyleconverter.cpp +++ b/src/core/vectortile/qgsmapboxglstyleconverter.cpp @@ -1480,17 +1480,25 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer, { bufferSize = std::min( bufferSize, textSize * BUFFER_SIZE_SCALE / 4 ); } - else if ( textSize > 0 ) + else if ( textSize > 0 && !bufferSizeDataDefined.isEmpty() ) { - bufferSizeDataDefined = QStringLiteral( "min( %1/4, %2)" ).arg( textSize * BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined ); + bufferSizeDataDefined = QStringLiteral( "min(%1/4, %2)" ).arg( textSize * BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined ); ddLabelProperties.setProperty( QgsPalLayerSettings::Property::BufferSize, QgsProperty::fromExpression( bufferSizeDataDefined ) ); } - else + else if ( !bufferSizeDataDefined.isEmpty() ) + { + bufferSizeDataDefined = QStringLiteral( "min(%1*%2/4, %3)" ) + .arg( textSizeProperty.asExpression() ) + .arg( BUFFER_SIZE_SCALE ) + .arg( bufferSizeDataDefined ); + ddLabelProperties.setProperty( QgsPalLayerSettings::Property::BufferSize, QgsProperty::fromExpression( bufferSizeDataDefined ) ); + } + else if ( bufferSizeDataDefined.isEmpty() ) { - bufferSizeDataDefined = QStringLiteral( "min( %1*%2/4, %2)" ) + bufferSizeDataDefined = QStringLiteral( "min(%1*%2/4, %3)" ) .arg( textSizeProperty.asExpression() ) .arg( BUFFER_SIZE_SCALE ) - .arg( textSizeProperty.asExpression() ); + .arg( bufferSize ); ddLabelProperties.setProperty( QgsPalLayerSettings::Property::BufferSize, QgsProperty::fromExpression( bufferSizeDataDefined ) ); } } diff --git a/tests/src/python/test_qgsmapboxglconverter.py b/tests/src/python/test_qgsmapboxglconverter.py index 0356977c734c..cf327778e25c 100644 --- a/tests/src/python/test_qgsmapboxglconverter.py +++ b/tests/src/python/test_qgsmapboxglconverter.py @@ -760,9 +760,9 @@ def testHaloMaxSize(self): data = ( (16, 3, 3, None), (16, 5, 4, None), - (12, ["get", "some_field_1"], None, 'min( 24/4, "some_field_1")'), - (["get", "some_field_2"], 4, None, 'min( "some_field_2"*2/4, 4)'), - (["get", "some_field_3"], ["get", "some_field_4"], None, 'min( "some_field_3"*2/4, "some_field_4")'), + (12, ["get", "some_field_1"], None, 'min(24/4, "some_field_1")'), + (["get", "some_field_2"], 4, None, f'min("some_field_2"*{BUFFER_SIZE_SCALE:.0f}/4, {BUFFER_SIZE_SCALE*4:.0f})'), + (["get", "some_field_3"], ["get", "some_field_4"], None, f'min("some_field_3"*{BUFFER_SIZE_SCALE:.0f}/4, "some_field_4")'), ) for (text_size, halo_size, expected_size, expected_data_defined) in data: