QGIS API Documentation 3.29.0-Master (da8bb1db43)
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#include "qgsunittypes.h"
24
25#include <memory>
26#include <QVariantMap>
27#include <QImage>
28
33class QgsRasterLayer;
34
42{
43 public:
44
48 void pushWarning( const QString &warning );
49
53 QStringList warnings() const { return mWarnings; }
54
58 void clearWarnings() { mWarnings.clear(); }
59
70 QgsUnitTypes::RenderUnit targetUnit() const;
71
87 void setTargetUnit( QgsUnitTypes::RenderUnit targetUnit );
88
95 double pixelSizeConversionFactor() const;
96
103 void setPixelSizeConversionFactor( double sizeConversionFactor );
104
111 QImage spriteImage() const;
112
119 QVariantMap spriteDefinitions() const;
120
127 void setSprites( const QImage &image, const QVariantMap &definitions );
128
135 void setSprites( const QImage &image, const QString &definitions );
136
142 QString layerId() const;
143
149 void setLayerId( const QString &value );
150
151 private:
152
153 QStringList mWarnings;
154
155 QString mLayerId;
156
158
159 double mSizeConversionFactor = 1.0;
160
161 QImage mSpriteImage;
162 QVariantMap mSpriteDefinitions;
163};
164
165
166
167
175{
176 public:
177
178#ifdef SIP_RUN
180
181 switch ( sipCpp->type() )
182 {
184 sipType = sipType_QgsMapBoxGlStyleRasterSource;
185 break;
186 default:
187 sipType = 0;
188 break;
189 }
190 SIP_END
191#endif
192
196 QgsMapBoxGlStyleAbstractSource( const QString &name );
197
199
204
208 virtual bool setFromJson( const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context ) = 0;
209
213 QString name() const;
214
215 private:
216
217 QString mName;
218};
219
220
228{
229 public:
230
234 QgsMapBoxGlStyleRasterSource( const QString &name );
235
236 Qgis::MapBoxGlStyleSourceType type() const override;
237 bool setFromJson( const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context ) override;
238
242 QString attribution() const { return mAttribution; }
243
249 int minimumZoom() const { return mMinZoom; }
250
256 int maximumZoom() const { return mMaxZoom; }
257
261 int tileSize() const { return mTileSize; }
262
266 QStringList tiles() const { return mTiles; }
267
273 QgsRasterLayer *toRasterLayer() const SIP_FACTORY;
274
275 private:
276
277 QStringList mTiles;
278 QString mAttribution;
279 int mMinZoom = 0;
280 int mMaxZoom = 22;
281 int mTileSize = 512;
282};
283
284
285
293{
294 public:
295
299 QgsMapBoxGlStyleRasterSubLayer( const QString &id, const QString &source );
300
304 QString id() const { return mId; }
305
309 QString source() const { return mSource; }
310
314 QgsPropertyCollection &dataDefinedProperties() { return mDataDefinedProperties; }
315
319 const QgsPropertyCollection &dataDefinedProperties() const SIP_SKIP { return mDataDefinedProperties; }
320
321 private:
322
323 QString mId;
324 QString mSource;
325 QgsPropertyCollection mDataDefinedProperties;
326
327};
328
329
342{
343 Q_GADGET
344
345 public:
346
351
356
358
361 {
362 Success = 0,
363 NoLayerList = 1,
364 };
365
370 enum class PropertyType
371 {
372 Color,
373 Numeric,
374 Opacity,
375 Point,
376 };
377 Q_ENUM( PropertyType )
378
379
390 Result convert( const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
391
403 Result convert( const QString &style, QgsMapBoxGlStyleConversionContext *context = nullptr );
404
411 QString errorMessage() const { return mError; }
412
419 QStringList warnings() const { return mWarnings; }
420
425 QgsVectorTileRenderer *renderer() const SIP_FACTORY;
426
431 QgsVectorTileLabeling *labeling() const SIP_FACTORY;
432
438 QList< QgsMapBoxGlStyleAbstractSource * > sources();
439
445 QList< QgsMapBoxGlStyleRasterSubLayer > rasterSubLayers() const;
446
454 QList< QgsMapLayer * > createSubLayers() const SIP_FACTORY;
455
456 protected:
457
464 void parseSources( const QVariantMap &sources, QgsMapBoxGlStyleConversionContext *context = nullptr );
465
472 void parseRasterSource( const QVariantMap &source, const QString &name, QgsMapBoxGlStyleConversionContext *context = nullptr );
473
478 void parseLayers( const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context = nullptr );
479
491 static bool parseFillLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle = false );
492
503 static bool parseLineLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
504
515 static bool parseCircleLayer( const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
516
529 static void parseSymbolLayer( const QVariantMap &jsonLayer,
531 bool &hasRenderer SIP_OUT,
533 bool &hasLabeling SIP_OUT, QgsMapBoxGlStyleConversionContext &context );
534
546 static bool parseSymbolLayerAsRenderer( const QVariantMap &jsonLayer,
548
558 static QgsProperty parseInterpolateColorByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor SIP_OUT = nullptr );
559
570 static QgsProperty parseInterpolateByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, double *defaultNumber SIP_OUT = nullptr );
571
579 static QgsProperty parseInterpolateOpacityByZoom( const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
580
587 static QString parseOpacityStops( double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context );
588
595 static QgsProperty parseInterpolatePointByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1, QPointF *defaultPoint SIP_OUT = nullptr );
596
603 static QgsProperty parseInterpolateStringByZoom( const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context,
604 const QVariantMap &conversionMap,
605 QString *defaultString SIP_OUT = nullptr );
606
613 static QString parsePointStops( double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
614
620 static QString parseArrayStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1 );
621
630 static QString parseStops( double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context );
631
642 static QString parseStringStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context,
643 const QVariantMap &conversionMap,
644 QString *defaultString SIP_OUT = nullptr );
645
646
655 static QString parseLabelStops( const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context );
656
662 static QgsProperty parseValueList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
663 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
664
665
671 static QgsProperty parseMatchList( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
672 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
673
679 static QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
680 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
681
689 static QString parseColorExpression( const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context );
690
702 static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
703
714 static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
715
722 static QString interpolateExpression( double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier = 1, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
723
729 static Qt::PenCapStyle parseCapStyle( const QString &style );
730
736 static Qt::PenJoinStyle parseJoinStyle( const QString &style );
737
743 static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
744
751 static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
752
759 static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty );
760
761 private:
762
763#ifdef SIP_RUN
765#endif
766
767 static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
768
769 static QString parseKey( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
770
771 static QString processLabelField( const QString &string, bool &isExpression );
772
781 static bool numericArgumentsOnly( const QVariant &bottomVariant, const QVariant &topVariant, double &bottom, double &top );
782
783 QString mError;
784 QStringList mWarnings;
785
786 std::unique_ptr< QgsVectorTileRenderer > mRenderer;
787 std::unique_ptr< QgsVectorTileLabeling > mLabeling;
788
789 QList< QgsMapBoxGlStyleAbstractSource * > mSources;
790 QList< QgsMapBoxGlStyleRasterSubLayer> mRasterSubLayers;
791
792};
793
794#endif // QGSMAPBOXGLSTYLECONVERTER_H
MapBoxGlStyleSourceType
Flags which control project capabilities.
Definition: qgis.h:2426
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.
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_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)