QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
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"
23
24#include <memory>
25#include <QVariantMap>
26#include <QImage>
27
32class QgsRasterLayer;
33
41{
42 public:
43
47 void pushWarning( const QString &warning );
48
52 QStringList warnings() const { return mWarnings; }
53
57 void clearWarnings() { mWarnings.clear(); }
58
69 Qgis::RenderUnit targetUnit() const;
70
86 void setTargetUnit( Qgis::RenderUnit targetUnit );
87
94 double pixelSizeConversionFactor() const;
95
102 void setPixelSizeConversionFactor( double sizeConversionFactor );
103
110 QImage spriteImage() const;
111
118 QVariantMap spriteDefinitions() const;
119
126 void setSprites( const QImage &image, const QVariantMap &definitions );
127
134 void setSprites( const QImage &image, const QString &definitions );
135
141 QString layerId() const;
142
148 void setLayerId( const QString &value );
149
150 private:
151
152 QStringList mWarnings;
153
154 QString mLayerId;
155
156 Qgis::RenderUnit mTargetUnit = Qgis::RenderUnit::Pixels;
157
158 double mSizeConversionFactor = 1.0;
159
160 QImage mSpriteImage;
161 QVariantMap mSpriteDefinitions;
162};
163
164
165
166
174{
175 public:
176
177#ifdef SIP_RUN
179
180 switch ( sipCpp->type() )
181 {
183 sipType = sipType_QgsMapBoxGlStyleRasterSource;
184 break;
185 default:
186 sipType = 0;
187 break;
188 }
189 SIP_END
190#endif
191
195 QgsMapBoxGlStyleAbstractSource( const QString &name );
196
198
203
207 virtual bool setFromJson( const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context ) = 0;
208
212 QString name() const;
213
214 private:
215
216 QString mName;
217};
218
219
227{
228 public:
229
233 QgsMapBoxGlStyleRasterSource( const QString &name );
234
235 Qgis::MapBoxGlStyleSourceType type() const override;
236 bool setFromJson( const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context ) override;
237
241 QString attribution() const { return mAttribution; }
242
248 int minimumZoom() const { return mMinZoom; }
249
255 int maximumZoom() const { return mMaxZoom; }
256
260 int tileSize() const { return mTileSize; }
261
265 QStringList tiles() const { return mTiles; }
266
272 QgsRasterLayer *toRasterLayer() const SIP_FACTORY;
273
274 private:
275
276 QStringList mTiles;
277 QString mAttribution;
278 int mMinZoom = 0;
279 int mMaxZoom = 22;
280 int mTileSize = 512;
281};
282
283
284
292{
293 public:
294
298 QgsMapBoxGlStyleRasterSubLayer( const QString &id, const QString &source );
299
303 QString id() const { return mId; }
304
308 QString source() const { return mSource; }
309
313 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
314
318 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
319
320 private:
321
322 QString mId;
323 QString mSource;
324 QgsPropertyCollection mDataDefinedProperties;
325
326};
327
328
341{
342 Q_GADGET
343
344 public:
345
350
355
357
360 {
361 Success = 0,
362 NoLayerList = 1,
363 };
364
369 enum class PropertyType
370 {
371 Color,
372 Numeric,
373 Opacity,
374 Point,
375 };
376 Q_ENUM( PropertyType )
377
378
389 Result convert( const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
390
402 Result convert( const QString &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
403
410 QString errorMessage() const { return mError; }
411
418 QStringList warnings() const { return mWarnings; }
419
424 QgsVectorTileRenderer *renderer() const SIP_FACTORY;
425
430 QgsVectorTileLabeling *labeling() const SIP_FACTORY;
431
437 QList< QgsMapBoxGlStyleAbstractSource * > sources();
438
444 QList< QgsMapBoxGlStyleRasterSubLayer > rasterSubLayers() const;
445
453 QList< QgsMapLayer * > createSubLayers() const SIP_FACTORY;
454
455 protected:
456
463 void parseSources( const QVariantMap &sources, QgsMapBoxGlStyleConversionContext *context = nullptr );
464
471 void parseRasterSource( const QVariantMap &source, const QString &name, QgsMapBoxGlStyleConversionContext *context = nullptr );
472
477 void parseLayers( const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context = nullptr );
478
490 static bool parseFillLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle = false );
491
502 static bool parseLineLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
503
514 static bool parseCircleLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
515
528 static void parseSymbolLayer( const QVariantMap &jsonLayer,
530 bool &hasRenderer SIP_OUT,
532 bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
533
545 static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
547
557 static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
558
569 static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
570
578 static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
579
586 static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context );
587
594 static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
595
602 static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
603 const QVariantMap &conversionMap,
604 QString *defaultString SIP_OUT = nullptr );
605
612 static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
613
619 static QString parseArrayStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
620
629 static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
630
641 static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
642 const QVariantMap &conversionMap,
643 QString *defaultString SIP_OUT = nullptr );
644
645
654 static QString parseLabelStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context );
655
661 static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
662 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
663
664
670 static QgsProperty parseMatchList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
671 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
672
678 static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
679 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
680
688 static QString parseColorExpression( const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context );
689
701 static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
702
713 static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
714
721 static QString interpolateExpression( double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier = 1, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
722
728 static Qt::PenCapStyle parseCapStyle( const QString &style );
729
735 static Qt::PenJoinStyle parseJoinStyle( const QString &style );
736
742 static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
743
750 static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
751
758 static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
759
760 private:
761
762#ifdef SIP_RUN
764#endif
765
766 static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
767
768 static QString parseKey( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
769
770 static QString processLabelField( const QString &string, bool &isExpression );
771
780 static bool numericArgumentsOnly( const QVariant &bottomVariant, const QVariant &topVariant, double &bottom, double &top );
781
782 QString mError;
783 QStringList mWarnings;
784
785 std::unique_ptr< QgsVectorTileRenderer > mRenderer;
786 std::unique_ptr< QgsVectorTileLabeling > mLabeling;
787
788 QList< QgsMapBoxGlStyleAbstractSource * > mSources;
789 QList< QgsMapBoxGlStyleRasterSubLayer> mRasterSubLayers;
790
791};
792
793#endif // QGSMAPBOXGLSTYLECONVERTER_H
RenderUnit
Rendering size units.
Definition: qgis.h:3176
MapBoxGlStyleSourceType
Flags which control project capabilities.
Definition: qgis.h:2590
Abstract base class for MapBox GL style sources.
virtual bool setFromJson(const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context)=0
Sets the source's state from a json map.
virtual Qgis::MapBoxGlStyleSourceType type() const =0
Returns the source type.
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.
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.
Encapsulates a MapBox GL style raster source.
int maximumZoom() const
Returns the maximum tile zoom for which tiles are available.
QString attribution() const
Returns the source's attribution text.
int tileSize() const
Returns the associated tile size.
int minimumZoom() const
Returns the minimum tile zoom for which tiles are available.
QStringList tiles() const
Returns the list of tile sources.
Encapsulates a MapBox GL style raster sub layer.
QString source() const
Returns the layer's source.
QString id() const
Returns the layer's ID.
QgsPropertyCollection & dataDefinedProperties()
Returns a reference to the layer's data defined properties.
const QgsPropertyCollection & dataDefinedProperties() const
Returns a reference to the layer's data defined properties.
Base class for all map layer types.
Definition: qgsmaplayer.h:73
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A store for object properties.
Definition: qgsproperty.h:230
Represents a raster layer.
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_CONVERT_TO_SUBCLASS_CODE(code)
Definition: qgis_sip.h:186
#define SIP_SKIP
Definition: qgis_sip.h:126
#define SIP_OUT
Definition: qgis_sip.h:58
#define SIP_FACTORY
Definition: qgis_sip.h:76
#define SIP_END
Definition: qgis_sip.h:203
QgsExpressionNode * parseExpression(const QString &str, QString &parserErrorMsg, QList< QgsExpression::ParserError > &parserErrors)