48#include <QRegularExpression>
51#include "moc_qgsmapboxglstyleconverter.cpp"
53using namespace Qt::StringLiterals;
63 if ( style.contains( u
"sources"_s ) )
65 parseSources( style.value( u
"sources"_s ).toMap(), context );
68 if ( style.contains( u
"layers"_s ) )
70 parseLayers( style.value( u
"layers"_s ).toList(), context );
74 mError = QObject::tr(
"Could not find layers list in JSON" );
87 qDeleteAll( mSources );
92 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
95 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
96 context = tmpContext.get();
99 QList<QgsVectorTileBasicRendererStyle> rendererStyles;
100 QList<QgsVectorTileBasicLabelingStyle> labelingStyles;
103 bool hasRendererBackgroundStyle =
false;
105 for (
const QVariant &layer : layers )
107 const QVariantMap jsonLayer = layer.toMap();
109 const QString layerType = jsonLayer.value( u
"type"_s ).toString();
110 if ( layerType ==
"background"_L1 )
112 hasRendererBackgroundStyle =
parseFillLayer( jsonLayer, rendererBackgroundStyle, *context,
true );
113 if ( hasRendererBackgroundStyle )
123 const QString styleId = jsonLayer.value( u
"id"_s ).toString();
126 if ( layerType.compare(
"raster"_L1, Qt::CaseInsensitive ) == 0 )
129 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
130 if ( jsonPaint.contains( u
"raster-opacity"_s ) )
132 const QVariant jsonRasterOpacity = jsonPaint.value( u
"raster-opacity"_s );
133 double defaultOpacity = 1;
137 mRasterSubLayers.append( raster );
141 const QString layerName = jsonLayer.value( u
"source-layer"_s ).toString();
143 const int minZoom = jsonLayer.value( u
"minzoom"_s, u
"-1"_s ).toInt();
152 int maxZoom = jsonLayer.value( u
"maxzoom"_s, u
"-1"_s ).toInt();
157 if ( jsonLayer.contains( u
"visibility"_s ) )
159 visibilyStr = jsonLayer.value( u
"visibility"_s ).toString();
161 else if ( jsonLayer.contains( u
"layout"_s ) && jsonLayer.value( u
"layout"_s ).userType() == QMetaType::Type::QVariantMap )
163 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
164 visibilyStr = jsonLayout.value( u
"visibility"_s ).toString();
167 const bool enabled = visibilyStr !=
"none"_L1;
169 QString filterExpression;
170 if ( jsonLayer.contains( u
"filter"_s ) )
172 filterExpression =
parseExpression( jsonLayer.value( u
"filter"_s ).toList(), *context );
178 bool hasRendererStyle =
false;
179 bool hasLabelingStyle =
false;
180 if ( layerType ==
"fill"_L1 )
182 hasRendererStyle =
parseFillLayer( jsonLayer, rendererStyle, *context );
184 else if ( layerType ==
"line"_L1 )
186 hasRendererStyle =
parseLineLayer( jsonLayer, rendererStyle, *context );
188 else if ( layerType ==
"circle"_L1 )
192 else if ( layerType ==
"symbol"_L1 )
194 parseSymbolLayer( jsonLayer, rendererStyle, hasRendererStyle, labelingStyle, hasLabelingStyle, *context );
198 mWarnings << QObject::tr(
"%1: Skipping unknown layer type %2" ).arg( context->
layerId(), layerType );
203 if ( hasRendererStyle )
211 rendererStyles.append( rendererStyle );
214 if ( hasLabelingStyle )
222 labelingStyles.append( labelingStyle );
225 mWarnings.append( context->
warnings() );
229 if ( hasRendererBackgroundStyle )
230 rendererStyles.prepend( rendererBackgroundStyle );
232 auto renderer = std::make_unique< QgsVectorTileBasicRenderer >();
233 renderer->setStyles( rendererStyles );
236 auto labeling = std::make_unique< QgsVectorTileBasicLabeling >();
237 labeling->setStyles( labelingStyles );
243 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
248 bool colorIsDataDefined =
false;
250 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsFillSymbol >() );
254 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-color"_s : u
"fill-color"_s ) )
256 const QVariant jsonFillColor = jsonPaint.value( isBackgroundStyle ? u
"background-color"_s : u
"fill-color"_s );
257 switch ( jsonFillColor.userType() )
259 case QMetaType::Type::QVariantMap:
263 case QMetaType::Type::QVariantList:
264 case QMetaType::Type::QStringList:
265 colorIsDataDefined =
true;
269 case QMetaType::Type::QString:
270 fillColor =
parseColor( jsonFillColor.toString(), context );
275 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillColor.userType() ) ) ) );
283 fillColor = QColor( 0, 0, 0 );
286 QColor fillOutlineColor;
287 if ( !isBackgroundStyle )
289 if ( !jsonPaint.contains( u
"fill-outline-color"_s ) )
291 if ( fillColor.isValid() )
292 fillOutlineColor = fillColor;
300 const QVariant jsonFillOutlineColor = jsonPaint.value( u
"fill-outline-color"_s );
301 switch ( jsonFillOutlineColor.userType() )
303 case QMetaType::Type::QVariantMap:
307 case QMetaType::Type::QVariantList:
308 case QMetaType::Type::QStringList:
312 case QMetaType::Type::QString:
313 fillOutlineColor =
parseColor( jsonFillOutlineColor.toString(), context );
318 QObject::tr(
"%1: Skipping unsupported fill-outline-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillOutlineColor.userType() ) ) )
325 double fillOpacity = -1.0;
326 double rasterOpacity = -1.0;
327 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-opacity"_s : u
"fill-opacity"_s ) )
329 const QVariant jsonFillOpacity = jsonPaint.value( isBackgroundStyle ? u
"background-opacity"_s : u
"fill-opacity"_s );
330 switch ( jsonFillOpacity.userType() )
332 case QMetaType::Type::Int:
333 case QMetaType::Type::LongLong:
334 case QMetaType::Type::Double:
335 fillOpacity = jsonFillOpacity.toDouble();
336 rasterOpacity = fillOpacity;
339 case QMetaType::Type::QVariantMap:
352 case QMetaType::Type::QVariantList:
353 case QMetaType::Type::QStringList:
368 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillOpacity.userType() ) ) ) );
374 QPointF fillTranslate;
375 if ( jsonPaint.contains( u
"fill-translate"_s ) )
377 const QVariant jsonFillTranslate = jsonPaint.value( u
"fill-translate"_s );
378 switch ( jsonFillTranslate.userType() )
380 case QMetaType::Type::QVariantMap:
384 case QMetaType::Type::QVariantList:
385 case QMetaType::Type::QStringList:
392 QObject::tr(
"%1: Skipping unsupported fill-translate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonFillTranslate.userType() ) ) )
399 Q_ASSERT( fillSymbol );
402 symbol->setOutputUnit( context.
targetUnit() );
405 if ( !fillTranslate.isNull() )
411 if ( jsonPaint.contains( isBackgroundStyle ? u
"background-pattern"_s : u
"fill-pattern"_s ) )
415 const QVariant fillPatternJson = jsonPaint.value( isBackgroundStyle ? u
"background-pattern"_s : u
"fill-pattern"_s );
418 fillColor = QColor();
419 fillOutlineColor = QColor();
426 QString spriteProperty, spriteSizeProperty;
428 if ( !sprite.isEmpty() )
433 rasterFill->
setWidth( spriteSize.width() );
437 if ( rasterOpacity >= 0 )
442 if ( !spriteProperty.isEmpty() )
449 symbol->appendSymbolLayer( rasterFill );
455 if ( fillOpacity != -1 )
457 symbol->setOpacity( fillOpacity );
468 if ( fillOutlineColor.isValid() && ( fillOutlineColor.alpha() == 255 || fillOutlineColor != fillColor ) )
479 if ( fillColor.isValid() )
483 else if ( colorIsDataDefined )
499 if ( !jsonLayer.contains( u
"paint"_s ) )
501 context.
pushWarning( QObject::tr(
"%1: Style has no paint property, skipping" ).arg( context.
layerId() ) );
506 QString rasterLineSprite;
508 const QVariantMap jsonPaint = jsonLayer.
value( u
"paint"_s ).toMap();
509 if ( jsonPaint.contains( u
"line-pattern"_s ) )
511 const QVariant jsonLinePattern = jsonPaint.value( u
"line-pattern"_s );
512 switch ( jsonLinePattern.userType() )
514 case QMetaType::Type::QVariantMap:
515 case QMetaType::Type::QString:
518 QString spriteProperty, spriteSizeProperty;
524 case QMetaType::Type::QVariantList:
525 case QMetaType::Type::QStringList:
530 if ( rasterLineSprite.isEmpty() )
533 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-pattern property" ).arg( context.
layerId() ) );
540 if ( jsonPaint.contains( u
"line-color"_s ) )
542 const QVariant jsonLineColor = jsonPaint.value( u
"line-color"_s );
543 switch ( jsonLineColor.userType() )
545 case QMetaType::Type::QVariantMap:
550 case QMetaType::Type::QVariantList:
551 case QMetaType::Type::QStringList:
556 case QMetaType::Type::QString:
557 lineColor =
parseColor( jsonLineColor.toString(), context );
561 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineColor.userType() ) ) ) );
568 lineColor = QColor( 0, 0, 0 );
574 if ( jsonPaint.contains( u
"line-width"_s ) )
576 const QVariant jsonLineWidth = jsonPaint.value( u
"line-width"_s );
577 switch ( jsonLineWidth.userType() )
579 case QMetaType::Type::Int:
580 case QMetaType::Type::LongLong:
581 case QMetaType::Type::Double:
585 case QMetaType::Type::QVariantMap:
597 case QMetaType::Type::QVariantList:
598 case QMetaType::Type::QStringList:
610 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported fill-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineWidth.userType() ) ) ) );
615 double lineOffset = 0.0;
616 if ( jsonPaint.contains( u
"line-offset"_s ) )
618 const QVariant jsonLineOffset = jsonPaint.value( u
"line-offset"_s );
619 switch ( jsonLineOffset.userType() )
621 case QMetaType::Type::Int:
622 case QMetaType::Type::LongLong:
623 case QMetaType::Type::Double:
627 case QMetaType::Type::QVariantMap:
632 case QMetaType::Type::QVariantList:
633 case QMetaType::Type::QStringList:
638 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineOffset.userType() ) ) ) );
643 double lineOpacity = -1.0;
645 if ( jsonPaint.contains( u
"line-opacity"_s ) )
647 const QVariant jsonLineOpacity = jsonPaint.value( u
"line-opacity"_s );
648 switch ( jsonLineOpacity.userType() )
650 case QMetaType::Type::Int:
651 case QMetaType::Type::LongLong:
652 case QMetaType::Type::Double:
653 lineOpacity = jsonLineOpacity.toDouble();
656 case QMetaType::Type::QVariantMap:
659 double defaultValue = 1.0;
668 case QMetaType::Type::QVariantList:
669 case QMetaType::Type::QStringList:
672 double defaultValue = 1.0;
683 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported line-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineOpacity.userType() ) ) ) );
688 QVector< double > dashVector;
689 if ( jsonPaint.contains( u
"line-dasharray"_s ) )
691 const QVariant jsonLineDashArray = jsonPaint.value( u
"line-dasharray"_s );
692 switch ( jsonLineDashArray.userType() )
694 case QMetaType::Type::QVariantMap:
696 QString arrayExpression;
699 arrayExpression = u
"array_to_string(array_foreach(%1,@element * (%2)), ';')"_s
704 arrayExpression = u
"array_to_string(%1, ';')"_s.arg(
parseArrayStops( jsonLineDashArray.toMap().value( u
"stops"_s ).toList(), context, lineWidth ) );
708 const QVariantList dashSource = jsonLineDashArray.toMap().value( u
"stops"_s ).toList().first().toList().value( 1 ).toList();
709 for (
const QVariant &v : dashSource )
711 dashVector << v.toDouble() * lineWidth;
716 case QMetaType::Type::QVariantList:
717 case QMetaType::Type::QStringList:
719 const QVariantList dashSource = jsonLineDashArray.toList();
721 if ( !dashSource.empty() )
723 if ( dashSource.at( 0 ).userType() == QMetaType::Type::QString )
729 u
"array_to_string(array_foreach(%1,@element * (%2)), ';')"_s
730 .arg( property.asExpression(), lineWidthProperty.
asExpression() )
741 QVector< double > rawDashVectorSizes;
742 rawDashVectorSizes.reserve( dashSource.size() );
743 for (
const QVariant &v : dashSource )
745 rawDashVectorSizes << v.toDouble();
749 if ( rawDashVectorSizes.size() == 1 )
752 rawDashVectorSizes.clear();
754 else if ( rawDashVectorSizes.size() % 2 == 1 )
758 rawDashVectorSizes.append( 0 );
761 if ( !rawDashVectorSizes.isEmpty() && ( !lineWidthProperty.
asExpression().isEmpty() ) )
763 QStringList dashArrayStringParts;
764 dashArrayStringParts.reserve( rawDashVectorSizes.size() );
765 for (
double v : std::as_const( rawDashVectorSizes ) )
770 QString arrayExpression = u
"array_to_string(array_foreach(array(%1),@element * (%2)), ';')"_s
771 .arg( dashArrayStringParts.join(
',' ), lineWidthProperty.
asExpression() );
776 for (
double v : std::as_const( rawDashVectorSizes ) )
778 dashVector << v * lineWidth;
787 QObject::tr(
"%1: Skipping unsupported line-dasharray type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonLineDashArray.userType() ) ) )
793 Qt::PenCapStyle penCapStyle = Qt::FlatCap;
794 Qt::PenJoinStyle penJoinStyle = Qt::MiterJoin;
795 if ( jsonLayer.contains( u
"layout"_s ) )
797 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
798 if ( jsonLayout.contains( u
"line-cap"_s ) )
800 penCapStyle =
parseCapStyle( jsonLayout.value( u
"line-cap"_s ).toString() );
802 if ( jsonLayout.contains( u
"line-join"_s ) )
804 penJoinStyle =
parseJoinStyle( jsonLayout.value( u
"line-join"_s ).toString() );
808 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsLineSymbol >() );
809 symbol->setOutputUnit( context.
targetUnit() );
811 if ( !rasterLineSprite.isEmpty() )
821 if ( lineOpacity != -1 )
823 symbol->setOpacity( lineOpacity );
829 symbol->setDataDefinedProperties( ddProperties );
831 if ( lineWidth != -1 )
835 symbol->changeSymbolLayer( 0, lineSymbol );
840 Q_ASSERT( lineSymbol );
850 if ( lineOpacity != -1 )
852 symbol->setOpacity( lineOpacity );
858 symbol->setDataDefinedProperties( ddProperties );
860 if ( lineColor.isValid() )
864 if ( lineWidth != -1 )
868 if ( !dashVector.empty() )
882 if ( !jsonLayer.contains( u
"paint"_s ) )
884 context.
pushWarning( QObject::tr(
"%1: Style has no paint property, skipping" ).arg( context.
layerId() ) );
888 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
893 QColor circleFillColor;
894 if ( jsonPaint.contains( u
"circle-color"_s ) )
896 const QVariant jsonCircleColor = jsonPaint.value( u
"circle-color"_s );
897 switch ( jsonCircleColor.userType() )
899 case QMetaType::Type::QVariantMap:
903 case QMetaType::Type::QVariantList:
904 case QMetaType::Type::QStringList:
908 case QMetaType::Type::QString:
909 circleFillColor =
parseColor( jsonCircleColor.toString(), context );
913 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported circle-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleColor.userType() ) ) ) );
920 circleFillColor = QColor( 0, 0, 0 );
924 double circleDiameter = 10.0;
925 if ( jsonPaint.contains( u
"circle-radius"_s ) )
927 const QVariant jsonCircleRadius = jsonPaint.value( u
"circle-radius"_s );
928 switch ( jsonCircleRadius.userType() )
930 case QMetaType::Type::Int:
931 case QMetaType::Type::LongLong:
932 case QMetaType::Type::Double:
936 case QMetaType::Type::QVariantMap:
941 case QMetaType::Type::QVariantList:
942 case QMetaType::Type::QStringList:
948 QObject::tr(
"%1: Skipping unsupported circle-radius type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleRadius.userType() ) ) )
954 double circleOpacity = -1.0;
955 if ( jsonPaint.contains( u
"circle-opacity"_s ) )
957 const QVariant jsonCircleOpacity = jsonPaint.value( u
"circle-opacity"_s );
958 switch ( jsonCircleOpacity.userType() )
960 case QMetaType::Type::Int:
961 case QMetaType::Type::LongLong:
962 case QMetaType::Type::Double:
963 circleOpacity = jsonCircleOpacity.toDouble();
966 case QMetaType::Type::QVariantMap:
970 case QMetaType::Type::QVariantList:
971 case QMetaType::Type::QStringList:
977 QObject::tr(
"%1: Skipping unsupported circle-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleOpacity.userType() ) ) )
982 if ( ( circleOpacity != -1 ) && circleFillColor.isValid() )
984 circleFillColor.setAlphaF( circleOpacity );
988 QColor circleStrokeColor;
989 if ( jsonPaint.contains( u
"circle-stroke-color"_s ) )
991 const QVariant jsonCircleStrokeColor = jsonPaint.value( u
"circle-stroke-color"_s );
992 switch ( jsonCircleStrokeColor.userType() )
994 case QMetaType::Type::QVariantMap:
998 case QMetaType::Type::QVariantList:
999 case QMetaType::Type::QStringList:
1003 case QMetaType::Type::QString:
1004 circleStrokeColor =
parseColor( jsonCircleStrokeColor.toString(), context );
1009 QObject::tr(
"%1: Skipping unsupported circle-stroke-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleStrokeColor.userType() ) ) )
1016 double circleStrokeWidth = -1.0;
1017 if ( jsonPaint.contains( u
"circle-stroke-width"_s ) )
1019 const QVariant circleStrokeWidthJson = jsonPaint.value( u
"circle-stroke-width"_s );
1020 switch ( circleStrokeWidthJson.userType() )
1022 case QMetaType::Type::Int:
1023 case QMetaType::Type::LongLong:
1024 case QMetaType::Type::Double:
1028 case QMetaType::Type::QVariantMap:
1029 circleStrokeWidth = -1.0;
1033 case QMetaType::Type::QVariantList:
1034 case QMetaType::Type::QStringList:
1040 QObject::tr(
"%1: Skipping unsupported circle-stroke-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( circleStrokeWidthJson.userType() ) ) )
1046 double circleStrokeOpacity = -1.0;
1047 if ( jsonPaint.contains( u
"circle-stroke-opacity"_s ) )
1049 const QVariant jsonCircleStrokeOpacity = jsonPaint.value( u
"circle-stroke-opacity"_s );
1050 switch ( jsonCircleStrokeOpacity.userType() )
1052 case QMetaType::Type::Int:
1053 case QMetaType::Type::LongLong:
1054 case QMetaType::Type::Double:
1055 circleStrokeOpacity = jsonCircleStrokeOpacity.toDouble();
1058 case QMetaType::Type::QVariantMap:
1062 case QMetaType::Type::QVariantList:
1063 case QMetaType::Type::QStringList:
1070 QObject::tr(
"%1: Skipping unsupported circle-stroke-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleStrokeOpacity.userType() ) ) )
1075 if ( ( circleStrokeOpacity != -1 ) && circleStrokeColor.isValid() )
1077 circleStrokeColor.setAlphaF( circleStrokeOpacity );
1081 QPointF circleTranslate;
1082 if ( jsonPaint.contains( u
"circle-translate"_s ) )
1084 const QVariant jsonCircleTranslate = jsonPaint.value( u
"circle-translate"_s );
1085 switch ( jsonCircleTranslate.userType() )
1087 case QMetaType::Type::QVariantMap:
1091 case QMetaType::Type::QVariantList:
1092 case QMetaType::Type::QStringList:
1099 QObject::tr(
"%1: Skipping unsupported circle-translate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonCircleTranslate.userType() ) ) )
1105 std::unique_ptr< QgsSymbol > symbol( std::make_unique< QgsMarkerSymbol >() );
1107 Q_ASSERT( markerSymbolLayer );
1110 symbol->setOutputUnit( context.
targetUnit() );
1113 if ( !circleTranslate.isNull() )
1115 markerSymbolLayer->
setOffset( circleTranslate );
1119 if ( circleFillColor.isValid() )
1123 if ( circleDiameter != -1 )
1125 markerSymbolLayer->
setSize( circleDiameter );
1128 if ( circleStrokeColor.isValid() )
1132 if ( circleStrokeWidth != -1 )
1147 hasLabeling =
false;
1148 hasRenderer =
false;
1150 if ( !jsonLayer.contains( u
"layout"_s ) )
1152 context.
pushWarning( QObject::tr(
"%1: Style layer has no layout property, skipping" ).arg( context.
layerId() ) );
1155 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
1156 if ( !jsonLayout.contains( u
"text-field"_s ) )
1162 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
1168 if ( jsonLayout.contains( u
"text-size"_s ) )
1170 const QVariant jsonTextSize = jsonLayout.value( u
"text-size"_s );
1171 switch ( jsonTextSize.userType() )
1173 case QMetaType::Type::Int:
1174 case QMetaType::Type::LongLong:
1175 case QMetaType::Type::Double:
1179 case QMetaType::Type::QVariantMap:
1185 case QMetaType::Type::QVariantList:
1186 case QMetaType::Type::QStringList:
1192 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextSize.userType() ) ) ) );
1196 if ( textSizeProperty )
1203 constexpr double EM_TO_CHARS = 2.0;
1205 double textMaxWidth = -1;
1206 if ( jsonLayout.contains( u
"text-max-width"_s ) )
1208 const QVariant jsonTextMaxWidth = jsonLayout.value( u
"text-max-width"_s );
1209 switch ( jsonTextMaxWidth.userType() )
1211 case QMetaType::Type::Int:
1212 case QMetaType::Type::LongLong:
1213 case QMetaType::Type::Double:
1214 textMaxWidth = jsonTextMaxWidth.toDouble() * EM_TO_CHARS;
1217 case QMetaType::Type::QVariantMap:
1221 case QMetaType::Type::QVariantList:
1222 case QMetaType::Type::QStringList:
1228 QObject::tr(
"%1: Skipping unsupported text-max-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextMaxWidth.userType() ) ) )
1236 textMaxWidth = 10 * EM_TO_CHARS;
1239 double textLetterSpacing = -1;
1240 if ( jsonLayout.contains( u
"text-letter-spacing"_s ) )
1242 const QVariant jsonTextLetterSpacing = jsonLayout.value( u
"text-letter-spacing"_s );
1243 switch ( jsonTextLetterSpacing.userType() )
1245 case QMetaType::Type::Int:
1246 case QMetaType::Type::LongLong:
1247 case QMetaType::Type::Double:
1248 textLetterSpacing = jsonTextLetterSpacing.toDouble();
1251 case QMetaType::Type::QVariantMap:
1255 case QMetaType::Type::QVariantList:
1256 case QMetaType::Type::QStringList:
1262 QObject::tr(
"%1: Skipping unsupported text-letter-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextLetterSpacing.userType() ) ) )
1269 bool foundFont =
false;
1271 QString fontStyleName;
1273 bool allowOverlap = jsonLayout.contains( u
"text-allow-overlap"_s ) && jsonLayout.
value( u
"text-allow-overlap"_s ).toBool();
1275 if ( jsonLayout.contains( u
"text-font"_s ) )
1277 auto splitFontFamily = [](
const QString &fontName, QString &family, QString &style ) ->
bool {
1278 QString matchedFamily;
1279 const QStringList textFontParts = fontName.split(
' ' );
1280 for (
int i = textFontParts.size() - 1; i >= 1; --i )
1282 const QString candidateFontFamily = textFontParts.mid( 0, i ).join(
' ' );
1283 const QString candidateFontStyle = textFontParts.mid( i ).join(
' ' );
1288 family = processedFontFamily;
1289 style = candidateFontStyle;
1294 if ( processedFontFamily == matchedFamily )
1296 family = processedFontFamily;
1297 style = candidateFontStyle;
1301 family = matchedFamily;
1302 style = processedFontFamily;
1303 style.replace( matchedFamily, QString() );
1304 style = style.trimmed();
1305 if ( !style.isEmpty() && !candidateFontStyle.isEmpty() )
1307 style += u
" %1"_s.arg( candidateFontStyle );
1315 if ( QFontDatabase().hasFamily( processedFontFamily ) )
1318 family = processedFontFamily;
1324 family = matchedFamily;
1331 const QVariant jsonTextFont = jsonLayout.value( u
"text-font"_s );
1332 if ( jsonTextFont.userType() != QMetaType::Type::QVariantList
1333 && jsonTextFont.userType() != QMetaType::Type::QStringList
1334 && jsonTextFont.userType() != QMetaType::Type::QString
1335 && jsonTextFont.userType() != QMetaType::Type::QVariantMap )
1337 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-font type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextFont.userType() ) ) ) );
1341 switch ( jsonTextFont.userType() )
1343 case QMetaType::Type::QVariantList:
1344 case QMetaType::Type::QStringList:
1345 fontName = jsonTextFont.toList().value( 0 ).toString();
1348 case QMetaType::Type::QString:
1349 fontName = jsonTextFont.toString();
1352 case QMetaType::Type::QVariantMap:
1354 QString familyCaseString = u
"CASE "_s;
1355 QString styleCaseString = u
"CASE "_s;
1357 const QVariantList stops = jsonTextFont.toMap().value( u
"stops"_s ).toList();
1360 for (
int i = 0; i < stops.length() - 1; ++i )
1363 const QVariant bz = stops.value( i ).toList().value( 0 );
1364 const QString bv = stops.value( i ).toList().value( 1 ).userType() == QMetaType::Type::QString ? stops.value( i ).toList().value( 1 ).toString()
1365 : stops.value( i ).toList().value( 1 ).toList().value( 0 ).toString();
1366 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
1368 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
1374 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
1375 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
1377 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
1382 if ( splitFontFamily( bv, fontFamily, fontStyleName ) )
1384 familyCaseString += QStringLiteral(
1385 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
1389 styleCaseString += QStringLiteral(
1390 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
1397 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), bv ) );
1403 const QString bv = stops.constLast().toList().value( 1 ).userType() == QMetaType::Type::QString ? stops.constLast().toList().value( 1 ).toString()
1404 : stops.constLast().toList().value( 1 ).toList().value( 0 ).toString();
1405 if ( splitFontFamily( bv, fontFamily, fontStyleName ) )
1412 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), bv ) );
1419 fontName = fontFamily;
1429 if ( splitFontFamily( fontName, fontFamily, fontStyleName ) )
1432 if ( !fontStyleName.isEmpty() )
1433 textFont.setStyleName( fontStyleName );
1443 fontName = u
"Open Sans"_s;
1445 textFont.setStyleName( u
"Regular"_s );
1446 fontStyleName = u
"Regular"_s;
1451 fontName = u
"Arial Unicode MS"_s;
1453 textFont.setStyleName( u
"Regular"_s );
1454 fontStyleName = u
"Regular"_s;
1459 fontName = u
"Open Sans, Arial Unicode MS"_s;
1462 if ( !foundFont && !fontName.isEmpty() )
1464 context.
pushWarning( QObject::tr(
"%1: Referenced font %2 is not available on system" ).arg( context.
layerId(), fontName ) );
1469 if ( jsonPaint.contains( u
"text-color"_s ) )
1471 const QVariant jsonTextColor = jsonPaint.value( u
"text-color"_s );
1472 switch ( jsonTextColor.userType() )
1474 case QMetaType::Type::QVariantMap:
1478 case QMetaType::Type::QVariantList:
1479 case QMetaType::Type::QStringList:
1483 case QMetaType::Type::QString:
1484 textColor =
parseColor( jsonTextColor.toString(), context );
1488 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextColor.userType() ) ) ) );
1495 textColor = QColor( 0, 0, 0 );
1499 QColor bufferColor( 0, 0, 0, 0 );
1500 if ( jsonPaint.contains( u
"text-halo-color"_s ) )
1502 const QVariant jsonBufferColor = jsonPaint.value( u
"text-halo-color"_s );
1503 switch ( jsonBufferColor.userType() )
1505 case QMetaType::Type::QVariantMap:
1509 case QMetaType::Type::QVariantList:
1510 case QMetaType::Type::QStringList:
1514 case QMetaType::Type::QString:
1515 bufferColor =
parseColor( jsonBufferColor.toString(), context );
1520 QObject::tr(
"%1: Skipping unsupported text-halo-color type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonBufferColor.userType() ) ) )
1526 double bufferSize = 0.0;
1530 constexpr double BUFFER_SIZE_SCALE = 2.0;
1531 if ( jsonPaint.contains( u
"text-halo-width"_s ) )
1533 const QVariant jsonHaloWidth = jsonPaint.value( u
"text-halo-width"_s );
1534 QString bufferSizeDataDefined;
1535 switch ( jsonHaloWidth.userType() )
1537 case QMetaType::Type::Int:
1538 case QMetaType::Type::LongLong:
1539 case QMetaType::Type::Double:
1543 case QMetaType::Type::QVariantMap:
1548 case QMetaType::Type::QVariantList:
1549 case QMetaType::Type::QStringList:
1555 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-halo-width type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonHaloWidth.userType() ) ) ) );
1561 if ( bufferSize > 0 )
1563 if ( textSize > 0 && bufferSizeDataDefined.isEmpty() )
1565 bufferSize = std::min( bufferSize, textSize * BUFFER_SIZE_SCALE / 4 );
1567 else if ( textSize > 0 && !bufferSizeDataDefined.isEmpty() )
1569 bufferSizeDataDefined = u
"min(%1/4, %2)"_s.arg( textSize * BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined );
1572 else if ( !bufferSizeDataDefined.isEmpty() )
1574 bufferSizeDataDefined = u
"min(%1*%2/4, %3)"_s.arg( textSizeProperty.
asExpression() ).arg( BUFFER_SIZE_SCALE ).arg( bufferSizeDataDefined );
1577 else if ( bufferSizeDataDefined.isEmpty() )
1579 bufferSizeDataDefined = u
"min(%1*%2/4, %3)"_s.arg( textSizeProperty.
asExpression() ).arg( BUFFER_SIZE_SCALE ).arg( bufferSize );
1585 double haloBlurSize = 0;
1586 if ( jsonPaint.contains( u
"text-halo-blur"_s ) )
1588 const QVariant jsonTextHaloBlur = jsonPaint.value( u
"text-halo-blur"_s );
1589 switch ( jsonTextHaloBlur.userType() )
1591 case QMetaType::Type::Int:
1592 case QMetaType::Type::LongLong:
1593 case QMetaType::Type::Double:
1601 QObject::tr(
"%1: Skipping unsupported text-halo-blur type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextHaloBlur.userType() ) ) )
1609 if ( textColor.isValid() )
1611 if ( textSize >= 0 )
1616 if ( !fontStyleName.isEmpty() )
1619 if ( textLetterSpacing > 0 )
1621 QFont f = format.
font();
1622 f.setLetterSpacing( QFont::AbsoluteSpacing, textLetterSpacing );
1626 if ( bufferSize > 0 )
1629 const double opacity = bufferColor.alphaF();
1630 bufferColor.setAlphaF( 1.0 );
1638 if ( haloBlurSize > 0 )
1661 if ( textMaxWidth > 0 )
1667 if ( jsonLayout.contains( u
"text-field"_s ) )
1669 const QVariant jsonTextField = jsonLayout.value( u
"text-field"_s );
1670 switch ( jsonTextField.userType() )
1672 case QMetaType::Type::QString:
1674 labelSettings.
fieldName = processLabelField( jsonTextField.toString(), labelSettings.
isExpression );
1678 case QMetaType::Type::QVariantList:
1679 case QMetaType::Type::QStringList:
1681 const QVariantList textFieldList = jsonTextField.toList();
1689 if ( textFieldList.size() > 2 && textFieldList.at( 0 ).toString() ==
"format"_L1 )
1692 for (
int i = 1; i < textFieldList.size(); ++i )
1694 bool isExpression =
false;
1695 const QString part = processLabelField( textFieldList.at( i ).toString(), isExpression );
1696 if ( !isExpression )
1703 labelSettings.
fieldName = u
"concat(%1)"_s.arg( parts.join(
',' ) );
1718 case QMetaType::Type::QVariantMap:
1720 const QVariantList stops = jsonTextField.toMap().value( u
"stops"_s ).toList();
1721 if ( !stops.empty() )
1728 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-field dictionary" ).arg( context.
layerId() ) );
1734 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-field type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextField.userType() ) ) ) );
1739 if ( jsonLayout.contains( u
"text-rotate"_s ) )
1741 const QVariant jsonTextRotate = jsonLayout.value( u
"text-rotate"_s );
1742 switch ( jsonTextRotate.userType() )
1744 case QMetaType::Type::Double:
1745 case QMetaType::Type::Int:
1747 labelSettings.
angleOffset = jsonTextRotate.toDouble();
1751 case QMetaType::Type::QVariantList:
1752 case QMetaType::Type::QStringList:
1759 case QMetaType::Type::QVariantMap:
1761 QVariantMap rotateMap = jsonTextRotate.toMap();
1762 if ( rotateMap.contains( u
"property"_s ) && rotateMap[u
"type"_s].toString() ==
"identity"_L1 )
1768 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-rotate map content (%2)" ).arg( context.
layerId(), QString( QJsonDocument::fromVariant( rotateMap ).toJson() ) ) );
1773 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextRotate.userType() ) ) ) );
1778 if ( jsonLayout.contains( u
"text-transform"_s ) )
1780 const QString textTransform = jsonLayout.value( u
"text-transform"_s ).toString();
1781 if ( textTransform ==
"uppercase"_L1 )
1785 else if ( textTransform ==
"lowercase"_L1 )
1794 if ( jsonLayout.contains( u
"symbol-placement"_s ) )
1796 const QString symbolPlacement = jsonLayout.value( u
"symbol-placement"_s ).toString();
1797 if ( symbolPlacement ==
"line"_L1 )
1803 if ( jsonLayout.contains( u
"text-rotation-alignment"_s ) )
1805 const QString textRotationAlignment = jsonLayout.value( u
"text-rotation-alignment"_s ).toString();
1806 if ( textRotationAlignment ==
"viewport"_L1 )
1816 if ( jsonLayout.contains( u
"text-offset"_s ) )
1818 const QVariant jsonTextOffset = jsonLayout.value( u
"text-offset"_s );
1821 switch ( jsonTextOffset.userType() )
1823 case QMetaType::Type::QVariantMap:
1824 textOffsetProperty =
parseInterpolatePointByZoom( jsonTextOffset.toMap(), context, !textSizeProperty ? textSize : 1.0, &textOffset );
1825 if ( !textSizeProperty )
1833 u
"with_variable('text_size',%2,abs(array_get(%1,1))*@text_size-@text_size)"_s.arg( textOffsetProperty.
asExpression(), textSizeProperty.
asExpression() )
1839 case QMetaType::Type::QVariantList:
1840 case QMetaType::Type::QStringList:
1841 textOffset = QPointF( jsonTextOffset.toList().value( 0 ).toDouble() * textSize, jsonTextOffset.toList().value( 1 ).toDouble() * textSize );
1846 QObject::tr(
"%1: Skipping unsupported text-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextOffset.userType() ) ) )
1851 if ( !textOffset.isNull() )
1854 labelSettings.
dist = std::abs( textOffset.y() ) - textSize;
1856 if ( textSizeProperty && !textOffsetProperty )
1860 u
"with_variable('text_size',%2,%1*@text_size-@text_size)"_s.arg( std::abs( textOffset.y() / textSize ) ).arg( textSizeProperty.
asExpression() )
1866 if ( textOffset.isNull() )
1874 if ( jsonLayout.contains( u
"text-justify"_s ) )
1876 const QVariant jsonTextJustify = jsonLayout.value( u
"text-justify"_s );
1879 QString textAlign = u
"center"_s;
1881 const QVariantMap conversionMap { { u
"left"_s, u
"left"_s }, { u
"center"_s, u
"center"_s }, { u
"right"_s, u
"right"_s }, { u
"auto"_s, u
"follow"_s } };
1883 switch ( jsonTextJustify.userType() )
1885 case QMetaType::Type::QString:
1886 textAlign = jsonTextJustify.toString();
1889 case QMetaType::Type::QVariantList:
1893 case QMetaType::Type::QVariantMap:
1898 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-justify type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextJustify.userType() ) ) ) );
1902 if ( textAlign ==
"left"_L1 )
1904 else if ( textAlign ==
"right"_L1 )
1906 else if ( textAlign ==
"center"_L1 )
1908 else if ( textAlign ==
"follow"_L1 )
1918 if ( jsonLayout.contains( u
"text-anchor"_s ) )
1920 const QVariant jsonTextAnchor = jsonLayout.value( u
"text-anchor"_s );
1923 const QVariantMap conversionMap {
1929 { u
"top-left"_s, 8 },
1930 { u
"top-right"_s, 6 },
1931 { u
"bottom-left"_s, 2 },
1932 { u
"bottom-right"_s, 0 },
1935 switch ( jsonTextAnchor.userType() )
1937 case QMetaType::Type::QString:
1938 textAnchor = jsonTextAnchor.toString();
1941 case QMetaType::Type::QVariantList:
1945 case QMetaType::Type::QVariantMap:
1950 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-anchor type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextAnchor.userType() ) ) ) );
1954 if ( textAnchor ==
"center"_L1 )
1956 else if ( textAnchor ==
"left"_L1 )
1958 else if ( textAnchor ==
"right"_L1 )
1960 else if ( textAnchor ==
"top"_L1 )
1962 else if ( textAnchor ==
"bottom"_L1 )
1964 else if ( textAnchor ==
"top-left"_L1 )
1966 else if ( textAnchor ==
"top-right"_L1 )
1968 else if ( textAnchor ==
"bottom-left"_L1 )
1970 else if ( textAnchor ==
"bottom-right"_L1 )
1975 if ( jsonLayout.contains( u
"text-offset"_s ) )
1977 const QVariant jsonTextOffset = jsonLayout.value( u
"text-offset"_s );
1980 switch ( jsonTextOffset.userType() )
1982 case QMetaType::Type::QVariantMap:
1986 case QMetaType::Type::QVariantList:
1987 case QMetaType::Type::QStringList:
1988 textOffset = QPointF( jsonTextOffset.toList().value( 0 ).toDouble() * textSize, jsonTextOffset.toList().value( 1 ).toDouble() * textSize );
1992 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported text-offset type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonTextOffset.userType() ) ) ) );
1996 if ( !textOffset.isNull() )
1999 labelSettings.
xOffset = textOffset.x();
2000 labelSettings.
yOffset = textOffset.y();
2008 QString spriteProperty, spriteSizeProperty;
2010 if ( !sprite.isEmpty() )
2013 if ( jsonLayout.contains( u
"icon-size"_s ) )
2016 const QVariant jsonIconSize = jsonLayout.
value( u
"icon-size"_s );
2017 switch ( jsonIconSize.userType() )
2019 case QMetaType::Type::Int:
2020 case QMetaType::Type::LongLong:
2021 case QMetaType::Type::Double:
2023 size = jsonIconSize.toDouble();
2024 if ( !spriteSizeProperty.isEmpty() )
2031 case QMetaType::Type::QVariantMap:
2035 case QMetaType::Type::QVariantList:
2036 case QMetaType::Type::QStringList:
2041 QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) )
2048 if ( !spriteSizeProperty.isEmpty() )
2061 markerLayer->
setPath( sprite );
2062 markerLayer->
setSize( spriteSize.width() );
2065 if ( !spriteProperty.isEmpty() )
2075 backgroundSettings.
setSize( spriteSize * size );
2085 if ( jsonLayout.contains( u
"symbol-spacing"_s ) )
2088 const QVariant jsonSpacing = jsonLayout.value( u
"symbol-spacing"_s );
2098 switch ( jsonSpacing.userType() )
2100 case QMetaType::Type::Int:
2101 case QMetaType::Type::LongLong:
2102 case QMetaType::Type::Double:
2109 case QMetaType::Type::QVariantMap:
2115 case QMetaType::Type::QVariantList:
2116 case QMetaType::Type::QStringList:
2123 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported symbol-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonSpacing.userType() ) ) ) );
2132 if ( textSize >= 0 )
2155 if ( !jsonLayer.contains( u
"layout"_s ) )
2157 context.
pushWarning( QObject::tr(
"%1: Style layer has no layout property, skipping" ).arg( context.
layerId() ) );
2160 const QVariantMap jsonLayout = jsonLayer.value( u
"layout"_s ).toMap();
2162 if ( jsonLayout.value( u
"symbol-placement"_s ).toString() ==
"line"_L1 && !jsonLayout.contains( u
"text-field"_s ) )
2166 double spacing = -1.0;
2167 if ( jsonLayout.contains( u
"symbol-spacing"_s ) )
2169 const QVariant jsonSpacing = jsonLayout.value( u
"symbol-spacing"_s );
2170 switch ( jsonSpacing.userType() )
2172 case QMetaType::Type::Int:
2173 case QMetaType::Type::LongLong:
2174 case QMetaType::Type::Double:
2178 case QMetaType::Type::QVariantMap:
2182 case QMetaType::Type::QVariantList:
2183 case QMetaType::Type::QStringList:
2188 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported symbol-spacing type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonSpacing.userType() ) ) ) );
2198 bool rotateMarkers =
true;
2199 if ( jsonLayout.contains( u
"icon-rotation-alignment"_s ) )
2201 const QString alignment = jsonLayout.value( u
"icon-rotation-alignment"_s ).toString();
2202 if ( alignment ==
"map"_L1 || alignment ==
"auto"_L1 )
2204 rotateMarkers =
true;
2206 else if ( alignment ==
"viewport"_L1 )
2208 rotateMarkers =
false;
2213 double rotation = 0.0;
2214 if ( jsonLayout.contains( u
"icon-rotate"_s ) )
2216 const QVariant jsonIconRotate = jsonLayout.value( u
"icon-rotate"_s );
2217 switch ( jsonIconRotate.userType() )
2219 case QMetaType::Type::Int:
2220 case QMetaType::Type::LongLong:
2221 case QMetaType::Type::Double:
2222 rotation = jsonIconRotate.toDouble();
2225 case QMetaType::Type::QVariantMap:
2229 case QMetaType::Type::QVariantList:
2230 case QMetaType::Type::QStringList:
2235 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported icon-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconRotate.userType() ) ) ) );
2251 QString spriteProperty, spriteSizeProperty;
2253 if ( !sprite.isNull() )
2255 markerLayer->
setPath( sprite );
2256 markerLayer->
setSize( spriteSize.width() );
2259 if ( !spriteProperty.isEmpty() )
2266 if ( jsonLayout.contains( u
"icon-size"_s ) )
2268 const QVariant jsonIconSize = jsonLayout.value( u
"icon-size"_s );
2271 switch ( jsonIconSize.userType() )
2273 case QMetaType::Type::Int:
2274 case QMetaType::Type::LongLong:
2275 case QMetaType::Type::Double:
2277 size = jsonIconSize.toDouble();
2278 if ( !spriteSizeProperty.isEmpty() )
2285 case QMetaType::Type::QVariantMap:
2289 case QMetaType::Type::QVariantList:
2290 case QMetaType::Type::QStringList:
2294 context.
pushWarning( QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) ) );
2297 markerLayer->
setSize( size * spriteSize.width() );
2300 if ( !spriteSizeProperty.isEmpty() )
2316 std::unique_ptr< QgsSymbol > symbol = std::make_unique< QgsLineSymbol >(
QgsSymbolLayerList() << lineSymbol );
2319 symbol->setOutputUnit( context.
targetUnit() );
2323 rendererStyle.
setSymbol( symbol.release() );
2326 else if ( jsonLayout.contains( u
"icon-image"_s ) )
2328 const QVariantMap jsonPaint = jsonLayer.value( u
"paint"_s ).toMap();
2331 QString spriteProperty, spriteSizeProperty;
2333 if ( !sprite.isEmpty() || !spriteProperty.isEmpty() )
2336 rasterMarker->
setPath( sprite );
2337 rasterMarker->
setSize( spriteSize.width() );
2341 if ( !spriteProperty.isEmpty() )
2347 if ( jsonLayout.contains( u
"icon-size"_s ) )
2349 const QVariant jsonIconSize = jsonLayout.value( u
"icon-size"_s );
2352 switch ( jsonIconSize.userType() )
2354 case QMetaType::Type::Int:
2355 case QMetaType::Type::LongLong:
2356 case QMetaType::Type::Double:
2358 size = jsonIconSize.toDouble();
2359 if ( !spriteSizeProperty.isEmpty() )
2366 case QMetaType::Type::QVariantMap:
2370 case QMetaType::Type::QVariantList:
2371 case QMetaType::Type::QStringList:
2376 QObject::tr(
"%1: Skipping non-implemented icon-size type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconSize.userType() ) ) )
2380 rasterMarker->
setSize( size * spriteSize.width() );
2383 if ( !spriteSizeProperty.isEmpty() )
2395 double rotation = 0.0;
2396 if ( jsonLayout.contains( u
"icon-rotate"_s ) )
2398 const QVariant jsonIconRotate = jsonLayout.value( u
"icon-rotate"_s );
2399 switch ( jsonIconRotate.userType() )
2401 case QMetaType::Type::Int:
2402 case QMetaType::Type::LongLong:
2403 case QMetaType::Type::Double:
2404 rotation = jsonIconRotate.toDouble();
2407 case QMetaType::Type::QVariantMap:
2411 case QMetaType::Type::QVariantList:
2412 case QMetaType::Type::QStringList:
2418 QObject::tr(
"%1: Skipping unsupported icon-rotate type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconRotate.userType() ) ) )
2424 double iconOpacity = -1.0;
2425 if ( jsonPaint.contains( u
"icon-opacity"_s ) )
2427 const QVariant jsonIconOpacity = jsonPaint.value( u
"icon-opacity"_s );
2428 switch ( jsonIconOpacity.userType() )
2430 case QMetaType::Type::Int:
2431 case QMetaType::Type::LongLong:
2432 case QMetaType::Type::Double:
2433 iconOpacity = jsonIconOpacity.toDouble();
2436 case QMetaType::Type::QVariantMap:
2440 case QMetaType::Type::QVariantList:
2441 case QMetaType::Type::QStringList:
2447 QObject::tr(
"%1: Skipping unsupported icon-opacity type (%2)" ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( jsonIconOpacity.userType() ) ) )
2454 rasterMarker->
setAngle( rotation );
2455 if ( iconOpacity >= 0 )
2459 rendererStyle.
setSymbol( markerSymbol );
2470 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2471 const QVariantList stops = json.value( u
"stops"_s ).toList();
2472 if ( stops.empty() )
2475 QString caseString = u
"CASE "_s;
2476 const QString colorComponent(
"color_part(%1,'%2')" );
2478 for (
int i = 0; i < stops.length() - 1; ++i )
2481 const QString bz = stops.at( i ).toList().value( 0 ).toString();
2483 const QString tz = stops.at( i + 1 ).toList().value( 0 ).toString();
2485 const QVariant bcVariant = stops.at( i ).toList().value( 1 );
2486 const QVariant tcVariant = stops.at( i + 1 ).toList().value( 1 );
2488 const QColor bottomColor =
parseColor( bcVariant.toString(), context );
2489 const QColor topColor =
parseColor( tcVariant.toString(), context );
2491 if ( i == 0 && bottomColor.isValid() )
2498 caseString += u
"WHEN @vector_tile_zoom < %1 THEN color_hsla(%2, %3, %4, %5) "_s.arg( bz ).arg( bcHue ).arg( bcSat ).arg( bcLight ).arg( bcAlpha );
2501 if ( bottomColor.isValid() && topColor.isValid() )
2513 caseString += QStringLiteral(
2514 "WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 THEN color_hsla("
2527 json.value( u
"x1"_s ).toDouble(),
2528 json.value( u
"y1"_s ).toDouble(),
2529 json.value( u
"x2"_s ).toDouble(),
2530 json.value( u
"y2"_s ).toDouble(),
2541 json.value( u
"x1"_s ).toDouble(),
2542 json.value( u
"y1"_s ).toDouble(),
2543 json.value( u
"x2"_s ).toDouble(),
2544 json.value( u
"y2"_s ).toDouble(),
2555 json.value( u
"x1"_s ).toDouble(),
2556 json.value( u
"y1"_s ).toDouble(),
2557 json.value( u
"x2"_s ).toDouble(),
2558 json.value( u
"y2"_s ).toDouble(),
2569 json.value( u
"x1"_s ).toDouble(),
2570 json.value( u
"y1"_s ).toDouble(),
2571 json.value( u
"x2"_s ).toDouble(),
2572 json.value( u
"y2"_s ).toDouble(),
2583 caseString += QStringLiteral(
2584 "WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 THEN color_hsla("
2593 colorComponent.arg( bottomColorExpr ).arg(
"hsl_hue" ),
2594 colorComponent.arg( topColorExpr ).arg(
"hsl_hue" ),
2597 json.value( u
"x1"_s ).toDouble(),
2598 json.value( u
"y1"_s ).toDouble(),
2599 json.value( u
"x2"_s ).toDouble(),
2600 json.value( u
"y2"_s ).toDouble(),
2607 colorComponent.arg( bottomColorExpr ).arg(
"hsl_saturation" ),
2608 colorComponent.arg( topColorExpr ).arg(
"hsl_saturation" ),
2611 json.value( u
"x1"_s ).toDouble(),
2612 json.value( u
"y1"_s ).toDouble(),
2613 json.value( u
"x2"_s ).toDouble(),
2614 json.value( u
"y2"_s ).toDouble(),
2621 colorComponent.arg( bottomColorExpr ).arg(
"lightness" ),
2622 colorComponent.arg( topColorExpr ).arg(
"lightness" ),
2625 json.value( u
"x1"_s ).toDouble(),
2626 json.value( u
"y1"_s ).toDouble(),
2627 json.value( u
"x2"_s ).toDouble(),
2628 json.value( u
"y2"_s ).toDouble(),
2635 colorComponent.arg( bottomColorExpr ).arg(
"alpha" ),
2636 colorComponent.arg( topColorExpr ).arg(
"alpha" ),
2639 json.value( u
"x1"_s ).toDouble(),
2640 json.value( u
"y1"_s ).toDouble(),
2641 json.value( u
"x2"_s ).toDouble(),
2642 json.value( u
"y2"_s ).toDouble(),
2651 const QString tz = stops.last().toList().value( 0 ).toString();
2652 const QVariant tcVariant = stops.last().toList().value( 1 );
2654 if ( tcVariant.userType() == QMetaType::Type::QString )
2657 if ( topColor.isValid() )
2664 caseString += QStringLiteral(
2665 "WHEN @vector_tile_zoom >= %1 THEN color_hsla(%2, %3, %4, %5) "
2666 "ELSE color_hsla(%2, %3, %4, %5) END"
2675 else if ( tcVariant.userType() == QMetaType::QVariantList )
2679 caseString += QStringLiteral(
2680 "WHEN @vector_tile_zoom >= %1 THEN color_hsla(%2, %3, %4, %5) "
2681 "ELSE color_hsla(%2, %3, %4, %5) END"
2684 .arg( colorComponent.arg( topColorExpr ).arg(
"hsl_hue" ) )
2685 .arg( colorComponent.arg( topColorExpr ).arg(
"hsl_saturation" ) )
2686 .arg( colorComponent.arg( topColorExpr ).arg(
"lightness" ) )
2687 .arg( colorComponent.arg( topColorExpr ).arg(
"alpha" ) );
2690 if ( !stops.empty() && defaultColor )
2691 *defaultColor =
parseColor( stops.value( 0 ).toList().value( 1 ).toString(), context );
2698 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2699 const QVariantList stops = json.value( u
"stops"_s ).toList();
2700 if ( stops.empty() )
2703 QString scaleExpression;
2704 if ( stops.size() <= 2 )
2707 stops.value( 0 ).toList().value( 0 ).toDouble(),
2708 stops.last().toList().value( 0 ).toDouble(),
2709 stops.value( 0 ).toList().value( 1 ),
2710 stops.last().toList().value( 1 ),
2713 json.value( u
"x1"_s ).toDouble(),
2714 json.value( u
"y1"_s ).toDouble(),
2715 json.value( u
"x2"_s ).toDouble(),
2716 json.value( u
"y2"_s ).toDouble(),
2724 =
parseStops( base, stops, multiplier, context, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2727 if ( !stops.empty() && defaultNumber )
2728 *defaultNumber = stops.value( 0 ).toList().value( 1 ).toDouble() * multiplier;
2738 context = *contextPtr;
2740 const double base = json.value( u
"base"_s, u
"1"_s ).toDouble();
2741 const QVariantList stops = json.value( u
"stops"_s ).toList();
2742 if ( stops.empty() )
2745 QString scaleExpression;
2746 if ( stops.length() <= 2 )
2748 const QVariant bv = stops.value( 0 ).toList().value( 1 );
2749 const QVariant tv = stops.last().toList().value( 1 );
2750 double bottom = 0.0;
2752 const bool numeric = numericArgumentsOnly( bv, tv, bottom, top );
2754 stops.value( 0 ).toList().value( 0 ).toDouble(),
2755 stops.last().toList().value( 0 ).toDouble(),
2756 numeric ? QString::number( bottom * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
2757 numeric ? QString::number( top * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
2760 json.value( u
"x1"_s ).toDouble(),
2761 json.value( u
"y1"_s ).toDouble(),
2762 json.value( u
"x2"_s ).toDouble(),
2763 json.value( u
"y2"_s ).toDouble(),
2771 =
parseOpacityStops( base, stops, maxOpacity, context, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2780 QString caseString = u
"CASE WHEN @vector_tile_zoom < %1 THEN set_color_part(@symbol_color, 'alpha', %2)"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() )
2781 .arg( stops.value( 0 ).toList().value( 1 ).toDouble() * maxOpacity );
2783 for (
int i = 0; i < stops.size() - 1; ++i )
2785 const QVariant bv = stops.value( i ).toList().value( 1 );
2786 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2787 double bottom = 0.0;
2789 const bool numeric = numericArgumentsOnly( bv, tv, bottom, top );
2791 caseString += QStringLiteral(
2792 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
2793 "THEN set_color_part(@symbol_color, 'alpha', %3)"
2796 stops.value( i ).toList().value( 0 ).toString(),
2797 stops.value( i + 1 ).toList().value( 0 ).toString(),
2799 stops.value( i ).toList().value( 0 ).toDouble(),
2800 stops.value( i + 1 ).toList().value( 0 ).toDouble(),
2801 numeric ? QString::number( bottom * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( bv, context ) ).arg( maxOpacity ),
2802 numeric ? QString::number( top * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( tv, context ) ).arg( maxOpacity ),
2816 bool numeric =
false;
2817 const QVariant vv = stops.last().toList().value( 1 );
2818 double dv = vv.toDouble( &numeric );
2820 caseString += QStringLiteral(
2821 " WHEN @vector_tile_zoom >= %1 "
2822 "THEN set_color_part(@symbol_color, 'alpha', %2) END"
2824 .arg( stops.last().toList().value( 0 ).toString(), numeric ? QString::number( dv * maxOpacity ) : QString(
"(%1) * %2" ).arg( parseValue( vv, context ) ).arg( maxOpacity ) );
2830 const double base = json.
value( u
"base"_s, u
"1"_s ).toDouble();
2831 const QVariantList stops = json.value( u
"stops"_s ).toList();
2832 if ( stops.empty() )
2835 QString scaleExpression;
2836 if ( stops.size() <= 2 )
2838 scaleExpression = u
"array(%1,%2)"_s.arg(
2840 stops.value( 0 ).toList().value( 0 ).toDouble(),
2841 stops.last().toList().value( 0 ).toDouble(),
2842 stops.value( 0 ).toList().value( 1 ).toList().value( 0 ),
2843 stops.last().toList().value( 1 ).toList().value( 0 ),
2846 json.value( u
"x1"_s ).toDouble(),
2847 json.value( u
"y1"_s ).toDouble(),
2848 json.value( u
"x2"_s ).toDouble(),
2849 json.value( u
"y2"_s ).toDouble(),
2854 stops.value( 0 ).toList().value( 0 ).toDouble(),
2855 stops.last().toList().value( 0 ).toDouble(),
2856 stops.value( 0 ).toList().value( 1 ).toList().value( 1 ),
2857 stops.last().toList().value( 1 ).toList().value( 1 ),
2860 json.value( u
"x1"_s ).toDouble(),
2861 json.value( u
"y1"_s ).toDouble(),
2862 json.value( u
"x2"_s ).toDouble(),
2863 json.value( u
"y2"_s ).toDouble(),
2872 =
parsePointStops( base, stops, context, multiplier, type, json.value( u
"x1"_s ).toDouble(), json.value( u
"y1"_s ).toDouble(), json.value( u
"x2"_s ).toDouble(), json.value( u
"y2"_s ).toDouble() );
2875 if ( !stops.empty() && defaultPoint )
2876 *defaultPoint = QPointF( stops.value( 0 ).toList().value( 1 ).toList().value( 0 ).toDouble() * multiplier, stops.value( 0 ).toList().value( 1 ).toList().value( 1 ).toDouble() * multiplier );
2883 const QVariantList stops = json.
value( u
"stops"_s ).toList();
2884 if ( stops.empty() )
2887 const QString scaleExpression =
parseStringStops( stops, context, conversionMap, defaultString );
2896 QString caseString = u
"CASE "_s;
2898 for (
int i = 0; i < stops.length() - 1; ++i )
2901 const QVariant bz = stops.value( i ).toList().value( 0 );
2902 const QVariant bv = stops.value( i ).toList().value( 1 );
2903 if ( bv.userType() != QMetaType::Type::QVariantList && bv.userType() != QMetaType::Type::QStringList )
2905 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported offset interpolation type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( bz.userType() ) ) ) );
2910 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
2911 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2912 if ( tv.userType() != QMetaType::Type::QVariantList && tv.userType() != QMetaType::Type::QStringList )
2914 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported offset interpolation type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( tz.userType() ) ) ) );
2918 caseString += QStringLiteral(
2919 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
2925 interpolateExpression( bz.toDouble(), tz.toDouble(), bv.toList().value( 0 ), tv.toList().value( 0 ), base, multiplier, x1, y1, x2, y2, type, &context ),
2926 interpolateExpression( bz.toDouble(), tz.toDouble(), bv.toList().value( 1 ), tv.toList().value( 1 ), base, multiplier, x1, y1, x2, y2, type, &context )
2929 caseString +=
"END"_L1;
2935 if ( stops.length() < 2 )
2938 QString caseString = u
"CASE"_s;
2940 for (
int i = 0; i < stops.length(); ++i )
2942 caseString +=
" WHEN "_L1;
2943 QStringList conditions;
2946 const QVariant bottomZoom = stops.value( i ).toList().value( 0 );
2947 conditions << u
"@vector_tile_zoom > %1"_s.arg( bottomZoom.toString() );
2949 if ( i < stops.length() - 1 )
2951 const QVariant topZoom = stops.value( i + 1 ).toList().value( 0 );
2952 conditions << u
"@vector_tile_zoom <= %1"_s.arg( topZoom.toString() );
2955 const QVariantList values = stops.value( i ).toList().value( 1 ).toList();
2956 QStringList valuesFixed;
2958 for (
const QVariant &value : values )
2960 const double number = value.toDouble( &ok );
2962 valuesFixed << QString::number( number * multiplier );
2966 caseString += u
"%1 THEN array(%3)"_s.arg( conditions.join(
" AND "_L1 ), valuesFixed.join(
',' ) );
2968 caseString +=
" END"_L1;
2976 QString caseString = u
"CASE "_s;
2978 for (
int i = 0; i < stops.length() - 1; ++i )
2981 const QVariant bz = stops.value( i ).toList().value( 0 );
2982 const QVariant bv = stops.value( i ).toList().value( 1 );
2983 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
2985 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
2990 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
2991 const QVariant tv = stops.value( i + 1 ).toList().value( 1 );
2992 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
2994 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
2998 const QString lowerComparator = i == 0 ? u
">="_s : u
">"_s;
3000 caseString += QStringLiteral(
3001 "WHEN @vector_tile_zoom %1 %2 AND @vector_tile_zoom <= %3 "
3004 .arg( lowerComparator, bz.toString(), tz.toString(),
interpolateExpression( bz.toDouble(), tz.toDouble(), bv, tv, base, multiplier, x1, y1, x2, y2, type, &context ) );
3007 const QVariant z = stops.last().toList().value( 0 );
3008 const QVariant v = stops.last().toList().value( 1 );
3009 QString vStr = v.toString();
3010 if ( ( QMetaType::Type ) v.userType() == QMetaType::QVariantList )
3013 caseString += QStringLiteral(
3014 "WHEN @vector_tile_zoom > %1 "
3015 "THEN ( ( %2 ) * %3 ) END"
3017 .arg( z.toString() )
3023 caseString += QStringLiteral(
3024 "WHEN @vector_tile_zoom > %1 "
3027 .arg( z.toString() )
3028 .arg( v.toDouble() * multiplier );
3036 QString caseString = u
"CASE "_s;
3038 for (
int i = 0; i < stops.length() - 1; ++i )
3041 const QVariant bz = stops.value( i ).toList().value( 0 );
3042 const QString bv = stops.value( i ).toList().value( 1 ).toString();
3043 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3045 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3050 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
3051 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
3053 context.
pushWarning( QObject::tr(
"%1: Expressions in interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3057 caseString += QStringLiteral(
3058 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom <= %2 "
3063 caseString += u
"ELSE %1 END"_s.arg(
QgsExpression::quotedValue( conversionMap.value( stops.constLast().toList().value( 1 ).toString(), stops.constLast().toList().value( 1 ) ) ) );
3064 if ( defaultString )
3065 *defaultString = stops.constLast().toList().value( 1 ).toString();
3071 QString caseString = u
"CASE "_s;
3073 bool isExpression =
false;
3074 for (
int i = 0; i < stops.length() - 1; ++i )
3077 const QVariant bz = stops.value( i ).toList().value( 0 );
3078 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3080 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3085 const QVariant tz = stops.value( i + 1 ).toList().value( 0 );
3086 if ( tz.userType() == QMetaType::Type::QVariantList || tz.userType() == QMetaType::Type::QStringList )
3088 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3092 QString fieldPart = processLabelField( stops.constLast().toList().value( 1 ).toString(), isExpression );
3093 if ( fieldPart.isEmpty() )
3094 fieldPart = u
"''"_s;
3095 else if ( !isExpression )
3098 caseString += QStringLiteral(
3099 "WHEN @vector_tile_zoom > %1 AND @vector_tile_zoom < %2 "
3102 .arg( bz.toString(), tz.toString(), fieldPart );
3106 const QVariant bz = stops.constLast().toList().value( 0 );
3107 if ( bz.userType() == QMetaType::Type::QVariantList || bz.userType() == QMetaType::Type::QStringList )
3109 context.
pushWarning( QObject::tr(
"%1: Lists in label interpolation function are not supported, skipping." ).arg( context.
layerId() ) );
3113 QString fieldPart = processLabelField( stops.constLast().toList().value( 1 ).toString(), isExpression );
3114 if ( fieldPart.isEmpty() )
3115 fieldPart = u
"''"_s;
3116 else if ( !isExpression )
3119 caseString += QStringLiteral(
3120 "WHEN @vector_tile_zoom >= %1 "
3123 .arg( bz.toString(), fieldPart );
3126 QString defaultPart = processLabelField( stops.constFirst().toList().value( 1 ).toString(), isExpression );
3127 if ( defaultPart.isEmpty() )
3128 defaultPart = u
"''"_s;
3129 else if ( !isExpression )
3131 caseString += u
"ELSE %1 END"_s.arg( defaultPart );
3140 const QString method = json.
value( 0 ).toString();
3141 if ( method ==
"interpolate"_L1 )
3145 else if ( method ==
"match"_L1 )
3147 return parseMatchList( json, type, context, multiplier, maxOpacity, defaultColor, defaultNumber );
3149 else if ( method ==
"step"_L1 )
3151 return parseStepList( json, type, context, multiplier, maxOpacity, defaultColor, defaultNumber );
3163 const QString attribute =
parseExpression( json.value( 1 ).toList(), context );
3164 if ( attribute.isEmpty() )
3166 context.
pushWarning( QObject::tr(
"%1: Could not interpret match list" ).arg( context.
layerId() ) );
3170 QString caseString = u
"CASE "_s;
3172 for (
int i = 2; i < json.length() - 1; i += 2 )
3175 QVariant variantKeys = json.value( i );
3176 if ( variantKeys.userType() == QMetaType::Type::QVariantList || variantKeys.userType() == QMetaType::Type::QStringList )
3177 keys = variantKeys.toList();
3179 keys = { variantKeys };
3181 QStringList matchString;
3182 for (
const QVariant &key : keys )
3187 const QVariant value = json.value( i + 1 );
3189 QString valueString;
3194 if ( value.userType() == QMetaType::Type::QVariantList || value.userType() == QMetaType::Type::QStringList )
3200 const QColor color =
parseColor( value, context );
3208 const double v = value.toDouble() * multiplier;
3209 valueString = QString::number( v );
3215 const double v = value.toDouble() * maxOpacity;
3216 valueString = QString::number( v );
3222 valueString = u
"array(%1,%2)"_s.arg( value.toList().value( 0 ).toDouble() * multiplier, value.toList().value( 0 ).toDouble() * multiplier );
3228 if ( value.toList().count() == 2 && value.toList().first().toString() ==
"literal"_L1 )
3230 valueString = u
"array(%1)"_s.arg( value.toList().at( 1 ).toStringList().join(
',' ) );
3234 valueString = u
"array(%1)"_s.arg( value.toStringList().join(
',' ) );
3241 if ( value.toList().count() == 2 && value.toList().first().toString() ==
"literal"_L1 )
3243 QStringList dashValues = value.toList().at( 1 ).toStringList();
3244 if ( dashValues.length() % 2 == 1 )
3246 dashValues << u
"0"_s;
3248 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3252 QStringList dashValues = value.toStringList();
3253 if ( dashValues.length() % 2 == 1 )
3255 dashValues << u
"0"_s;
3257 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3263 if ( matchString.count() == 1 )
3265 caseString += u
"WHEN %1 IS %2 THEN %3 "_s.arg( attribute, matchString.at( 0 ), valueString );
3269 caseString += u
"WHEN %1 IN (%2) THEN %3 "_s.arg( attribute, matchString.join(
',' ), valueString );
3273 QVariant lastValue = json.constLast();
3276 switch ( lastValue.userType() )
3278 case QMetaType::Type::QVariantList:
3279 case QMetaType::Type::QStringList:
3280 elseValue =
parseValueList( lastValue.toList(), type, context, multiplier, maxOpacity, defaultColor, defaultNumber ).
asExpression();
3289 const QColor color =
parseColor( lastValue, context );
3291 *defaultColor = color;
3299 const double v = json.constLast().toDouble() * multiplier;
3300 if ( defaultNumber )
3302 elseValue = QString::number( v );
3308 const double v = json.constLast().toDouble() * maxOpacity;
3309 if ( defaultNumber )
3311 elseValue = QString::number( v );
3317 elseValue = u
"array(%1,%2)"_s.arg( json.constLast().toList().value( 0 ).toDouble() * multiplier ).arg( json.constLast().toList().value( 0 ).toDouble() * multiplier );
3323 if ( json.constLast().toList().count() == 2 && json.constLast().toList().first().toString() ==
"literal"_L1 )
3325 elseValue = u
"array(%1)"_s.arg( json.constLast().toList().at( 1 ).toStringList().join(
',' ) );
3329 elseValue = u
"array(%1)"_s.arg( json.constLast().toStringList().join(
',' ) );
3336 if ( json.constLast().toList().count() == 2 && json.constLast().toList().first().toString() ==
"literal"_L1 )
3338 QStringList dashValues = json.constLast().toList().at( 1 ).toStringList();
3339 if ( dashValues.length() % 2 == 1 )
3341 dashValues << u
"0"_s;
3343 elseValue = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3347 QStringList dashValues = json.constLast().toStringList();
3348 if ( dashValues.length() % 2 == 1 )
3350 dashValues << u
"0"_s;
3352 elseValue = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3361 caseString += u
"ELSE %1 END"_s.arg( elseValue );
3369 const QString expression =
parseExpression( json.value( 1 ).toList(), context );
3370 if ( expression.isEmpty() )
3372 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
3376 QString caseString = u
"CASE "_s;
3379 for (
int i = json.length() - 2; i > 0; i -= 2 )
3381 const QVariant stepValue = json.value( i + 1 );
3383 QString valueString;
3394 const QColor color =
parseColor( stepValue, context );
3401 const double v = stepValue.toDouble() * multiplier;
3402 valueString = QString::number( v );
3408 const double v = stepValue.toDouble() * maxOpacity;
3409 valueString = QString::number( v );
3415 valueString = u
"array(%1,%2)"_s.arg( stepValue.toList().value( 0 ).toDouble() * multiplier ).arg( stepValue.toList().value( 0 ).toDouble() * multiplier );
3421 if ( stepValue.toList().count() == 2 && stepValue.toList().first().toString() ==
"literal"_L1 )
3423 valueString = u
"array(%1)"_s.arg( stepValue.toList().at( 1 ).toStringList().join(
',' ) );
3427 valueString = u
"array(%1)"_s.arg( stepValue.toStringList().join(
',' ) );
3434 if ( stepValue.toList().count() == 2 && stepValue.toList().first().toString() ==
"literal"_L1 )
3436 QStringList dashValues = stepValue.toList().at( 1 ).toStringList();
3437 if ( dashValues.length() % 2 == 1 )
3439 dashValues << u
"0"_s;
3441 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3445 QStringList dashValues = stepValue.toStringList();
3446 if ( dashValues.length() % 2 == 1 )
3448 dashValues << u
"0"_s;
3450 valueString = u
"array(%1)"_s.arg( dashValues.join(
',' ) );
3460 caseString += u
" WHEN %1 >= %2 THEN (%3) "_s.arg( expression, stepKey, valueString );
3464 caseString += u
"ELSE (%1) END"_s.arg( valueString );
3474 if ( json.value( 0 ).toString() !=
"interpolate"_L1 )
3476 context.
pushWarning( QObject::tr(
"%1: Could not interpret value list" ).arg( context.
layerId() ) );
3480 const QVariantList parts = json.
value( 1 ).toList();
3481 const QString technique = parts.value( 0 ).toString();
3485 if ( technique ==
"linear"_L1 )
3487 props.insert( u
"base"_s, 1 );
3490 else if ( technique ==
"exponential"_L1 )
3492 props.insert( u
"base"_s, parts.value( 1 ).toDouble() );
3495 else if ( technique ==
"cubic-bezier"_L1 )
3499 props.insert( u
"x1"_s, parts.value( 1 ).toDouble() );
3500 props.insert( u
"y1"_s, parts.value( 2 ).toDouble() );
3501 props.insert( u
"x2"_s, parts.value( 3 ).toDouble() );
3502 props.insert( u
"y2"_s, parts.value( 4 ).toDouble() );
3506 context.
pushWarning( QObject::tr(
"%1: Skipping not implemented interpolation method %2" ).arg( context.
layerId(), technique ) );
3510 if ( json.value( 2 ).toList().value( 0 ).toString() !=
"zoom"_L1 )
3512 context.
pushWarning( QObject::tr(
"%1: Skipping not implemented interpolation input %2" ).arg( context.
layerId(), json.value( 2 ).toString() ) );
3518 for (
int i = 3; i < json.length(); i += 2 )
3520 stops.push_back( QVariantList() << json.value( i ).toString() << json.value( i + 1 ) );
3523 props.insert( u
"stops"_s, stops );
3541 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported numeric array in interpolate" ).arg( context.
layerId() ) );
3549 if ( ( QMetaType::Type ) colorExpression.userType() == QMetaType::QVariantList )
3553 return parseValue( colorExpression, context,
true );
3558 if ( color.userType() != QMetaType::Type::QString )
3560 context.
pushWarning( QObject::tr(
"%1: Could not parse non-string color %2, skipping" ).arg( context.
layerId(), color.toString() ) );
3569 hue = std::max( 0, color.hslHue() );
3570 saturation = color.hslSaturation() / 255.0 * 100;
3571 lightness = color.lightness() / 255.0 * 100;
3572 alpha = color.alpha();
3576 double zoomMin,
double zoomMax, QVariant valueMin, QVariant valueMax,
double base,
double multiplier,
double x1,
double y1,
double x2,
double y2,
InterpolationType type,
QgsMapBoxGlStyleConversionContext *contextPtr
3582 context = *contextPtr;
3586 if ( valueMin.canConvert( QMetaType::Double ) && valueMax.canConvert( QMetaType::Double ) )
3588 bool minDoubleOk =
true;
3589 const double min = valueMin.toDouble( &minDoubleOk );
3590 bool maxDoubleOk =
true;
3591 const double max = valueMax.toDouble( &maxDoubleOk );
3592 if ( minDoubleOk && maxDoubleOk &&
qgsDoubleNear( min, max ) )
3594 return QString::number( min * multiplier );
3598 QString minValueExpr = valueMin.toString();
3599 QString maxValueExpr = valueMax.toString();
3600 if ( valueMin.userType() == QMetaType::Type::QVariantList )
3604 if ( valueMax.userType() == QMetaType::Type::QVariantList )
3610 if ( minValueExpr == maxValueExpr )
3612 expression = minValueExpr;
3619 expression = u
"scale_linear(@vector_tile_zoom,%1,%2,%3,%4)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr );
3624 expression = u
"scale_linear(@vector_tile_zoom,%1,%2,%3,%4)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr );
3628 expression = u
"scale_exponential(@vector_tile_zoom,%1,%2,%3,%4,%5)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr ).arg( base );
3633 expression = u
"scale_cubic_bezier(@vector_tile_zoom,%1,%2,%3,%4,%5,%6,%7,%8)"_s.arg( zoomMin ).arg( zoomMax ).arg( minValueExpr ).arg( maxValueExpr ).arg( x1 ).arg( y1 ).arg( x2 ).arg( y2 );
3638 if ( multiplier != 1 )
3639 return u
"(%1) * %2"_s.arg( expression ).arg( multiplier );
3646 if ( style ==
"round"_L1 )
3647 return Qt::RoundCap;
3648 else if ( style ==
"square"_L1 )
3649 return Qt::SquareCap;
3656 if ( style ==
"bevel"_L1 )
3657 return Qt::BevelJoin;
3658 else if ( style ==
"round"_L1 )
3659 return Qt::RoundJoin;
3661 return Qt::MiterJoin;
3666 QString op = expression.value( 0 ).toString();
3667 if ( ( op ==
"%"_L1 || op ==
"/"_L1 || op ==
"-"_L1 || op ==
"^"_L1 ) && expression.size() >= 3 )
3669 if ( expression.size() != 3 )
3671 context.
pushWarning( QObject::tr(
"%1: Operator %2 requires exactly two operands, skipping extra operands" ).arg( context.
layerId() ).arg( op ) );
3673 QString v1 = parseValue( expression.value( 1 ), context, colorExpected );
3674 QString v2 = parseValue( expression.value( 2 ), context, colorExpected );
3675 return u
"(%1 %2 %3)"_s.arg( v1, op, v2 );
3677 else if ( ( op ==
"*"_L1 || op ==
"+"_L1 ) && expression.size() >= 3 )
3679 QStringList operands;
3680 std::transform( std::next( expression.begin() ), expression.end(), std::back_inserter( operands ), [&context, colorExpected](
const QVariant &val ) {
3681 return parseValue( val, context, colorExpected );
3683 return u
"(%1)"_s.arg( operands.join( u
" %1 "_s.arg( op ) ) );
3685 else if ( op ==
"to-number"_L1 )
3687 return u
"to_real(%1)"_s.arg( parseValue( expression.value( 1 ), context ) );
3689 else if ( op ==
"sqrt"_L1 )
3691 return u
"sqrt(%1)"_s.arg( parseValue( expression.value( 1 ), context ) );
3693 else if ( op ==
"literal"_L1 )
3695 return expression.value( 1 ).toString();
3697 else if ( op ==
"all"_L1 || op ==
"any"_L1 || op ==
"none"_L1 )
3700 for (
int i = 1; i < expression.size(); ++i )
3702 const QString part = parseValue( expression.at( i ), context );
3703 if ( part.isEmpty() )
3705 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3711 if ( op ==
"none"_L1 )
3712 return u
"NOT (%1)"_s.arg( parts.join(
") AND NOT ("_L1 ) );
3714 QString operatorString;
3715 if ( op ==
"all"_L1 )
3716 operatorString = u
") AND ("_s;
3717 else if ( op ==
"any"_L1 )
3718 operatorString = u
") OR ("_s;
3720 return u
"(%1)"_s.arg( parts.join( operatorString ) );
3722 else if ( op ==
'!' )
3725 QVariantList contraJsonExpr = expression.value( 1 ).toList();
3726 contraJsonExpr[0] = QString( op + contraJsonExpr[0].toString() );
3728 return parseKey( contraJsonExpr, context );
3730 else if ( op ==
"=="_L1 || op ==
"!="_L1 || op ==
">="_L1 || op ==
'>' || op ==
"<="_L1 || op ==
'<' )
3733 if ( op ==
"=="_L1 )
3735 else if ( op ==
"!="_L1 )
3737 return u
"%1 %2 %3"_s.arg( parseKey( expression.value( 1 ), context ), op, parseValue( expression.value( 2 ), context ) );
3739 else if ( op ==
"has"_L1 )
3741 return parseKey( expression.value( 1 ), context ) + u
" IS NOT NULL"_s;
3743 else if ( op ==
"!has"_L1 )
3745 return parseKey( expression.value( 1 ), context ) + u
" IS NULL"_s;
3747 else if ( op ==
"in"_L1 || op ==
"!in"_L1 )
3749 const QString key = parseKey( expression.value( 1 ), context );
3752 QVariantList values = expression.mid( 2 );
3753 if ( expression.size() == 3 && expression.at( 2 ).userType() == QMetaType::Type::QVariantList && expression.at( 2 ).toList().count() > 1 && expression.at( 2 ).toList().at( 0 ).toString() ==
"literal"_L1 )
3755 values = expression.at( 2 ).toList().at( 1 ).toList();
3758 for (
const QVariant &value : std::as_const( values ) )
3760 const QString part = parseValue( value, context );
3761 if ( part.isEmpty() )
3763 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3769 if ( parts.size() == 1 )
3771 if ( op ==
"in"_L1 )
3772 return u
"%1 IS %2"_s.arg( key, parts.at( 0 ) );
3774 return u
"(%1 IS NULL OR %1 IS NOT %2)"_s.arg( key, parts.at( 0 ) );
3778 if ( op ==
"in"_L1 )
3779 return u
"%1 IN (%2)"_s.arg( key, parts.join(
", "_L1 ) );
3781 return u
"(%1 IS NULL OR %1 NOT IN (%2))"_s.arg( key, parts.join(
", "_L1 ) );
3784 else if ( op ==
"get"_L1 )
3786 return parseKey( expression.value( 1 ), context );
3788 else if ( op ==
"match"_L1 )
3790 const QString attribute = expression.value( 1 ).toList().value( 1 ).toString();
3792 if ( expression.size() == 5
3793 && expression.at( 3 ).userType() == QMetaType::Type::Bool
3794 && expression.at( 3 ).toBool() ==
true
3795 && expression.at( 4 ).userType() == QMetaType::Type::Bool
3796 && expression.at( 4 ).toBool() ==
false )
3799 if ( expression.at( 2 ).userType() == QMetaType::Type::QVariantList || expression.at( 2 ).userType() == QMetaType::Type::QStringList )
3802 for (
const QVariant &p : expression.at( 2 ).toList() )
3804 parts << parseValue( p, context );
3807 if ( parts.size() > 1 )
3812 else if ( expression.at( 2 ).userType() == QMetaType::Type::QString
3813 || expression.at( 2 ).userType() == QMetaType::Type::Int
3814 || expression.at( 2 ).userType() == QMetaType::Type::Double
3815 || expression.at( 2 ).userType() == QMetaType::Type::LongLong )
3821 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression" ).arg( context.
layerId() ) );
3827 QString caseString = u
"CASE "_s;
3828 for (
int i = 2; i < expression.size() - 2; i += 2 )
3830 if ( expression.at( i ).userType() == QMetaType::Type::QVariantList || expression.at( i ).userType() == QMetaType::Type::QStringList )
3833 for (
const QVariant &p : expression.at( i ).toList() )
3838 if ( parts.size() > 1 )
3843 else if ( expression.at( i ).userType() == QMetaType::Type::QString
3844 || expression.at( i ).userType() == QMetaType::Type::Int
3845 || expression.at( i ).userType() == QMetaType::Type::Double
3846 || expression.at( i ).userType() == QMetaType::Type::LongLong )
3851 caseString += u
"THEN %1 "_s.arg( parseValue( expression.at( i + 1 ), context, colorExpected ) );
3853 caseString += u
"ELSE %1 END"_s.arg( parseValue( expression.last(), context, colorExpected ) );
3857 else if ( op ==
"to-string"_L1 )
3859 return u
"to_string(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3861 else if ( op ==
"to-boolean"_L1 )
3863 return u
"to_bool(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3865 else if ( op ==
"case"_L1 )
3867 QString caseString = u
"CASE"_s;
3868 for (
int i = 1; i < expression.size() - 2; i += 2 )
3870 const QString condition =
parseExpression( expression.value( i ).toList(), context );
3871 const QString value = parseValue( expression.value( i + 1 ), context, colorExpected );
3872 caseString += u
" WHEN (%1) THEN %2"_s.arg( condition, value );
3874 const QString value = parseValue( expression.constLast(), context, colorExpected );
3875 caseString += u
" ELSE %1 END"_s.arg( value );
3878 else if ( op ==
"zoom"_L1 && expression.count() == 1 )
3880 return u
"@vector_tile_zoom"_s;
3882 else if ( op ==
"coalesce"_L1 )
3884 QString coalesceString = u
"coalesce("_s;
3885 for (
int i = 1; i < expression.size(); i++ )
3888 coalesceString +=
", "_L1;
3889 coalesceString += parseValue( expression.value( i ), context );
3891 coalesceString +=
')'_L1;
3892 return coalesceString;
3894 else if ( op ==
"concat"_L1 )
3896 QString concatString = u
"concat("_s;
3897 for (
int i = 1; i < expression.size(); i++ )
3900 concatString +=
", "_L1;
3901 concatString += parseValue( expression.value( i ), context );
3903 concatString +=
')'_L1;
3904 return concatString;
3906 else if ( op ==
"length"_L1 )
3908 return u
"length(%1)"_s.arg(
parseExpression( expression.value( 1 ).toList(), context ) );
3910 else if ( op ==
"step"_L1 )
3912 const QString stepExpression =
parseExpression( expression.value( 1 ).toList(), context );
3913 if ( stepExpression.isEmpty() )
3915 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
3919 QString caseString = u
"CASE "_s;
3921 for (
int i = expression.length() - 2; i > 0; i -= 2 )
3923 const QString stepValue = parseValue( expression.value( i + 1 ), context, colorExpected );
3927 caseString += u
" WHEN %1 >= %2 THEN (%3) "_s.arg( stepExpression, stepKey, stepValue );
3931 caseString += u
"ELSE (%1) END"_s.arg( stepValue );
3936 else if ( op ==
"pitch"_L1 )
3940 else if ( op ==
"slice"_L1 )
3945 const QString inputExpression = parseValue( expression.value( 1 ), context );
3946 if ( inputExpression.isEmpty() )
3948 context.
pushWarning( QObject::tr(
"%1: Could not interpret slice list" ).arg( context.
layerId() ) );
3954 const auto constantInt = [](
const QVariant &value,
int &result ) ->
bool {
3955 switch ( value.userType() )
3957 case QMetaType::Int:
3958 case QMetaType::UInt:
3959 case QMetaType::LongLong:
3960 case QMetaType::ULongLong:
3963 result = value.toInt( &ok );
3972 const bool startIsConstant = constantInt( expression.value( 2 ), startValue );
3973 const QString startExpression = parseValue( expression.value( 2 ), context );
3974 const QString startOffset = startIsConstant ? QString::number( startValue + 1 ) : u
"(%1) + 1"_s.arg( startExpression );
3976 if ( expression.size() > 3 )
3979 const bool endIsConstant = constantInt( expression.value( 3 ), endValue );
3980 const QString endExpression = parseValue( expression.value( 3 ), context );
3981 const QString length = ( startIsConstant && endIsConstant ) ? QString::number( endValue - startValue ) : u
"(%1) - (%2)"_s.arg( endExpression, startExpression );
3982 return u
"substr(%1, %2, %3)"_s.arg( inputExpression, startOffset, length );
3986 return u
"substr(%1, %2)"_s.arg( inputExpression, startOffset );
3991 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression \"%2\"" ).arg( context.
layerId(), op ) );
4000 if ( name.isEmpty() )
4006 QString actualName = name;
4007 const int categorySeparator = name.indexOf(
':' );
4008 if ( categorySeparator > 0 )
4010 category = name.left( categorySeparator );
4013 actualName = name.mid( categorySeparator + 1 );
4022 if ( category.isEmpty() )
4027 category = u
"default"_s;
4031 if ( spriteImage.isNull() )
4033 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
4037 const QVariantMap spriteDefinition = context.
spriteDefinitions( category ).value( actualName ).toMap();
4038 if ( spriteDefinition.size() == 0 )
4040 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
4045 = spriteImage.copy( spriteDefinition.value( u
"x"_s ).toInt(), spriteDefinition.value( u
"y"_s ).toInt(), spriteDefinition.value( u
"width"_s ).toInt(), spriteDefinition.value( u
"height"_s ).toInt() );
4046 if ( sprite.isNull() )
4048 context.
pushWarning( QObject::tr(
"%1: Could not retrieve sprite '%2'" ).arg( context.
layerId(), name ) );
4052 spriteSize = sprite.size() / spriteDefinition.value( u
"pixelRatio"_s ).toDouble() * context.
pixelSizeConversionFactor();
4062 auto prepareBase64 = [](
const QImage &sprite ) {
4064 if ( !sprite.isNull() )
4067 QBuffer buffer( &blob );
4068 buffer.open( QIODevice::WriteOnly );
4069 sprite.save( &buffer,
"PNG" );
4071 const QByteArray encoded = blob.toBase64();
4072 path = QString( encoded );
4073 path.prepend(
"base64:"_L1 );
4078 switch ( value.userType() )
4080 case QMetaType::Type::QString:
4082 QString spriteName = value.toString();
4083 const thread_local QRegularExpression fieldNameMatch( u
"{([^}]+)}"_s );
4084 QRegularExpressionMatch match = fieldNameMatch.match( spriteName );
4085 if ( match.hasMatch() )
4087 const QString fieldName = match.captured( 1 );
4088 spriteProperty = u
"CASE"_s;
4089 spriteSizeProperty = u
"CASE"_s;
4091 spriteName.replace(
"(",
"\\("_L1 );
4092 spriteName.replace(
")",
"\\)"_L1 );
4093 spriteName.replace( fieldNameMatch, u
"([^\\/\\\\]+)"_s );
4094 const QRegularExpression fieldValueMatch( spriteName );
4096 for (
const QString &name : spriteNames )
4098 match = fieldValueMatch.match( name );
4099 if ( match.hasMatch() )
4103 const QString fieldValue = match.captured( 1 );
4105 path = prepareBase64( sprite );
4106 if ( spritePath.isEmpty() && !path.isEmpty() )
4112 spriteProperty += u
" WHEN \"%1\" = '%2' THEN '%3'"_s.arg( fieldName, fieldValue, path );
4113 spriteSizeProperty += u
" WHEN \"%1\" = '%2' THEN %3"_s.arg( fieldName ).arg( fieldValue ).arg( size.width() );
4117 spriteProperty +=
" END"_L1;
4118 spriteSizeProperty +=
" END"_L1;
4122 spriteProperty.clear();
4123 spriteSizeProperty.clear();
4124 const QImage sprite =
retrieveSprite( spriteName, context, spriteSize );
4125 spritePath = prepareBase64( sprite );
4130 case QMetaType::Type::QVariantMap:
4132 const QVariantList stops = value.toMap().value( u
"stops"_s ).toList();
4133 if ( stops.size() == 0 )
4140 sprite =
retrieveSprite( stops.value( 0 ).toList().value( 1 ).toString(), context, spriteSize );
4141 spritePath = prepareBase64( sprite );
4143 spriteProperty = u
"CASE WHEN @vector_tile_zoom < %1 THEN '%2'"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() ).arg( spritePath );
4144 spriteSizeProperty = u
"CASE WHEN @vector_tile_zoom < %1 THEN %2"_s.arg( stops.value( 0 ).toList().value( 0 ).toString() ).arg( spriteSize.width() );
4146 for (
int i = 0; i < stops.size() - 1; ++i )
4149 sprite =
retrieveSprite( stops.value( 0 ).toList().value( 1 ).toString(), context, size );
4150 path = prepareBase64( sprite );
4152 spriteProperty += QStringLiteral(
4153 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
4156 .arg( stops.value( i ).toList().value( 0 ).toString(), stops.value( i + 1 ).toList().value( 0 ).toString(), path );
4157 spriteSizeProperty += QStringLiteral(
4158 " WHEN @vector_tile_zoom >= %1 AND @vector_tile_zoom < %2 "
4161 .arg( stops.value( i ).toList().value( 0 ).toString(), stops.value( i + 1 ).toList().value( 0 ).toString() )
4162 .arg( size.width() );
4164 sprite =
retrieveSprite( stops.last().toList().value( 1 ).toString(), context, size );
4165 path = prepareBase64( sprite );
4167 spriteProperty += QStringLiteral(
4168 " WHEN @vector_tile_zoom >= %1 "
4171 .arg( stops.last().toList().value( 0 ).toString() )
4173 spriteSizeProperty += QStringLiteral(
4174 " WHEN @vector_tile_zoom >= %1 "
4177 .arg( stops.last().toList().value( 0 ).toString() )
4178 .arg( size.width() );
4182 case QMetaType::Type::QVariantList:
4184 const QVariantList json = value.toList();
4185 const QString method = json.value( 0 ).toString();
4187 if ( method ==
"match"_L1 )
4189 const QString attribute =
parseExpression( json.value( 1 ).toList(), context );
4190 if ( attribute.isEmpty() )
4192 context.
pushWarning( QObject::tr(
"%1: Could not interpret match list" ).arg( context.
layerId() ) );
4196 spriteProperty = u
"CASE"_s;
4197 spriteSizeProperty = u
"CASE"_s;
4199 for (
int i = 2; i < json.length() - 1; i += 2 )
4201 const QVariant matchKey = json.value( i );
4202 const QVariant matchValue = json.value( i + 1 );
4203 QString matchString;
4204 switch ( matchKey.userType() )
4206 case QMetaType::Type::QVariantList:
4207 case QMetaType::Type::QStringList:
4209 const QVariantList keys = matchKey.toList();
4210 QStringList matchStringList;
4211 for (
const QVariant &key : keys )
4215 matchString = matchStringList.join(
',' );
4219 case QMetaType::Type::Bool:
4220 case QMetaType::Type::QString:
4221 case QMetaType::Type::Int:
4222 case QMetaType::Type::LongLong:
4223 case QMetaType::Type::Double:
4230 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported sprite type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( value.userType() ) ) ) );
4234 QString valuePathExpression;
4235 QString valueSizeExpression;
4236 if ( matchValue.userType() == QMetaType::Type::QVariantList || matchValue.userType() == QMetaType::Type::QStringList )
4240 QString nestedProperty;
4241 QString nestedSizeProperty;
4243 valuePathExpression = nestedProperty.isEmpty() ? u
"'%1'"_s.arg( nestedPath ) : nestedProperty;
4244 valueSizeExpression = nestedSizeProperty.isEmpty() ? QString::number( nestedSize.width() ) : nestedSizeProperty;
4245 spritePath = nestedPath;
4246 spriteSize = nestedSize;
4250 const QImage sprite =
retrieveSprite( matchValue.toString(), context, spriteSize );
4251 spritePath = prepareBase64( sprite );
4252 valuePathExpression = u
"'%1'"_s.arg( spritePath );
4253 valueSizeExpression = QString::number( spriteSize.width() );
4256 spriteProperty += u
" WHEN %1 IN (%2) THEN %3"_s.arg( attribute, matchString, valuePathExpression );
4257 spriteSizeProperty += u
" WHEN %1 IN (%2) THEN %3"_s.arg( attribute, matchString, valueSizeExpression );
4260 const QVariant defaultValue = json.constLast();
4261 if ( defaultValue.userType() == QMetaType::Type::QVariantList || defaultValue.userType() == QMetaType::Type::QStringList )
4265 QString nestedProperty;
4266 QString nestedSizeProperty;
4268 spriteProperty += u
" ELSE %1 END"_s.arg( nestedProperty.isEmpty() ? u
"'%1'"_s.arg( nestedPath ) : nestedProperty );
4269 spriteSizeProperty += u
" ELSE %1 END"_s.arg( nestedSizeProperty.isEmpty() ? QString::number( nestedSize.width() ) : nestedSizeProperty );
4270 spritePath = nestedPath;
4271 spriteSize = nestedSize;
4275 if ( !defaultValue.toString().isEmpty() )
4277 const QImage sprite =
retrieveSprite( defaultValue.toString(), context, spriteSize );
4278 spritePath = prepareBase64( sprite );
4282 spritePath = QString();
4285 spriteProperty += u
" ELSE '%1' END"_s.arg( spritePath );
4286 spriteSizeProperty += u
" ELSE %3 END"_s.arg( spriteSize.width() );
4290 else if ( method ==
"step"_L1 )
4292 const QString expression =
parseExpression( json.value( 1 ).toList(), context );
4293 if ( expression.isEmpty() )
4295 context.
pushWarning( QObject::tr(
"%1: Could not interpret step list" ).arg( context.
layerId() ) );
4299 spriteProperty = u
"CASE"_s;
4300 spriteSizeProperty = u
"CASE"_s;
4301 for (
int i = json.length() - 2; i > 2; i -= 2 )
4304 const QString stepValue = json.value( i + 1 ).toString();
4306 const QImage sprite =
retrieveSprite( stepValue, context, spriteSize );
4307 spritePath = prepareBase64( sprite );
4309 spriteProperty += u
" WHEN %1 >= %2 THEN '%3' "_s.arg( expression, stepKey, spritePath );
4310 spriteSizeProperty += u
" WHEN %1 >= %2 THEN %3 "_s.arg( expression ).arg( stepKey ).arg( spriteSize.width() );
4313 const QImage sprite =
retrieveSprite( json.at( 2 ).toString(), context, spriteSize );
4314 spritePath = prepareBase64( sprite );
4316 spriteProperty += u
"ELSE '%1' END"_s.arg( spritePath );
4317 spriteSizeProperty += u
"ELSE %3 END"_s.arg( spriteSize.width() );
4320 else if ( method ==
"case"_L1 )
4322 spriteProperty = u
"CASE"_s;
4323 spriteSizeProperty = u
"CASE"_s;
4324 for (
int i = 1; i < json.length() - 2; i += 2 )
4326 const QString caseExpression =
parseExpression( json.value( i ).toList(), context );
4327 const QString caseValue = json.value( i + 1 ).toString();
4329 const QImage sprite =
retrieveSprite( caseValue, context, spriteSize );
4330 spritePath = prepareBase64( sprite );
4332 spriteProperty += u
" WHEN %1 THEN '%2' "_s.arg( caseExpression, spritePath );
4333 spriteSizeProperty += u
" WHEN %1 THEN %2 "_s.arg( caseExpression ).arg( spriteSize.width() );
4335 const QImage sprite =
retrieveSprite( json.last().toString(), context, spriteSize );
4336 spritePath = prepareBase64( sprite );
4338 spriteProperty += u
"ELSE '%1' END"_s.arg( spritePath );
4339 spriteSizeProperty += u
"ELSE %3 END"_s.arg( spriteSize.width() );
4344 context.
pushWarning( QObject::tr(
"%1: Could not interpret sprite value list with method %2" ).arg( context.
layerId(), method ) );
4350 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported sprite type (%2)." ).arg( context.
layerId(), QMetaType::typeName(
static_cast<QMetaType::Type
>( value.userType() ) ) ) );
4360 switch ( value.userType() )
4362 case QMetaType::Type::QVariantList:
4363 case QMetaType::Type::QStringList:
4366 case QMetaType::Type::Bool:
4367 case QMetaType::Type::QString:
4368 if ( colorExpected )
4373 return parseValue(
c, context );
4378 case QMetaType::Type::Int:
4379 case QMetaType::Type::LongLong:
4380 case QMetaType::Type::Double:
4381 return value.toString();
4383 case QMetaType::Type::QColor:
4384 c = value.value<QColor>();
4385 return QString(
"color_rgba(%1,%2,%3,%4)" ).arg(
c.red() ).arg(
c.green() ).arg(
c.blue() ).arg(
c.alpha() );
4388 context.
pushWarning( QObject::tr(
"%1: Skipping unsupported expression part" ).arg( context.
layerId() ) );
4396 if ( value.toString() ==
"$type"_L1 )
4398 return u
"_geom_type"_s;
4400 if ( value.toString() ==
"level"_L1 )
4404 else if ( ( value.userType() == QMetaType::Type::QVariantList && value.toList().size() == 1 ) || value.userType() == QMetaType::Type::QStringList )
4406 if ( value.toList().size() > 1 )
4407 return value.toList().at( 1 ).toString();
4410 QString valueString = value.toList().value( 0 ).toString();
4411 if ( valueString ==
"geometry-type"_L1 )
4413 return u
"_geom_type"_s;
4418 else if ( value.userType() == QMetaType::Type::QVariantList && value.toList().size() > 1 )
4425QString QgsMapBoxGlStyleConverter::processLabelField(
const QString &
string,
bool &isExpression )
4429 const thread_local QRegularExpression singleFieldRx( u
"^{([^}]+)}$"_s );
4430 const QRegularExpressionMatch match = singleFieldRx.match(
string );
4431 if ( match.hasMatch() )
4433 isExpression =
false;
4434 return match.captured( 1 );
4437 const thread_local QRegularExpression multiFieldRx( u
"(?={[^}]+})"_s );
4438 const QStringList parts =
string.split( multiFieldRx );
4439 if ( parts.size() > 1 )
4441 isExpression =
true;
4444 for (
const QString &part : parts )
4446 if ( part.isEmpty() )
4449 if ( !part.contains(
'{' ) )
4456 const QStringList split = part.split(
'}' );
4458 if ( !split.at( 1 ).isEmpty() )
4461 return u
"concat(%1)"_s.arg( res.join(
',' ) );
4465 isExpression =
false;
4472 return mRenderer ? std::unique_ptr<QgsVectorTileRenderer>( mRenderer->clone() ) :
nullptr;
4477 return mLabeling ? std::unique_ptr<QgsVectorTileLabeling>( mLabeling->clone() ) :
nullptr;
4487 return mRasterSubLayers;
4492 QList<QgsMapLayer *> subLayers;
4495 const QString sourceName = subLayer.source();
4496 std::unique_ptr< QgsRasterLayer > rl;
4503 rl->pipe()->setDataDefinedProperties( subLayer.dataDefinedProperties() );
4510 subLayers.append( rl.release() );
4519 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
4522 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
4523 context = tmpContext.get();
4527 if (
string.compare(
"vector"_L1, Qt::CaseInsensitive ) == 0 )
4529 else if (
string.compare(
"raster"_L1, Qt::CaseInsensitive ) == 0 )
4531 else if (
string.compare(
"raster-dem"_L1, Qt::CaseInsensitive ) == 0 )
4533 else if (
string.compare(
"geojson"_L1, Qt::CaseInsensitive ) == 0 )
4535 else if (
string.compare(
"image"_L1, Qt::CaseInsensitive ) == 0 )
4537 else if (
string.compare(
"video"_L1, Qt::CaseInsensitive ) == 0 )
4539 context->
pushWarning( QObject::tr(
"Invalid source type \"%1\" for source \"%2\"" ).arg(
string, name ) );
4545 const QString name = it.key();
4546 const QVariantMap jsonSource = it.value().toMap();
4547 const QString typeString = jsonSource.value( u
"type"_s ).toString();
4570 std::unique_ptr< QgsMapBoxGlStyleConversionContext > tmpContext;
4573 tmpContext = std::make_unique< QgsMapBoxGlStyleConversionContext >();
4574 context = tmpContext.get();
4577 auto raster = std::make_unique< QgsMapBoxGlStyleRasterSource >( name );
4578 if ( raster->setFromJson( source, context ) )
4579 mSources.append( raster.release() );
4582bool QgsMapBoxGlStyleConverter::numericArgumentsOnly(
const QVariant &bottomVariant,
const QVariant &topVariant,
double &bottom,
double &top )
4584 if ( bottomVariant.canConvert( QMetaType::Double ) && topVariant.canConvert( QMetaType::Double ) )
4586 bool bDoubleOk, tDoubleOk;
4587 bottom = bottomVariant.toDouble( &bDoubleOk );
4588 top = topVariant.toDouble( &tDoubleOk );
4589 return ( bDoubleOk && tDoubleOk );
4600 mWarnings << warning;
4615 return mSizeConversionFactor;
4620 mSizeConversionFactor = sizeConversionFactor;
4625 return mSpriteImage.keys();
4630 return mSpriteImage.contains( category ) ? mSpriteImage[category] : QImage();
4635 return mSpriteDefinitions.contains( category ) ? mSpriteDefinitions[category] : QVariantMap();
4640 mSpriteImage[category] = image;
4641 mSpriteDefinitions[category] = definitions;
4688 mAttribution = json.value( u
"attribution"_s ).toString();
4690 const QString scheme = json.value( u
"scheme"_s, u
"xyz"_s ).toString();
4691 if ( scheme.compare(
"xyz"_L1 ) == 0 )
4697 context->
pushWarning( QObject::tr(
"%1 scheme is not supported for raster source %2" ).arg( scheme,
name() ) );
4701 mMinZoom = json.value( u
"minzoom"_s, u
"0"_s ).toInt();
4702 mMaxZoom = json.value( u
"maxzoom"_s, u
"22"_s ).toInt();
4703 mTileSize = json.value( u
"tileSize"_s, u
"512"_s ).toInt();
4705 const QVariantList
tiles = json.value( u
"tiles"_s ).toList();
4706 for (
const QVariant &tile :
tiles )
4708 mTiles.append( tile.toString() );
4717 parts.insert( u
"type"_s, u
"xyz"_s );
4718 parts.insert( u
"url"_s, mTiles.value( 0 ) );
4720 if ( mTileSize == 256 )
4721 parts.insert( u
"tilePixelRation"_s, u
"1"_s );
4722 else if ( mTileSize == 512 )
4723 parts.insert( u
"tilePixelRation"_s, u
"2"_s );
4725 parts.insert( u
"zmax"_s, QString::number( mMaxZoom ) );
4726 parts.insert( u
"zmin"_s, QString::number( mMinZoom ) );
4729 return rl.release();
@ BelowLine
Labels can be placed below a line feature. Unless MapOrientation is also specified this mode respects...
@ OnLine
Labels can be placed directly over a line feature.
@ AboveLine
Labels can be placed above a line feature. Unless MapOrientation is also specified this mode respects...
@ CentralPoint
Place symbols at the mid point of the line.
@ OverPoint
Arranges candidates over a point (or centroid of a polygon), or at a preset offset from the point....
@ Curved
Arranges candidates following the curvature of a line feature. Applies to line layers only.
@ Horizontal
Arranges horizontal candidates scattered throughout a polygon feature or along a line feature....
GeometryType
The geometry types are used to group Qgis::WkbType in a coarse way.
@ FollowPlacement
Alignment follows placement of label, e.g., labels to the left of a feature will be drawn with right ...
RenderUnit
Rendering size units.
MapBoxGlStyleSourceType
Available MapBox GL style source types.
@ RasterDem
Raster DEM source.
@ Unknown
Other/unknown source type.
@ Viewport
Relative to the whole viewport/output device.
@ AllowOverlapAtNoCost
Labels may freely overlap other labels, at no cost.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
static QgsFontManager * fontManager()
Returns the application font manager, which manages available fonts and font installation for the QGI...
A paint effect which blurs a source picture, using a number of different blur methods.
void setBlurUnit(const Qgis::RenderUnit unit)
Sets the units used for the blur level (radius).
@ StackBlur
Stack blur, a fast but low quality blur. Valid blur level values are between 0 - 16.
void setBlurMethod(const BlurMethod method)
Sets the blur method (algorithm) to use for performing the blur.
void setBlurLevel(const double level)
Sets blur level (radius).
A paint effect which consists of a stack of other chained paint effects.
void appendEffect(QgsPaintEffect *effect)
Appends an effect to the end of the stack.
static QString quotedValue(const QVariant &value)
Returns a string representation of a literal value, including appropriate quotations where required.
static QString quotedString(QString text)
Returns a quoted version of a string (in single quotes).
static QString createFieldEqualityExpression(const QString &fieldName, const QVariant &value, QMetaType::Type fieldType=QMetaType::Type::UnknownType)
Create an expression allowing to evaluate if a field is equal to a value.
static QString quotedColumnRef(QString name)
Returns a quoted column reference (in double quotes).
QString processFontFamilyName(const QString &name) const
Processes a font family name, applying any matching fontFamilyReplacements() to the name.
static QFont createFont(const QString &family, int pointSize=-1, int weight=-1, bool italic=false)
Creates a font with the specified family.
static bool fontFamilyHasStyle(const QString &family, const QString &style)
Check whether font family on system has specific style.
static QVariant parseJson(const std::string &jsonString)
Converts JSON jsonString to a QVariant, in case of parsing error an invalid QVariant is returned and ...
void setPlacementFlags(Qgis::LabelLinePlacementFlags flags)
Returns the line placement flags, which dictate how line labels can be placed above or below the line...
void setFactor(double factor)
Sets the obstacle factor, where 1.0 = default, < 1.0 more likely to be covered by labels,...
Contains general settings related to how labels are placed.
void setOverlapHandling(Qgis::LabelOverlapHandling handling)
Sets the technique used to handle overlapping labels.
void setAllowDegradedPlacement(bool allow)
Sets whether labels can be placed in inferior fallback positions if they cannot otherwise be placed.
void setQuadrant(Qgis::LabelQuadrantPosition quadrant)
Sets the quadrant in which to offset labels from the point.
Contains settings related to how the label engine removes candidate label positions and reduces the n...
void setAllowDuplicateRemoval(bool allow)
Sets whether duplicate label removal is permitted for this layer.
void setMinimumDistanceToDuplicateUnit(Qgis::RenderUnit unit)
Sets the unit for the minimum distance to labels with duplicate text.
virtual void setWidth(double width)
Sets the width of the line symbol layer.
void setOffset(double offset)
Sets the line's offset.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the line's offset.
Abstract base class for MapBox GL style sources.
QString name() const
Returns the source's name.
virtual ~QgsMapBoxGlStyleAbstractSource()
QgsMapBoxGlStyleAbstractSource(const QString &name)
Constructor for QgsMapBoxGlStyleAbstractSource.
Context for a MapBox GL style conversion operation.
void setLayerId(const QString &value)
Sets the layer ID of the layer currently being converted.
QStringList warnings() const
Returns a list of warning messages generated during the conversion.
void pushWarning(const QString &warning)
Pushes a warning message generated during the conversion.
QImage spriteImage(const QString &category=QString()) const
Returns the sprite image for a given category to use during conversion, or an invalid image if this i...
double pixelSizeConversionFactor() const
Returns the pixel size conversion factor, used to scale the original pixel sizes when converting styl...
void setTargetUnit(Qgis::RenderUnit targetUnit)
Sets the target unit type.
void setSprites(const QImage &image, const QVariantMap &definitions, const QString &category=QString())
Sets the sprite image and definitions JSON for a given category to use during conversion.
void setPixelSizeConversionFactor(double sizeConversionFactor)
Sets the pixel size conversion factor, used to scale the original pixel sizes when converting styles.
QVariantMap spriteDefinitions(const QString &category=QString()) const
Returns the sprite definitions for a given category to use during conversion.
Qgis::RenderUnit targetUnit() const
Returns the target unit type.
QString layerId() const
Returns the layer ID of the layer currently being converted.
QStringList spriteCategories() const
Returns the list of sprite categories to use during conversion, or an empty list of none is set.
void clearWarnings()
Clears the list of warning messages.
static QgsProperty parseInterpolateByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, double *defaultNumber=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Parses a numeric value which is interpolated by zoom range.
static QString parseColorExpression(const QVariant &colorExpression, QgsMapBoxGlStyleConversionContext &context)
Converts an expression representing a color to a string (can be color string or an expression where a...
static QString parseExpression(const QVariantList &expression, QgsMapBoxGlStyleConversionContext &context, bool colorExpected=false)
Converts a MapBox GL expression to a QGIS expression.
InterpolationType
Interpolation types, for interpolated value conversion.
@ Linear
Linear interpolation.
@ Exponential
Exponential interpolation.
@ CubicBezier
Cubic-bezier interpolation.
static QString parsePointStops(double base, const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=0, double y2=0)
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate point/...
PropertyType
Property types, for interpolated value conversion.
@ Point
Point/offset property.
@ DashArray
Dash array. Like numeric array, but must be even length array. Odd length arrays are considered as ha...
@ Numeric
Numeric property (e.g. line width, text size).
@ Opacity
Opacity property.
@ NumericArray
Numeric array for dash arrays or such.
QList< QgsMapBoxGlStyleAbstractSource * > sources()
Returns the list of converted sources.
QList< QgsMapBoxGlStyleRasterSubLayer > rasterSubLayers() const
Returns a list of raster sub layers contained in the style.
static Qt::PenJoinStyle parseJoinStyle(const QString &style)
Converts a value to Qt::PenJoinStyle enum from JSON value.
static QString interpolateExpression(double zoomMin, double zoomMax, QVariant valueMin, QVariant valueMax, double base, double multiplier=1, double x1=0, double y1=0, double x2=1, double y2=1, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, QgsMapBoxGlStyleConversionContext *contextPtr=nullptr)
Generates an interpolation for values between valueMin and valueMax, scaled between the ranges zoomMi...
static QgsProperty parseInterpolateStringByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr)
Interpolates a string by zoom.
static QgsProperty parseStepList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a match function value list.
static bool parseCircleLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context)
Parses a circle layer.
Result convert(const QVariantMap &style, QgsMapBoxGlStyleConversionContext *context=nullptr)
Converts a JSON style map, and returns the resultant status of the conversion.
static QgsProperty parseInterpolateListByZoom(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Interpolates a list which starts with the interpolate function.
~QgsMapBoxGlStyleConverter()
QList< QgsMapLayer * > createSubLayers() const
Returns a list of new map layers corresponding to sublayers of the style, e.g.
Result
Result of conversion.
@ Success
Conversion was successful.
@ NoLayerList
No layer list was found in JSON input.
QgsMapBoxGlStyleConverter()
Constructor for QgsMapBoxGlStyleConverter.
static QgsProperty parseInterpolateColorByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, QColor *defaultColor=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Parses a color value which is interpolated by zoom range.
static QImage retrieveSprite(const QString &name, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize)
Retrieves the sprite image with the specified name, taken from the specified context.
static QString parseLabelStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context)
Parses a list of interpolation stops containing label values.
void parseLayers(const QVariantList &layers, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse list of layers from JSON.
static QgsProperty parseInterpolateOpacityByZoom(const QVariantMap &json, int maxOpacity, QgsMapBoxGlStyleConversionContext *contextPtr=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Interpolates opacity with either scale_linear() or scale_exp() (depending on base value).
static QString retrieveSpriteAsBase64WithProperties(const QVariant &value, QgsMapBoxGlStyleConversionContext &context, QSize &spriteSize, QString &spriteProperty, QString &spriteSizeProperty)
Retrieves the sprite image with the specified name, taken from the specified context as a base64 enco...
std::unique_ptr< QgsVectorTileLabeling > labeling() const
Returns a new instance of a vector tile labeling representing the converted style,...
void parseSources(const QVariantMap &sources, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse list of sources from JSON.
static QColor parseColor(const QVariant &color, QgsMapBoxGlStyleConversionContext &context)
Parses a color in one of these supported formats:
static bool parseSymbolLayerAsRenderer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, QgsMapBoxGlStyleConversionContext &context)
Parses a symbol layer as a renderer.
static bool parseFillLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context, bool isBackgroundStyle=false)
Parses a fill layer.
static void parseSymbolLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &rendererStyle, bool &hasRenderer, QgsVectorTileBasicLabelingStyle &labelingStyle, bool &hasLabeling, QgsMapBoxGlStyleConversionContext &context)
Parses a symbol layer as renderer or labeling.
static QString parseOpacityStops(double base, const QVariantList &stops, int maxOpacity, QgsMapBoxGlStyleConversionContext &context, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=1, double y2=1)
Takes values from stops and uses either scale_linear() or scale_exp() functions to interpolate alpha ...
static bool parseLineLayer(const QVariantMap &jsonLayer, QgsVectorTileBasicRendererStyle &style, QgsMapBoxGlStyleConversionContext &context)
Parses a line layer.
void parseRasterSource(const QVariantMap &source, const QString &name, QgsMapBoxGlStyleConversionContext *context=nullptr)
Parse a raster source from JSON.
std::unique_ptr< QgsVectorTileRenderer > renderer() const
Returns a new instance of a vector tile renderer representing the converted style,...
static void colorAsHslaComponents(const QColor &color, int &hue, int &saturation, int &lightness, int &alpha)
Takes a QColor object and returns HSLA components in required format for QGIS color_hsla() expression...
static Qt::PenCapStyle parseCapStyle(const QString &style)
Converts a value to Qt::PenCapStyle enum from JSON value.
static QString parseStringStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, const QVariantMap &conversionMap, QString *defaultString=nullptr)
Parses a list of interpolation stops containing string values.
static QgsProperty parseMatchList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a match function value list.
static QString parseStops(double base, const QVariantList &stops, double multiplier, QgsMapBoxGlStyleConversionContext &context, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential, double x1=0, double y1=0, double x2=1, double y2=1)
Parses a list of interpolation stops.
static QgsProperty parseValueList(const QVariantList &json, PropertyType type, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, int maxOpacity=255, QColor *defaultColor=nullptr, double *defaultNumber=nullptr)
Parses and converts a value list (e.g.
static QgsProperty parseInterpolatePointByZoom(const QVariantMap &json, QgsMapBoxGlStyleConversionContext &context, double multiplier=1, QPointF *defaultPoint=nullptr, QgsMapBoxGlStyleConverter::InterpolationType type=QgsMapBoxGlStyleConverter::InterpolationType::Exponential)
Interpolates a point/offset with either scale_linear() or scale_exp() (depending on base value).
static QString parseArrayStops(const QVariantList &stops, QgsMapBoxGlStyleConversionContext &context, double multiplier=1)
Takes numerical arrays from stops.
Encapsulates a MapBox GL style raster source.
Qgis::MapBoxGlStyleSourceType type() const override
Returns the source type.
QgsMapBoxGlStyleRasterSource(const QString &name)
Constructor for QgsMapBoxGlStyleRasterSource.
QgsRasterLayer * toRasterLayer() const
Returns a new raster layer representing the raster source, or nullptr if the source cannot be represe...
bool setFromJson(const QVariantMap &json, QgsMapBoxGlStyleConversionContext *context) override
Sets the source's state from a json map.
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.
QgsMapBoxGlStyleRasterSubLayer(const QString &id, const QString &source)
Constructor for QgsMapBoxGlStyleRasterSubLayer, with the given id and source.
Line symbol layer type which draws repeating marker symbols along a line feature.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
bool setSubSymbol(QgsSymbol *symbol) override
Sets layer's subsymbol. takes ownership of the passed symbol.
virtual void setSize(double size)
Sets the symbol size.
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's offset.
void setAngle(double angle)
Sets the rotation angle for the marker.
void setOffset(QPointF offset)
Sets the marker's offset, which is the horizontal and vertical displacement which the rendered marker...
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the symbol's size.
A marker symbol type, for rendering Point and MultiPoint geometries.
void setEnabled(bool enabled)
Sets whether the effect is enabled.
Contains settings for how a map layer will be labeled.
double yOffset
Vertical offset of label.
const QgsLabelObstacleSettings & obstacleSettings() const
Returns the label obstacle settings.
const QgsLabelPlacementSettings & placementSettings() const
Returns the label placement settings.
void setFormat(const QgsTextFormat &format)
Sets the label text formatting settings, e.g., font settings, buffer settings, etc.
double xOffset
Horizontal offset of label.
Qgis::LabelPlacement placement
Label placement mode.
Qgis::LabelMultiLineAlignment multilineAlign
Horizontal alignment of multi-line labels.
int priority
Label priority.
double angleOffset
Label rotation, in degrees clockwise.
const QgsLabelThinningSettings & thinningSettings() const
Returns the label thinning settings.
void setThinningSettings(const QgsLabelThinningSettings &settings)
Sets the label thinning settings.
Qgis::RenderUnit offsetUnits
Units for offsets of label.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the label's property collection, used for data defined overrides.
bool isExpression
true if this label is made from a expression string, e.g., FieldName || 'mm'
void setPlacementSettings(const QgsLabelPlacementSettings &settings)
Sets the label placement settings.
const QgsLabelLineSettings & lineSettings() const
Returns the label line settings, which contain settings related to how the label engine places and fo...
double dist
Distance from feature to the label.
Qgis::RenderUnit distUnits
Units the distance from feature to the label.
@ LinePlacementOptions
Line placement flags.
@ LabelRotation
Label rotation.
@ FontStyle
Font style name.
@ RemoveDuplicateLabelDistance
Minimum distance from labels for this feature to other labels with duplicate text.
@ FontLetterSpacing
Letter spacing.
QString fieldName
Name of field (or an expression) to use for label text.
int autoWrapLength
If non-zero, indicates that label text should be automatically wrapped to (ideally) the specified num...
const QgsLabelPointSettings & pointSettings() const
Returns the label point settings, which contain settings related to how the label engine places and f...
A grouped map of multiple QgsProperty objects, each referenced by an integer key value.
QVariant value(int key, const QgsExpressionContext &context, const QVariant &defaultValue=QVariant()) const final
Returns the calculated value of the property with the specified key from within the collection.
void setProperty(int key, const QgsProperty &property)
Adds a property to the collection and takes ownership of it.
bool isActive(int key) const final
Returns true if the collection contains an active property with the specified key.
QgsProperty property(int key) const final
Returns a matching property from the collection, if one exists.
A store for object properties.
QString asExpression() const
Returns an expression string representing the state of the property, or an empty string if the proper...
QString expressionString() const
Returns the expression used for the property value.
QVariant value(const QgsExpressionContext &context, const QVariant &defaultValue=QVariant(), bool *ok=nullptr) const
Calculates the current value of the property, including any transforms which are set for the property...
static QgsProperty fromExpression(const QString &expression, bool isActive=true)
Returns a new ExpressionBasedProperty created from the specified expression.
void setExpressionString(const QString &expression)
Sets the expression to use for the property value.
static QgsProperty fromValue(const QVariant &value, bool isActive=true)
Returns a new StaticProperty created from the specified value.
void setActive(bool active)
Sets whether the property is currently active.
static QgsProviderRegistry * instance(const QString &pluginPath=QString())
Means of accessing canonical single instance.
A fill symbol layer which fills polygons with a repeated raster image.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the unit for the image's width and height.
void setOpacity(double opacity)
Sets the opacity for the raster image used in the fill.
void setImageFilePath(const QString &imagePath)
Sets the path to the raster image used for the fill.
void setWidth(double width)
Sets the width for scaling the image used in the fill.
void setCoordinateMode(Qgis::SymbolCoordinateReference mode)
Set the coordinate mode for fill.
Represents a raster layer.
Line symbol layer type which draws line sections using a raster image file.
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
Raster marker symbol layer class.
void setOpacity(double opacity)
Set the marker opacity.
void setPath(const QString &path)
Set the marker raster image path.
@ RendererOpacity
Raster renderer global opacity.
Renders polygons using a single fill and stroke color.
void setBrushStyle(Qt::BrushStyle style)
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setStrokeWidth(double strokeWidth)
void setStrokeStyle(Qt::PenStyle strokeStyle)
void setOffsetUnit(Qgis::RenderUnit unit)
Sets the unit for the fill's offset.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setOffset(QPointF offset)
Sets an offset by which polygons will be translated during rendering.
void setStrokeColor(const QColor &strokeColor) override
Sets the stroke color for the symbol layer.
A simple line symbol layer, which renders lines using a line in a variety of styles (e....
void setPenCapStyle(Qt::PenCapStyle style)
Sets the pen cap style used to render the line (e.g.
void setUseCustomDashPattern(bool b)
Sets whether the line uses a custom dash pattern.
void setCustomDashVector(const QVector< qreal > &vector)
Sets the custom dash vector, which is the pattern of alternating drawn/skipped lengths used while ren...
void setOutputUnit(Qgis::RenderUnit unit) override
Sets the units to use for sizes and widths within the symbol layer.
void setPenJoinStyle(Qt::PenJoinStyle style)
Sets the pen join style used to render the line (e.g.
Simple marker symbol layer, consisting of a rendered shape with solid fill color and a stroke.
void setFillColor(const QColor &color) override
Sets the fill color for the symbol layer.
void setStrokeWidthUnit(Qgis::RenderUnit u)
Sets the unit for the width of the marker's stroke.
void setStrokeWidth(double w)
Sets the width of the marker's stroke.
void setStrokeColor(const QColor &color) override
Sets the marker's stroke color.
static QColor parseColor(const QString &colorStr, bool strictEval=false)
Attempts to parse a string as a color using a variety of common formats, including hex codes,...
@ File
Filename, eg for svg files.
@ CustomDash
Custom dash pattern.
@ Name
Name, eg shape name for simple markers.
@ StrokeColor
Stroke color.
@ Interval
Line marker interval.
@ StrokeWidth
Stroke width.
@ LayerEnabled
Whether symbol layer is enabled.
virtual void setColor(const QColor &color)
Sets the "representative" color for the symbol layer.
void setDataDefinedProperties(const QgsPropertyCollection &collection)
Sets the symbol layer's property collection, used for data defined overrides.
void setPlacements(Qgis::MarkerLinePlacements placements)
Sets the placement of the symbols.
Container for settings relating to a text background object.
void setMarkerSymbol(QgsMarkerSymbol *symbol)
Sets the current marker symbol for the background shape.
void setSizeType(SizeType type)
Sets the method used to determine the size of the background shape (e.g., fixed size or buffer around...
@ ShapeMarkerSymbol
Marker symbol.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the shape's size.
void setType(ShapeType type)
Sets the type of background shape to draw (e.g., square, ellipse, SVG).
void setEnabled(bool enabled)
Sets whether the text background will be drawn.
void setSize(QSizeF size)
Sets the size of the background shape.
void setColor(const QColor &color)
Sets the color for the buffer.
void setOpacity(double opacity)
Sets the buffer opacity.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units used for the buffer size.
void setEnabled(bool enabled)
Sets whether the text buffer will be drawn.
void setPaintEffect(QgsPaintEffect *effect)
Sets the current paint effect for the buffer.
void setSize(double size)
Sets the size of the buffer.
Container for all settings relating to text rendering.
void setColor(const QColor &color)
Sets the color that text will be rendered in.
void setSize(double size)
Sets the size for rendered text.
void setFont(const QFont &font)
Sets the font used for rendering text.
void setSizeUnit(Qgis::RenderUnit unit)
Sets the units for the size of rendered text.
void setBackground(const QgsTextBackgroundSettings &backgroundSettings)
Sets the text's background settings.q.
void setNamedStyle(const QString &style)
Sets the named style for the font used for rendering text.
QFont font() const
Returns the font used for rendering text.
QgsTextBufferSettings & buffer()
Returns a reference to the text buffer settings.
Configuration of a single style within QgsVectorTileBasicLabeling.
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match).
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
void setStyleName(const QString &name)
Sets human readable name of this style.
void setGeometryType(Qgis::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon).
void setLabelSettings(const QgsPalLayerSettings &settings)
Sets labeling configuration of this style.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering).
Definition of map rendering of a subset of vector tile data.
void setEnabled(bool enabled)
Sets whether this style is enabled (used for rendering).
void setMinZoomLevel(int minZoom)
Sets minimum zoom level index (negative number means no limit).
void setLayerName(const QString &name)
Sets name of the sub-layer to render (empty layer means that all layers match).
void setFilterExpression(const QString &expr)
Sets filter expression (empty filter means that all features match).
void setSymbol(QgsSymbol *sym)
Sets symbol for rendering. Takes ownership of the symbol.
void setStyleName(const QString &name)
Sets human readable name of this style.
void setMaxZoomLevel(int maxZoom)
Sets maximum zoom level index (negative number means no limit).
void setGeometryType(Qgis::GeometryType geomType)
Sets type of the geometry that will be used (point / line / polygon).
As part of the API refactoring and improvements which landed in the Processing API was substantially reworked from the x version This was done in order to allow much of the underlying Processing framework to be ported into c
QString qgsDoubleToString(double a, int precision=17)
Returns a string representation of a double.
QString qgsEnumValueToKey(const T &value, bool *returnOk=nullptr)
Returns the value for the given key of an enum.
bool qgsDoubleNear(double a, double b, double epsilon=4 *std::numeric_limits< double >::epsilon())
Compare two doubles (but allow some difference).
#define QgsDebugError(str)
QList< QgsSymbolLayer * > QgsSymbolLayerList