QGIS API Documentation  3.24.2-Tisler (13c1a02865)
qgsmapboxglstyleconverter.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsmapboxglstyleconverter.h
3  --------------------------------------
4  Date : September 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSMAPBOXGLSTYLECONVERTER_H
17 #define QGSMAPBOXGLSTYLECONVERTER_H
18 
19 #include "qgis_core.h"
20 #include "qgis_sip.h"
21 #include "qgsproperty.h"
22 #include <QVariantMap>
23 #include <memory>
24 #include <QImage>
25 
30 
38 {
39  public:
40 
44  void pushWarning( const QString &warning );
45 
49  QStringList warnings() const { return mWarnings; }
50 
54  void clearWarnings() { mWarnings.clear(); }
55 
66  QgsUnitTypes::RenderUnit targetUnit() const;
67 
83  void setTargetUnit( QgsUnitTypes::RenderUnit targetUnit );
84 
91  double pixelSizeConversionFactor() const;
92 
99  void setPixelSizeConversionFactor( double sizeConversionFactor );
100 
107  QImage spriteImage() const;
108 
115  QVariantMap spriteDefinitions() const;
116 
123  void setSprites( const QImage &image, const QVariantMap &definitions );
124 
131  void setSprites( const QImage &image, const QString &definitions );
132 
138  QString layerId() const;
139 
145  void setLayerId( const QString &value );
146 
147  private:
148 
149  QStringList mWarnings;
150 
151  QString mLayerId;
152 
154 
155  double mSizeConversionFactor = 1.0;
156 
157  QImage mSpriteImage;
158  QVariantMap mSpriteDefinitions;
159 };
160 
172 class CORE_EXPORT QgsMapBoxGlStyleConverter
173 {
174  public:
175 
180 
185 
187 
189  enum Result
190  {
191  Success = 0,
192  NoLayerList = 1,
193  };
194 
206  Result convert( const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
207 
219  Result convert( const QString &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
220 
227  QString errorMessage() const { return mError; }
228 
235  QStringList warnings() const { return mWarnings; }
236 
241  QgsVectorTileRenderer *renderer() const SIP_FACTORY;
242 
247  QgsVectorTileLabeling *labeling() const SIP_FACTORY;
248 
249  protected:
250 
256  {
261  };
262 
267  void parseLayers( const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context = nullptr );
268 
280  static bool parseFillLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle = false );
281 
292  static bool parseLineLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
293 
304  static bool parseCircleLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
305 
318  static void parseSymbolLayer( const QVariantMap &jsonLayer,
320  bool &hasRenderer SIP_OUT,
322  bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
323 
335  static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
337 
347  static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
348 
359  static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
360 
368  static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
369 
376  static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context );
377 
384  static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
385 
392  static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
393  const QVariantMap &conversionMap,
394  QString *defaultString SIP_OUT = nullptr );
395 
396 
403  static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
404 
410  static QString parseArrayStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
411 
420  static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
421 
432  static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
433  const QVariantMap &conversionMap,
434  QString *defaultString SIP_OUT = nullptr );
435 
436 
442  static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
443  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
444 
445 
451  static QgsProperty parseMatchList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
452  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
453 
459  static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
460  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
461 
469  static QString parseColorExpression( const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context );
470 
482  static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
483 
494  static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
495 
502  static QString interpolateExpression( double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier = 1, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
503 
509  static Qt::PenCapStyle parseCapStyle( const QString &style );
510 
516  static Qt::PenJoinStyle parseJoinStyle( const QString &style );
517 
523  static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
524 
531  static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
532 
539  static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
540 
541  private:
542 
543 #ifdef SIP_RUN
545 #endif
546 
547  static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
548 
549  static QString parseKey( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
550 
559  static bool numericArgumentsOnly( const QVariant &bottomVariant, const QVariant &topVariant, double &bottom, double &top );
560 
561  QString mError;
562  QStringList mWarnings;
563 
564  std::unique_ptr< QgsVectorTileRenderer > mRenderer;
565  std::unique_ptr< QgsVectorTileLabeling > mLabeling;
566 
567 };
568 
569 #endif // QGSMAPBOXGLSTYLECONVERTER_H
Context for a MapBox GL style conversion operation.
QStringList warnings() const
Returns a list of warning messages generated during the conversion.
void clearWarnings()
Clears the list of warning messages.
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
PropertyType
Property types, for interpolated value conversion.
@ Numeric
Numeric property (e.g. line width, text size)
QgsMapBoxGlStyleConverter & operator=(const QgsMapBoxGlStyleConverter &other)=delete
QgsMapBoxGlStyleConverter cannot be copied.
QString errorMessage() const
Returns a descriptive error message if an error was encountered during the style conversion,...
QStringList warnings() const
Returns a list of user-friendly warnings generated during the conversion, e.g.
QgsMapBoxGlStyleConverter(const QgsMapBoxGlStyleConverter &other)=delete
QgsMapBoxGlStyleConverter cannot be copied.
A store for object properties.
Definition: qgsproperty.h:231
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:168
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:171
Configuration of a single style within QgsVectorTileBasicLabeling.
Definition of map rendering of a subset of vector tile data.
Base class for labeling configuration classes for vector tile layers.
Abstract base class for all vector tile renderer implementations.
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsExpressionNode * parseExpression(const QString &str, QString &parserErrorMsg, QList< QgsExpression::ParserError > &parserErrors)