QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
|
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings. More...
#include <qgsmapboxglstyleconverter.h>
Public Types | |
enum class | PropertyType { Color , Numeric , Opacity , Point } |
Property types, for interpolated value conversion. More... | |
enum | Result { Success = 0 , NoLayerList = 1 } |
Result of conversion. More... | |
Public Member Functions | |
QgsMapBoxGlStyleConverter () | |
Constructor for QgsMapBoxGlStyleConverter. More... | |
QgsMapBoxGlStyleConverter (const QgsMapBoxGlStyleConverter &other)=delete | |
QgsMapBoxGlStyleConverter cannot be copied. More... | |
~QgsMapBoxGlStyleConverter () | |
Result | convert (const QString &style, QgsMapBoxGlStyleConversionContext *context=nullptr) |
Converts a JSON style string, and returns the resultant status of the conversion. More... | |
Result | convert (const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context=nullptr) |
Converts a JSON style map, and returns the resultant status of the conversion. More... | |
QList< QgsMapLayer * > | createSubLayers () const |
Returns a list of new map layers corresponding to sublayers of the style, e.g. More... | |
QString | errorMessage () const |
Returns a descriptive error message if an error was encountered during the style conversion, or an empty string if no error was encountered. More... | |
QgsVectorTileLabeling * | labeling () const |
Returns a new instance of a vector tile labeling representing the converted style, or nullptr if the style could not be converted successfully. More... | |
QgsMapBoxGlStyleConverter & | operator= (const QgsMapBoxGlStyleConverter &other)=delete |
QgsMapBoxGlStyleConverter cannot be copied. More... | |
QList< QgsMapBoxGlStyleRasterSubLayer > | rasterSubLayers () const |
Returns a list of raster sub layers contained in the style. More... | |
QgsVectorTileRenderer * | renderer () const |
Returns a new instance of a vector tile renderer representing the converted style, or nullptr if the style could not be converted successfully. More... | |
QList< QgsMapBoxGlStyleAbstractSource * > | sources () |
Returns the list of converted sources. More... | |
QStringList | warnings () const |
Returns a list of user-friendly warnings generated during the conversion, e.g. More... | |
Protected Member Functions | |
void | parseLayers (const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context=nullptr) |
Parse list of layers from JSON. More... | |
void | parseRasterSource (const QVariantMap &source, const QString &name, QgsMapBoxGlStyleConversionContext *context=nullptr) |
Parse a raster source from JSON. More... | |
void | parseSources (const QVariantMap &sources, QgsMapBoxGlStyleConversionContext *context=nullptr) |
Parse list of sources from JSON. More... | |
Static Protected Member Functions | |
static void | colorAsHslaComponents (const QColor &color, int &hue, int &saturation, int &lightness, int &alpha) |
Takes a QColor object and returns HSLA components in required format for QGIS color_hsla() expression function. More... | |
static QString | interpolateExpression (double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier=1, QgsMapBoxGlStyleConversionContext *contextPtr=0) |
Generates an interpolation for values between valueMin and valueMax, scaled between the ranges zoomMin to zoomMax. More... | |
static QString | parseArrayStops (const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1) |
Takes numerical arrays from stops. More... | |
static Qt::PenCapStyle | parseCapStyle (const QString &style) |
Converts a value to Qt::PenCapStyle enum from JSON value. More... | |
static bool | parseCircleLayer (const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context) |
Parses a circle layer. More... | |
static QColor | parseColor (const QVariant &color, QgsMapBoxGlStyleConversionContext &context) |
Parses a color in one of these supported formats: More... | |
static QString | parseColorExpression (const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context) |
Converts an expression representing a color to a string (can be color string or an expression where a color is expected) More... | |
static QString | parseExpression (const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected=false) |
Converts a MapBox GL expression to a QGIS expression. More... | |
static bool | parseFillLayer (const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle=false) |
Parses a fill layer. More... | |
static QgsProperty | parseInterpolateByZoom (const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, double *defaultNumber=nullptr) |
Parses a numeric value which is interpolated by zoom range. More... | |
static QgsProperty | parseInterpolateColorByZoom (const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor=nullptr) |
Parses a color value which is interpolated by zoom range. More... | |
static QgsProperty | parseInterpolateListByZoom (const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr) |
Interpolates a list which starts with the interpolate function. More... | |
static QgsProperty | parseInterpolateOpacityByZoom (const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr=0) |
Interpolates opacity with either scale_linear() or scale_exp() (depending on base value). More... | |
static QgsProperty | parseInterpolatePointByZoom (const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, QPointF *defaultPoint=nullptr) |
Interpolates a point/offset with either scale_linear() or scale_exp() (depending on base value). More... | |
static QgsProperty | parseInterpolateStringByZoom (const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr) |
Interpolates a string by zoom. More... | |
static Qt::PenJoinStyle | parseJoinStyle (const QString &style) |
Converts a value to Qt::PenJoinStyle enum from JSON value. More... | |
static QString | parseLabelStops (const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context) |
Parses a list of interpolation stops containing label values. More... | |
static bool | parseLineLayer (const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context) |
Parses a line layer. More... | |
static QgsProperty | parseMatchList (const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr) |
Parses and converts a match function value list. More... | |
static QString | parseOpacityStops (double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context) |
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate alpha component of color. More... | |
static QString | parsePointStops (double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1) |
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate point/offset values. More... | |
static QString | parseStops (double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context) |
Parses a list of interpolation stops. More... | |
static QString | parseStringStops (const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr) |
Parses a list of interpolation stops containing string values. More... | |
static void | parseSymbolLayer (const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, bool &hasRenderer, QgsVectorTileBasicLabelingStyle &labelingStyle, bool &hasLabeling, QgsMapBoxGlStyleConversionContext &context) |
Parses a symbol layer as renderer or labeling. More... | |
static bool | parseSymbolLayerAsRenderer (const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, QgsMapBoxGlStyleConversionContext &context) |
Parses a symbol layer as a renderer. More... | |
static QgsProperty | parseValueList (const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr) |
Parses and converts a value list (e.g. More... | |
static QImage | retrieveSprite (const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize) |
Retrieves the sprite image with the specified name, taken from the specified context. More... | |
static QString | retrieveSpriteAsBase64 (const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty) |
Retrieves the sprite image with the specified name, taken from the specified context as a base64 encoded value. More... | |
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
Conversions are performed by calling convert() with either a JSON map or JSON string value, and then retrieving the results by calling renderer() or labeling() respectively.
Definition at line 340 of file qgsmapboxglstyleconverter.h.
|
strong |
Property types, for interpolated value conversion.
Enumerator | |
---|---|
Color | Color property. |
Numeric | Numeric property (e.g. line width, text size) |
Opacity | Opacity property. |
Point | Point/offset property. |
Definition at line 369 of file qgsmapboxglstyleconverter.h.
Result of conversion.
Enumerator | |
---|---|
Success | Conversion was successful. |
NoLayerList | No layer list was found in JSON input. |
Definition at line 359 of file qgsmapboxglstyleconverter.h.
QgsMapBoxGlStyleConverter::QgsMapBoxGlStyleConverter | ( | ) |
Constructor for QgsMapBoxGlStyleConverter.
Definition at line 49 of file qgsmapboxglstyleconverter.cpp.
|
delete |
QgsMapBoxGlStyleConverter cannot be copied.
QgsMapBoxGlStyleConverter::~QgsMapBoxGlStyleConverter | ( | ) |
Definition at line 80 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Takes a QColor object and returns HSLA components in required format for QGIS color_hsla() expression function.
color | input color |
hue | an integer value from 0 to 360 |
saturation | an integer value from 0 to 100 |
lightness | an integer value from 0 to 100 |
alpha | an integer value from 0 (completely transparent) to 255 (opaque). |
Definition at line 2827 of file qgsmapboxglstyleconverter.cpp.
QgsMapBoxGlStyleConverter::Result QgsMapBoxGlStyleConverter::convert | ( | const QString & | style, |
QgsMapBoxGlStyleConversionContext * | context = nullptr |
||
) |
Converts a JSON style string, and returns the resultant status of the conversion.
If an error occurs during conversion then a descriptive error message can be retrieved by calling errorMessage().
After conversion, the resultant labeling and style rules can be retrieved by calling renderer() or labeling() respectively.
The optional context argument can be set to use a specific context during the conversion.
Definition at line 75 of file qgsmapboxglstyleconverter.cpp.
QgsMapBoxGlStyleConverter::Result QgsMapBoxGlStyleConverter::convert | ( | const QVariantMap & | style, |
QgsMapBoxGlStyleConversionContext * | context = nullptr |
||
) |
Converts a JSON style map, and returns the resultant status of the conversion.
If an error occurs during conversion then a descriptive error message can be retrieved by calling errorMessage().
After conversion, the resultant labeling and style rules can be retrieved by calling renderer() or labeling() respectively.
The optional context argument can be set to use a specific context during the conversion.
Definition at line 53 of file qgsmapboxglstyleconverter.cpp.
QList< QgsMapLayer * > QgsMapBoxGlStyleConverter::createSubLayers | ( | ) | const |
Returns a list of new map layers corresponding to sublayers of the style, e.g.
raster layers.
The caller takes ownership of the returned layers.
Definition at line 3434 of file qgsmapboxglstyleconverter.cpp.
|
inline |
Returns a descriptive error message if an error was encountered during the style conversion, or an empty string if no error was encountered.
Definition at line 410 of file qgsmapboxglstyleconverter.h.
|
staticprotected |
Generates an interpolation for values between valueMin and valueMax, scaled between the ranges zoomMin to zoomMax.
Definition at line 2835 of file qgsmapboxglstyleconverter.cpp.
QgsVectorTileLabeling * QgsMapBoxGlStyleConverter::labeling | ( | ) | const |
Returns a new instance of a vector tile labeling representing the converted style, or nullptr
if the style could not be converted successfully.
Definition at line 3419 of file qgsmapboxglstyleconverter.cpp.
|
delete |
QgsMapBoxGlStyleConverter cannot be copied.
|
staticprotected |
Takes numerical arrays from stops.
Definition at line 2432 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Converts a value to Qt::PenCapStyle enum from JSON value.
Definition at line 2895 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a circle layer.
jsonLayer | circle layer to parse |
style | generated QGIS vector tile style |
context | conversion context |
true
if the layer was successfully parsed. Definition at line 785 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a color in one of these supported formats:
#fff
or #ffffff
hsl(30, 19%, 90%)
or hsla(30, 19%, 90%, 0.4)
rgb(10, 20, 30)
or rgba(10, 20, 30, 0.5)
Returns an invalid color if the color could not be parsed.
Definition at line 2816 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Converts an expression representing a color to a string (can be color string or an expression where a color is expected)
colorExpression | the color expression |
context | the style conversion context |
Definition at line 2807 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Converts a MapBox GL expression to a QGIS expression.
Definition at line 2915 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a fill layer.
jsonLayer | fill layer to parse |
style | generated QGIS vector tile style |
context | conversion context |
isBackgroundStyle | set to true if the layer should be parsed as background layer |
true
if the layer was successfully parsed. Definition at line 215 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a numeric value which is interpolated by zoom range.
json | definition of interpolation |
context | conversion context |
multiplier | optional multiplication factor |
defaultNumber | optional storage for a reasonable "default" number representing the overall property. |
Definition at line 2263 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a color value which is interpolated by zoom range.
json | definition of color interpolation |
context | conversion context |
defaultColor | optional storage for a reasonable "default" color representing the overall property. |
Definition at line 2167 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Interpolates a list which starts with the interpolate function.
Definition at line 2749 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Interpolates opacity with either scale_linear() or scale_exp() (depending on base value).
For json with intermediate stops it uses parseOpacityStops() function. It uses QGIS set_color_part() function to set alpha component of color.
Definition at line 2289 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Interpolates a point/offset with either scale_linear() or scale_exp() (depending on base value).
For json with intermediate stops it uses parsePointStops() function.
Definition at line 2354 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Interpolates a string by zoom.
For json with intermediate stops it uses parseStringStops() function.
Definition at line 2386 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Converts a value to Qt::PenJoinStyle enum from JSON value.
Definition at line 2905 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a list of interpolation stops containing label values.
stops | definition of interpolation stops |
context | conversion context |
Definition at line 2563 of file qgsmapboxglstyleconverter.cpp.
|
protected |
Parse list of layers from JSON.
Definition at line 85 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a line layer.
jsonLayer | line layer to parse |
style | generated QGIS vector tile style |
context | conversion context |
true
if the layer was successfully parsed. Definition at line 450 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses and converts a match function value list.
Definition at line 2644 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate alpha component of color.
Definition at line 2322 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate point/offset values.
Definition at line 2398 of file qgsmapboxglstyleconverter.cpp.
|
protected |
Parse a raster source from JSON.
Definition at line 3513 of file qgsmapboxglstyleconverter.cpp.
|
protected |
Parse list of sources from JSON.
Definition at line 3461 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a list of interpolation stops.
base | interpolation exponent base |
stops | definition of interpolation stops |
multiplier | optional multiplication factor |
context | conversion context |
Definition at line 2477 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a list of interpolation stops containing string values.
stops | definition of interpolation stops |
context | conversion context |
conversionMap | map of input string to output expression value |
defaultString | reasonable default value taken from stops |
Definition at line 2528 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a symbol layer as renderer or labeling.
jsonLayer | symbol layer to parse |
rendererStyle | generated QGIS vector tile style |
hasRenderer | will be set to true if symbol layer generated a renderer style |
labelingStyle | generated QGIS vector tile labeling |
hasLabeling | will be set to true if symbol layer generated a labeling style |
context | conversion context |
Definition at line 1035 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses a symbol layer as a renderer.
jsonLayer | fill layer to parse |
rendererStyle | generated QGIS vector tile style |
context | conversion context |
true
if symbol layer was converted to renderer Definition at line 1858 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Parses and converts a value list (e.g.
an interpolate list).
Definition at line 2627 of file qgsmapboxglstyleconverter.cpp.
QList< QgsMapBoxGlStyleRasterSubLayer > QgsMapBoxGlStyleConverter::rasterSubLayers | ( | ) | const |
Returns a list of raster sub layers contained in the style.
Definition at line 3429 of file qgsmapboxglstyleconverter.cpp.
QgsVectorTileRenderer * QgsMapBoxGlStyleConverter::renderer | ( | ) | const |
Returns a new instance of a vector tile renderer representing the converted style, or nullptr
if the style could not be converted successfully.
Definition at line 3414 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Retrieves the sprite image with the specified name, taken from the specified context.
The context must have valid sprite definitions and images set via QgsMapBoxGlStyleConversionContext::setSprites() prior to conversion.
Definition at line 3085 of file qgsmapboxglstyleconverter.cpp.
|
staticprotected |
Retrieves the sprite image with the specified name, taken from the specified context as a base64 encoded value.
The context must have valid sprite definitions and images set via QgsMapBoxGlStyleConversionContext::setSprites() prior to conversion.
Definition at line 3114 of file qgsmapboxglstyleconverter.cpp.
QList< QgsMapBoxGlStyleAbstractSource * > QgsMapBoxGlStyleConverter::sources | ( | ) |
Returns the list of converted sources.
Definition at line 3424 of file qgsmapboxglstyleconverter.cpp.
|
inline |
Returns a list of user-friendly warnings generated during the conversion, e.g.
as a result of MapBox GL style settings which cannot be translated to QGIS styles.
Definition at line 418 of file qgsmapboxglstyleconverter.h.