QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
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 QgsMapLayer;
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 Qgis::RenderUnit targetUnit() const;
71
87 void setTargetUnit( Qgis::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
354
356
359 {
360 Success = 0,
361 NoLayerList = 1,
362 };
363
368 enum class PropertyType
369 {
370 Color,
371 Numeric,
372 Opacity,
373 Point,
374 NumericArray,
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 parseStepList( 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 QgsProperty parseInterpolateListByZoom( const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier = 1,
689 int maxOpacity = 255, QColor *defaultColor SIP_OUT = nullptr, double *defaultNumber SIP_OUT = nullptr );
690
698 static QString parseColorExpression( const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context );
699
711 static QColor parseColor( const QVariant &color, QgsMapBoxGlStyleConversionContext &context );
712
723 static void colorAsHslaComponents( const QColor &color, int &hue, int &saturation, int &lightness, int &alpha );
724
731 static QString interpolateExpression( double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier = 1, QgsMapBoxGlStyleConversionContext *contextPtr = 0 );
732
738 static Qt::PenCapStyle parseCapStyle( const QString &style );
739
745 static Qt::PenJoinStyle parseJoinStyle( const QString &style );
746
752 static QString parseExpression( const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
753
760 static QImage retrieveSprite( const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize );
761
768 static QString retrieveSpriteAsBase64( const QVariant &value, QgsMapBoxGlStyleConversionContext &context )
769 {
770 QSize spriteSize;
771 QString spriteProperty;
772 QString spriteSizeProperty;
773 return retrieveSpriteAsBase64WithProperties( value, context, spriteSize, spriteProperty, spriteSizeProperty );
774 }
775
784 static QString retrieveSpriteAsBase64WithProperties( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize SIP_OUT, QString &spriteProperty SIP_OUT, QString &spriteSizeProperty SIP_OUT );
785
786 private:
787
788#ifdef SIP_RUN
790#endif
791
792 static QString parseValue( const QVariant &value, QgsMapBoxGlStyleConversionContext &context, bool colorExpected = false );
793
794 static QString parseKey( const QVariant &value, QgsMapBoxGlStyleConversionContext &context );
795
796 static QString processLabelField( const QString &string, bool &isExpression );
797
806 static bool numericArgumentsOnly( const QVariant &bottomVariant, const QVariant &topVariant, double &bottom, double &top );
807
808 QString mError;
809 QStringList mWarnings;
810
811 std::unique_ptr< QgsVectorTileRenderer > mRenderer;
812 std::unique_ptr< QgsVectorTileLabeling > mLabeling;
813
814 QList< QgsMapBoxGlStyleAbstractSource * > mSources;
815 QList< QgsMapBoxGlStyleRasterSubLayer> mRasterSubLayers;
816
817};
818
819#endif // QGSMAPBOXGLSTYLECONVERTER_H
RenderUnit
Rendering size units.
Definition qgis.h:4910
MapBoxGlStyleSourceType
Available MapBox GL style source types.
Definition qgis.h:4119
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
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
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:76
A grouped map of multiple QgsProperty objects, each referenced by a integer key value.
A store for object properties.
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:191
#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:208
QgsExpressionNode * parseExpression(const QString &str, QString &parserErrorMsg, QList< QgsExpression::ParserError > &parserErrors)