QGIS API Documentation  3.22.4-Białowieża (ce8e65e95e)
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 
279  static bool parseFillLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle = false );
280 
291  static bool parseLineLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
292 
303  static bool parseCircleLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
304 
317  static void parseSymbolLayer( const QVariantMap &jsonLayer,
319  bool &hasRenderer SIP_OUT,
321  bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
322 
334  static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
336 
346  static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
347 
358  static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
359 
367  static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
368 
375  static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context );
376 
383  static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
384 
391  static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
392  const QVariantMap &conversionMap,
393  QString *defaultString SIP_OUT = nullptr );
394 
395 
402  static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
403 
409  static QString parseArrayStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
410 
419  static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
420 
431  static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
432  const QVariantMap &conversionMap,
433  QString *defaultString SIP_OUT = nullptr );
434 
435 
441  static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
442  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
443 
444 
450  static QgsProperty parseMatchList( 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 
458  static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
459  int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
460 
468  static QString parseColorExpression( const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context );
469 
481  static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
482 
493  static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
494 
501  static QString interpolateExpression( double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier = 1, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
502 
508  static Qt::PenCapStyle parseCapStyle( const QString &style );
509 
515  static Qt::PenJoinStyle parseJoinStyle( const QString &style );
516 
522  static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
523 
530  static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
531 
538  static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
539 
540  private:
541 
542 #ifdef SIP_RUN
544 #endif
545 
546  static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
547 
548  static QString parseKey( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
549 
558  static bool numericArgumentsOnly( const QVariant &bottomVariant, const QVariant &topVariant, double &bottom, double &top );
559 
560  QString mError;
561  QStringList mWarnings;
562 
563  std::unique_ptr< QgsVectorTileRenderer > mRenderer;
564  std::unique_ptr< QgsVectorTileLabeling > mLabeling;
565 
566 };
567 
568 #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)