Skip to content

Commit

Permalink
[needs-docs] Rename map_layers_ids to map_layer_ids
Browse files Browse the repository at this point in the history
It's more natural grammar
  • Loading branch information
nyalldawson committed Aug 27, 2018
1 parent 820c40a commit ff9e389
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions src/core/expression/qgsexpression.cpp
Expand Up @@ -743,6 +743,8 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts.insert( QStringLiteral( "map_crs" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of map (e.g., 'EPSG:4326')." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_definition" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of map (full definition)." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_units" ), QCoreApplication::translate( "variable_help", "Units for map measurements." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_layer_ids" ), QCoreApplication::translate( "variable_help", "List of map layer IDs visible in the map." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_layers" ), QCoreApplication::translate( "variable_help", "List of map layers visible in the map." ) );

sVariableHelpTexts.insert( QStringLiteral( "row_number" ), QCoreApplication::translate( "variable_help", "Stores the number of the current row." ) );
sVariableHelpTexts.insert( QStringLiteral( "grid_number" ), QCoreApplication::translate( "variable_help", "Current grid annotation value." ) );
Expand Down
6 changes: 3 additions & 3 deletions src/core/layout/qgslayoutitemmap.cpp
Expand Up @@ -1157,12 +1157,12 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const

QVariantList layersIds;
QVariantList layers;
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layer_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers" ), layers, true ) );

context.appendScope( scope );

// The scope map_layers_ids and map_layers variables have been added to the context, only now we can
// The scope map_layer_ids and map_layers variables have been added to the context, only now we can
// call layersToRender (just in case layersToRender relies on evaluating an expression which uses
// other variables contained within the map settings scope
const QList<QgsMapLayer *> layersInMap = layersToRender( &context );
Expand All @@ -1174,7 +1174,7 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const
layersIds << layer->id();
layers << QVariant::fromValue<QgsWeakMapLayerPointer>( QgsWeakMapLayerPointer( layer ) );
}
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layer_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers" ), layers, true ) );

return context;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsexpressioncontext.cpp
Expand Up @@ -1005,7 +1005,7 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
layersIds << layer->id();
layers << QVariant::fromValue<QgsWeakMapLayerPointer>( QgsWeakMapLayerPointer( layer ) );
}
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layer_ids" ), layersIds, true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_layers" ), layers, true ) );

scope->addFunction( QStringLiteral( "is_layer_visible" ), new GetLayerVisibility( mapSettings.layers() ) );
Expand Down
2 changes: 1 addition & 1 deletion tests/src/core/testqgslayoutitem.cpp
Expand Up @@ -1435,7 +1435,7 @@ void TestQgsLayoutItem::itemVariablesFunction()
std::unique_ptr< QgsVectorLayer > layer = qgis::make_unique< QgsVectorLayer >( QStringLiteral( "Point?field=id_a:integer" ), QStringLiteral( "A" ), QStringLiteral( "memory" ) );
std::unique_ptr< QgsVectorLayer > layer2 = qgis::make_unique< QgsVectorLayer >( QStringLiteral( "Point?field=id_a:integer" ), QStringLiteral( "B" ), QStringLiteral( "memory" ) );
map->setLayers( QList<QgsMapLayer *>() << layer.get() << layer2.get() );
QgsExpression e5( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_layers_ids' )" ) );
QgsExpression e5( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_layer_ids' )" ) );
r = e5.evaluate( &c );
QCOMPARE( r.toStringList().join( ',' ), QStringLiteral( "%1,%2" ).arg( layer->id(), layer2->id() ) );
e5 = QgsExpression( QStringLiteral( "array_foreach(map_get( item_variables( 'Map_id' ), 'map_layers' ), layer_property(@element, 'name'))" ) );
Expand Down

0 comments on commit ff9e389

Please sign in to comment.