Skip to content

Commit

Permalink
fix halo size + add test
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids committed Sep 17, 2024
1 parent 1e61af6 commit bbad285
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
18 changes: 13 additions & 5 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) );
}
}
Expand Down
6 changes: 3 additions & 3 deletions tests/src/python/test_qgsmapboxglconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit bbad285

Please sign in to comment.