QGIS API Documentation  3.21.0-Master (5b68dc587e)
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 
302  static bool parseCircleLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
303 
316  static void parseSymbolLayer( const QVariantMap &jsonLayer,
318  bool &hasRenderer SIP_OUT,
320  bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
321 
333  static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
335 
345  static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
346 
357  static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
358 
366  static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity );
367 
374  static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity );
375 
382  static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
383 
390  static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
391  const QVariantMap &conversionMap,
392  QString *defaultString SIP_OUT = nullptr );
393 
394 
401  static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
402 
411  static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
412 
423  static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
424  const QVariantMap &conversionMap,
425  QString *defaultString SIP_OUT = nullptr );
426 
427 
433  static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
434  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
435 
436 
442  static QgsProperty parseMatchList( 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 
450  static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
451  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
452 
464  static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
465 
476  static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
477 
484  static QString interpolateExpression( double zoomMin, double zoomMax, double valueMin, double valueMax, double base, double multiplier = 1 );
485 
491  static Qt::PenCapStyle parseCapStyle( const QString &style );
492 
498  static Qt::PenJoinStyle parseJoinStyle( const QString &style );
499 
505  static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context );
506 
513  static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
514 
521  static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
522 
523  private:
524 
525 #ifdef SIP_RUN
527 #endif
528 
529  static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
530  static QString parseKey( const QVariant &value );
531 
532  QString mError;
533  QStringList mWarnings;
534 
535  std::unique_ptr< QgsVectorTileRenderer > mRenderer;
536  std::unique_ptr< QgsVectorTileLabeling > mLabeling;
537 
538 };
539 
540 #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:232
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)