Skip to content
Permalink
Browse files

Improve handling of text-transform setting

  • Loading branch information
nyalldawson committed Sep 6, 2020
1 parent df774f5 commit c58e540ff3099ae04564ae5b275595f2269dec6b
Showing with 66 additions and 3 deletions.
  1. +3 −3 src/core/vectortile/qgsmapboxglstyleconverter.cpp
  2. +63 −0 tests/src/python/test_qgsmapboxglconverter.py
@@ -830,16 +830,16 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,

if ( jsonLayout.contains( QStringLiteral( "text-transform" ) ) )
{
labelSettings.isExpression = true;
const QString textTransform = jsonLayout.value( QStringLiteral( "text-transform" ) ).toString();
if ( textTransform == QLatin1String( "uppercase" ) )
{
labelSettings.fieldName = QStringLiteral( "upper(%1)" ).arg( labelSettings.fieldName );
labelSettings.fieldName = QStringLiteral( "upper(%1)" ).arg( labelSettings.isExpression ? labelSettings.fieldName : QgsExpression::quotedColumnRef( labelSettings.fieldName ) );
}
else if ( textTransform == QLatin1String( "lowercase" ) )
{
labelSettings.fieldName = QStringLiteral( "lower(%1)" ).arg( labelSettings.fieldName );
labelSettings.fieldName = QStringLiteral( "lower(%1)" ).arg( labelSettings.isExpression ? labelSettings.fieldName : QgsExpression::quotedColumnRef( labelSettings.fieldName ) );
}
labelSettings.isExpression = true;
}

labelSettings.placement = QgsPalLayerSettings::OverPoint;
@@ -335,6 +335,69 @@ def testConvertLabels(self):
self.assertEqual(labeling.labelSettings().fieldName, '''concat(concat("name_en",' - ',"name_fr"),"bar")''')
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)


if __name__ == '__main__':
unittest.main()

0 comments on commit c58e540

Please sign in to comment.
You can’t perform that action at this time.