@@ -955,23 +955,39 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
955
955
// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
956
956
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )
957
957
958
+ // and because people don't read that ^^, I'm going to blast it all over this function
959
+
958
960
QgsExpressionContextScope *scope = new QgsExpressionContextScope ( QObject::tr ( " Map Settings" ) );
959
961
960
962
// add known map settings context variables
961
963
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_id" ), " canvas" , true ) );
962
964
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_rotation" ), mapSettings.rotation (), true ) );
963
965
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_scale" ), mapSettings.scale (), true ) );
966
+
967
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
968
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
969
+
964
970
QgsGeometry extent = QgsGeometry::fromRect ( mapSettings.visibleExtent () );
965
971
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_extent" ), QVariant::fromValue ( extent ), true ) );
966
972
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_extent_width" ), mapSettings.visibleExtent ().width (), true ) );
967
973
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_extent_height" ), mapSettings.visibleExtent ().height (), true ) );
974
+
975
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
976
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
977
+
968
978
QgsGeometry centerPoint = QgsGeometry::fromPointXY ( mapSettings.visibleExtent ().center () );
969
979
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_extent_center" ), QVariant::fromValue ( centerPoint ), true ) );
970
980
981
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
982
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
983
+
971
984
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_crs" ), mapSettings.destinationCrs ().authid (), true ) );
972
985
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_crs_definition" ), mapSettings.destinationCrs ().toProj4 (), true ) );
973
986
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_units" ), QgsUnitTypes::toString ( mapSettings.mapUnits () ), true ) );
974
987
988
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
989
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
990
+
975
991
QVariantList layersIds;
976
992
QVariantList layers;
977
993
const QList<QgsMapLayer *> layersInMap = mapSettings.layers ();
@@ -982,11 +998,21 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
982
998
layersIds << layer->id ();
983
999
layers << QVariant::fromValue<QgsWeakMapLayerPointer>( QgsWeakMapLayerPointer ( layer ) );
984
1000
}
1001
+
1002
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
1003
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
1004
+
985
1005
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_layer_ids" ), layersIds, true ) );
986
1006
scope->addVariable ( QgsExpressionContextScope::StaticVariable ( QStringLiteral ( " map_layers" ), layers, true ) );
987
1007
1008
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
1009
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
1010
+
988
1011
scope->addFunction ( QStringLiteral ( " is_layer_visible" ), new GetLayerVisibility ( mapSettings.layers () ) );
989
1012
1013
+ // IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
1014
+ // (rationale is described in QgsLayoutItemMap::createExpressionContext() )
1015
+
990
1016
return scope;
991
1017
}
992
1018
0 commit comments