Skip to content

Commit

Permalink
Add bracket (in case %2 is an arithmetic expression) and add unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mhugent authored and nyalldawson committed Dec 23, 2021
1 parent 2a7382e commit 3eec85e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
1 change: 0 additions & 1 deletion python/core/auto_generated/layout/qgslayoutitem.sip.in
Expand Up @@ -270,7 +270,6 @@ tasks.
%End

virtual int type() const;

%Docstring
Returns a unique graphics item type identifier.

Expand Down
2 changes: 1 addition & 1 deletion src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -2387,7 +2387,7 @@ QString QgsMapBoxGlStyleConverter::parseStops( double base, const QVariantList &
{
vStr = parseExpression( v.toList(), context );
caseString += QStringLiteral( "WHEN @vector_tile_zoom > %1 "
"THEN ( %2 * %3 ) END" ).arg( z.toString() ).arg( vStr ).arg( multiplier );
"THEN ( ( %2 ) * %3 ) END" ).arg( z.toString() ).arg( vStr ).arg( multiplier );
}
else
{
Expand Down
18 changes: 18 additions & 0 deletions tests/src/python/test_qgsmapboxglconverter.py
Expand Up @@ -290,6 +290,24 @@ def testInterpolateListByZoom(self):
"CASE WHEN @vector_tile_zoom > 10 AND @vector_tile_zoom <= 15 THEN scale_linear(@vector_tile_zoom,10,15,0.1,0.3) * 2 WHEN @vector_tile_zoom > 15 AND @vector_tile_zoom <= 18 THEN scale_linear(@vector_tile_zoom,15,18,0.3,0.6) * 2 WHEN @vector_tile_zoom > 18 THEN 1.2 END")
self.assertEqual(default_val, 0.2)

prop, default_color, default_val = QgsMapBoxGlStyleConverter.parseInterpolateListByZoom([
"interpolate",
["exponential", 1.5],
["zoom"],
5,
0,
6,
["match", ["get", "class"], ["ice", "glacier"], 0.3, 0],
10,
["match", ["get", "class"], ["ice", "glacier"], 0.2, 0],
11,
["match", ["get", "class"], ["ice", "glacier"], 0.2, 0.3],
14,
["match", ["get", "class"], ["ice", "glacier"], 0, 0.3]
], QgsMapBoxGlStyleConverter.Numeric, conversion_context, 2)
self.assertEqual(prop.expressionString(),
"CASE WHEN @vector_tile_zoom > 5 AND @vector_tile_zoom <= 6 THEN scale_exp(@vector_tile_zoom,5,6,0,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.3 ELSE 0 END,1.5) * 2 WHEN @vector_tile_zoom > 6 AND @vector_tile_zoom <= 10 THEN scale_exp(@vector_tile_zoom,6,10,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.3 ELSE 0 END,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.2 ELSE 0 END,1.5) * 2 WHEN @vector_tile_zoom > 10 AND @vector_tile_zoom <= 11 THEN scale_exp(@vector_tile_zoom,10,11,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.2 ELSE 0 END,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.2 ELSE 0.3 END,1.5) * 2 WHEN @vector_tile_zoom > 11 AND @vector_tile_zoom <= 14 THEN scale_exp(@vector_tile_zoom,11,14,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0.2 ELSE 0.3 END,CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0 ELSE 0.3 END,1.5) * 2 WHEN @vector_tile_zoom > 14 THEN ( ( CASE WHEN \"class\" IN ('ice', 'glacier') THEN 0 ELSE 0.3 END ) * 2 ) END")

def testParseExpression(self):
conversion_context = QgsMapBoxGlStyleConversionContext()
self.assertEqual(QgsMapBoxGlStyleConverter.parseExpression([
Expand Down

0 comments on commit 3eec85e

Please sign in to comment.