Skip to content

Commit

Permalink
When converting a interpolated line width, also set the base setting …
Browse files Browse the repository at this point in the history
…to a decent value so that legends look ok
  • Loading branch information
nyalldawson committed Sep 6, 2020
1 parent 98ba6a4 commit 54b506a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 13 deletions.
Expand Up @@ -251,13 +251,14 @@ Parses a color value which is interpolated by zoom range.
:param defaultColor: optional storage for a reasonable "default" color representing the overall property.
%End

static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber = 0 );
%Docstring
Parses a numeric value which is interpolated by zoom range.

:param json: definition of interpolation
:param context: conversion context
:param multiplier: optional multiplication factor
:param defaultNumber: optional storage for a reasonable "default" number representing the overall property.
%End

static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json );
Expand Down Expand Up @@ -291,7 +292,9 @@ Parses a list of interpolation stops
:param context: conversion context
%End

static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QColor *defaultColor = 0 );
static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
QColor *defaultColor = 0,
double *defaultNumber = 0 );
%Docstring
Interpolates a list which starts with the interpolate function.

Expand Down
22 changes: 13 additions & 9 deletions src/core/vectortile/qgsmapboxglstyleconverter.cpp
Expand Up @@ -395,12 +395,12 @@ bool QgsMapBoxGlStyleConverter::parseLineLayer( const QVariantMap &jsonLayer, Qg

case QVariant::Map:
lineWidth = -1;
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeWidth, parseInterpolateByZoom( jsonLineWidth.toMap(), context, context.pixelSizeConversionFactor() ) );
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeWidth, parseInterpolateByZoom( jsonLineWidth.toMap(), context, context.pixelSizeConversionFactor(), &lineWidth ) );
break;

case QVariant::List:
case QVariant::StringList:
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeWidth, parseInterpolateListByZoom( jsonLineWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor() ) );
ddProperties.setProperty( QgsSymbolLayer::PropertyStrokeWidth, parseInterpolateListByZoom( jsonLineWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor(), nullptr, &lineWidth ) );
break;

default:
Expand Down Expand Up @@ -568,13 +568,13 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,

case QVariant::Map:
textSize = -1;
ddLabelProperties.setProperty( QgsPalLayerSettings::Size, parseInterpolateByZoom( jsonTextSize.toMap(), context, context.pixelSizeConversionFactor() ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::Size, parseInterpolateByZoom( jsonTextSize.toMap(), context, context.pixelSizeConversionFactor(), &textSize ) );
break;

case QVariant::List:
case QVariant::StringList:
textSize = -1;
ddLabelProperties.setProperty( QgsPalLayerSettings::Size, parseInterpolateListByZoom( jsonTextSize.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor() ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::Size, parseInterpolateListByZoom( jsonTextSize.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor(), nullptr, &textSize ) );
break;

default:
Expand Down Expand Up @@ -698,13 +698,13 @@ void QgsMapBoxGlStyleConverter::parseSymbolLayer( const QVariantMap &jsonLayer,

case QVariant::Map:
bufferSize = 1;
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateByZoom( jsonHaloWidth.toMap(), context, context.pixelSizeConversionFactor() ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateByZoom( jsonHaloWidth.toMap(), context, context.pixelSizeConversionFactor(), &bufferSize ) );
break;

case QVariant::List:
case QVariant::StringList:
bufferSize = 1;
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateListByZoom( jsonHaloWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor() ) );
ddLabelProperties.setProperty( QgsPalLayerSettings::BufferSize, parseInterpolateListByZoom( jsonHaloWidth.toList(), PropertyType::Numeric, context, context.pixelSizeConversionFactor(), nullptr, &bufferSize ) );
break;

default:
Expand Down Expand Up @@ -1005,7 +1005,7 @@ QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateColorByZoom( const QVaria
return QgsProperty::fromExpression( caseString );
}

QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier )
QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier, double *defaultNumber )
{
const double base = json.value( QStringLiteral( "base" ), QStringLiteral( "1" ) ).toDouble();
const QVariantList stops = json.value( QStringLiteral( "stops" ) ).toList();
Expand Down Expand Up @@ -1034,6 +1034,10 @@ QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateByZoom( const QVariantMap
{
scaleExpression = parseStops( base, stops, multiplier, context );
}

if ( !stops.empty() && defaultNumber )
*defaultNumber = stops.value( 0 ).toList().value( 1 ).toDouble() * multiplier;

return QgsProperty::fromExpression( scaleExpression );
}

Expand Down Expand Up @@ -1162,7 +1166,7 @@ QString QgsMapBoxGlStyleConverter::parseStops( double base, const QVariantList &
return caseString;
}

QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier, QColor *defaultColor )
QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier, QColor *defaultColor, double *defaultNumber )
{
if ( json.value( 0 ).toString() != QLatin1String( "interpolate" ) )
{
Expand Down Expand Up @@ -1209,7 +1213,7 @@ QgsProperty QgsMapBoxGlStyleConverter::parseInterpolateListByZoom( const QVarian
return parseInterpolateColorByZoom( props, context, defaultColor );

case PropertyType::Numeric:
return parseInterpolateByZoom( props, context, multiplier );
return parseInterpolateByZoom( props, context, multiplier, defaultNumber );

case PropertyType::Opacity:
return parseInterpolateOpacityByZoom( props );
Expand Down
7 changes: 5 additions & 2 deletions src/core/vectortile/qgsmapboxglstyleconverter.h
Expand Up @@ -271,8 +271,9 @@ class CORE_EXPORT QgsMapBoxGlStyleConverter
* \param json definition of interpolation
* \param context conversion context
* \param multiplier optional multiplication factor
* \param defaultNumber optional storage for a reasonable "default" number representing the overall property.
*/
static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber = nullptr );

/**
* Interpolates opacity with either scale_linear() or scale_exp() (depending on base value).
Expand Down Expand Up @@ -306,7 +307,9 @@ class CORE_EXPORT QgsMapBoxGlStyleConverter
*
* \warning This is private API only, and may change in future QGIS versions
*/
static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QColor *defaultColor = nullptr );
static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
QColor *defaultColor = nullptr,
double *defaultNumber = nullptr );

/**
* Parses a \a color in one of these supported formats:
Expand Down

0 comments on commit 54b506a

Please sign in to comment.