QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
29 
37 {
38  public:
39 
43  void pushWarning( const QString &warning );
44 
48  QStringList warnings() const { return mWarnings; }
49 
53  void clearWarnings() { mWarnings.clear(); }
54 
65  QgsUnitTypes::RenderUnit targetUnit() const;
66 
82  void setTargetUnit( QgsUnitTypes::RenderUnit targetUnit );
83 
90  double pixelSizeConversionFactor() const;
91 
98  void setPixelSizeConversionFactor( double sizeConversionFactor );
99 
106  QImage spriteImage() const;
107 
114  QVariantMap spriteDefinitions() const;
115 
122  void setSprites( const QImage &image, const QVariantMap &definitions );
123 
130  void setSprites( const QImage &image, const QString &definitions );
131 
137  QString layerId() const;
138 
144  void setLayerId( const QString &value );
145 
146  private:
147 
148  QStringList mWarnings;
149 
150  QString mLayerId;
151 
153 
154  double mSizeConversionFactor = 1.0;
155 
156  QImage mSpriteImage;
157  QVariantMap mSpriteDefinitions;
158 };
159 
171 class CORE_EXPORT QgsMapBoxGlStyleConverter
172 {
173  public:
174 
179 
184 
186 
188  enum Result
189  {
190  Success = 0,
191  NoLayerList = 1,
192  };
193 
205  Result convert( const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
206 
218  Result convert( const QString &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
219 
226  QString errorMessage() const { return mError; }
227 
234  QStringList warnings() const { return mWarnings; }
235 
240  QgsVectorTileRenderer *renderer() const SIP_FACTORY;
241 
246  QgsVectorTileLabeling *labeling() const SIP_FACTORY;
247 
248  protected:
249 
255  {
260  };
261 
266  void parseLayers( const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context = nullptr );
267 
278  static bool parseFillLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
279 
290  static bool parseLineLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
291 
304  static void parseSymbolLayer( const QVariantMap &jsonLayer,
306  bool &hasRenderer SIP_OUT,
308  bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
309 
321  static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
323 
333  static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
334 
345  static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
346 
354  static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity );
355 
362  static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity );
363 
370  static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
371 
378  static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
379  const QVariantMap &conversionMap,
380  QString *defaultString SIP_OUT = nullptr );
381 
382 
389  static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
390 
399  static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
400 
411  static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
412  const QVariantMap &conversionMap,
413  QString *defaultString SIP_OUT = nullptr );
414 
415 
421  static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
422  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
423 
424 
430  static QgsProperty parseMatchList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
431  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
432 
438  static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
439  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
440 
452  static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
453 
464  static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
465 
472  static QString interpolateExpression( double zoomMin, double zoomMax, double valueMin, double valueMax, double base, double multiplier = 1 );
473 
479  static Qt::PenCapStyle parseCapStyle( const QString &style );
480 
486  static Qt::PenJoinStyle parseJoinStyle( const QString &style );
487 
493  static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context );
494 
501  static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
502 
509  static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
510 
511  private:
512 
513 #ifdef SIP_RUN
515 #endif
516 
517  static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
518  static QString parseKey( const QVariant &value );
519 
520  QString mError;
521  QStringList mWarnings;
522 
523  std::unique_ptr< QgsVectorTileRenderer > mRenderer;
524  std::unique_ptr< QgsVectorTileLabeling > mLabeling;
525 
526 };
527 
528 #endif // QGSMAPBOXGLSTYLECONVERTER_H
QgsProperty
A store for object properties.
Definition: qgsproperty.h:232
QgsUnitTypes::RenderUnit
RenderUnit
Rendering size units.
Definition: qgsunittypes.h:167
QgsMapBoxGlStyleConverter::~QgsMapBoxGlStyleConverter
~QgsMapBoxGlStyleConverter()
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsVectorTileBasicLabelingStyle
Configuration of a single style within QgsVectorTileBasicLabeling.
Definition: qgsvectortilebasiclabeling.h:32
parseExpression
QgsExpressionNode * parseExpression(const QString &str, QString &parserErrorMsg, QList< QgsExpression::ParserError > &parserErrors)
QgsMapBoxGlStyleConverter::errorMessage
QString errorMessage() const
Returns a descriptive error message if an error was encountered during the style conversion,...
Definition: qgsmapboxglstyleconverter.h:226
SIP_FACTORY
#define SIP_FACTORY
Definition: qgis_sip.h:76
QgsMapBoxGlStyleConverter::Numeric
@ Numeric
Numeric property (e.g. line width, text size)
Definition: qgsmapboxglstyleconverter.h:257
QgsMapBoxGlStyleConverter::PropertyType
PropertyType
Property types, for interpolated value conversion.
Definition: qgsmapboxglstyleconverter.h:255
QgsMapBoxGlStyleConversionContext
Context for a MapBox GL style conversion operation.
Definition: qgsmapboxglstyleconverter.h:37
QgsVectorTileBasicRendererStyle
Definition of map rendering of a subset of vector tile data.
Definition: qgsvectortilebasicrenderer.h:48
QgsMapBoxGlStyleConversionContext::warnings
QStringList warnings() const
Returns a list of warning messages generated during the conversion.
Definition: qgsmapboxglstyleconverter.h:48
QgsVectorTileRenderer
Abstract base class for all vector tile renderer implementations.
Definition: qgsvectortilerenderer.h:89
QgsMapBoxGlStyleConversionContext::clearWarnings
void clearWarnings()
Clears the list of warning messages.
Definition: qgsmapboxglstyleconverter.h:53
QgsMapBoxGlStyleConverter::Result
Result
Result of conversion.
Definition: qgsmapboxglstyleconverter.h:189
qgis_sip.h
QgsUnitTypes::RenderPixels
@ RenderPixels
Pixels.
Definition: qgsunittypes.h:170
QgsMapBoxGlStyleConverter::Opacity
@ Opacity
Opacity property.
Definition: qgsmapboxglstyleconverter.h:258
QgsMapBoxGlStyleConverter::Color
@ Color
Color property.
Definition: qgsmapboxglstyleconverter.h:256
QgsMapBoxGlStyleConverter::Point
@ Point
Point/offset property.
Definition: qgsmapboxglstyleconverter.h:259
qgsproperty.h
QgsVectorTileLabeling
Base class for labeling configuration classes for vector tile layers.
Definition: qgsvectortilelabeling.h:71
QgsMapBoxGlStyleConverter::warnings
QStringList warnings() const
Returns a list of user-friendly warnings generated during the conversion, e.g.
Definition: qgsmapboxglstyleconverter.h:234
QgsMapBoxGlStyleConverter::QgsMapBoxGlStyleConverter
QgsMapBoxGlStyleConverter(const QgsMapBoxGlStyleConverter &other)=delete
QgsMapBoxGlStyleConverter cannot be copied.
QgsMapBoxGlStyleConverter::operator=
QgsMapBoxGlStyleConverter & operator=(const QgsMapBoxGlStyleConverter &other)=delete
QgsMapBoxGlStyleConverter cannot be copied.
QgsMapBoxGlStyleConverter
Handles conversion of MapBox GL styles to QGIS vector tile renderers and labeling settings.
Definition: qgsmapboxglstyleconverter.h:172