Skip to content

Commit

Permalink
fix bad parsing of match list with strings + avoid useless warning
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored and nyalldawson committed Sep 16, 2024
1 parent bdc2e10 commit 7b5d8be
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2749,7 +2749,7 @@ QgsProperty QgsMapBoxGlStyleConverter::parseMatchList( const QVariantList &json,
{
QVariantList keys;
QVariant variantKeys = json.value( i );
if ( variantKeys.canConvert< QVariantList >() )
if ( variantKeys.userType() == QMetaType::Type::QVariantList || variantKeys.userType() == QMetaType::Type::QStringList )
keys = variantKeys.toList();
else
keys = {variantKeys};
Expand Down Expand Up @@ -3567,8 +3567,15 @@ QString QgsMapBoxGlStyleConverter::retrieveSpriteAsBase64WithProperties( const Q
matchString ).arg( spriteSize.width() );
}

const QImage sprite = retrieveSprite( json.constLast().toString(), context, spriteSize );
spritePath = prepareBase64( sprite );
if ( !json.constLast().toString().isEmpty() )
{
const QImage sprite = retrieveSprite( json.constLast().toString(), context, spriteSize );
spritePath = prepareBase64( sprite );
}
else
{
spritePath = QString();
}

spriteProperty += QStringLiteral( " ELSE '%1' END" ).arg( spritePath );
spriteSizeProperty += QStringLiteral( " ELSE %3 END" ).arg( spriteSize.width() );
Expand Down
13 changes: 13 additions & 0 deletions tests/src/python/test_qgsmapboxglconverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,19 @@ def testParseMatchList(self):
self.assertEqual(res.asExpression(), 'CASE WHEN "luminosity" IS -15 THEN \'#c8d2d5\' WHEN "luminosity" IS -14 THEN \'#cbd5d8\' WHEN "luminosity" IS -13 THEN \'#cfd7da\' WHEN "luminosity" IS -12 THEN \'#d2dadd\' WHEN "luminosity" IS -11 THEN \'#d5dde0\' WHEN "luminosity" IS -10 THEN \'#d9e0e2\' WHEN "luminosity" IS -9 THEN \'#dce3e5\' WHEN "luminosity" IS -8 THEN \'#e0e6e7\' WHEN "luminosity" IS -7 THEN \'#e3e8ea\' WHEN "luminosity" IS -6 THEN \'#e7ebed\' WHEN "luminosity" IS -5 THEN \'#eaeeef\' WHEN "luminosity" IS -4 THEN \'#eef1f2\' WHEN "luminosity" IS -3 THEN \'#f1f4f5\' WHEN "luminosity" IS -2 THEN \'#f5f7f7\' WHEN "luminosity" IS -1 THEN \'#f8f9fa\' ELSE \'#fcfcfc\' END')
self.assertTrue(qgsDoubleNear(default_number, 0.0))

res, default_color, default_number = QgsMapBoxGlStyleConverter.parseMatchList([
"match",
[
"get",
"class"
],
"scree",
"rgba(0, 0, 0, 1)",
"hsl(35, 86%, 38%)"
], QgsMapBoxGlStyleConverter.PropertyType.Color, conversion_context, 2.5, 200)
self.assertEqual(res.asExpression(), '''CASE WHEN "class" IS 'scree' THEN '#000000' ELSE '#b26e0e' END''')
self.assertTrue(qgsDoubleNear(default_number, 0.0))

def testParseStepList(self):
conversion_context = QgsMapBoxGlStyleConversionContext()
res, default_color, default_number = QgsMapBoxGlStyleConverter.parseStepList([
Expand Down

0 comments on commit 7b5d8be

Please sign in to comment.