Skip to content
Permalink
Browse files

[layouts] Fix item_variables function with non-lowercase item ids

Fixes #19063
  • Loading branch information
nyalldawson committed Jun 8, 2018
1 parent 262a01f commit 57c442a4430a83683721c4568dde88c5cfd659ad
Showing with 6 additions and 6 deletions.
  1. +1 −1 src/core/qgsexpressioncontext.cpp
  2. +5 −5 tests/src/core/testqgslayoutitem.cpp
@@ -677,7 +677,7 @@ class GetLayoutItemVariables : public QgsScopedExpressionFunction
if ( !mLayout )
return QVariant();

QString id = values.at( 0 ).toString().toLower();
QString id = values.at( 0 ).toString();

const QgsLayoutItem *item = mLayout->itemById( id );
if ( !item )
@@ -1403,7 +1403,7 @@ void TestQgsLayoutItem::itemVariablesFunction()
QgsRectangle extent( 2000, 2800, 2500, 2900 );
QgsLayout l( QgsProject::instance() );

QgsExpression e( QStringLiteral( "map_get( item_variables( 'map_id' ), 'map_scale' )" ) );
QgsExpression e( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_scale' )" ) );
// no map
QgsExpressionContext c = l.createExpressionContext();
QVariant r = e.evaluate( &c );
@@ -1414,21 +1414,21 @@ void TestQgsLayoutItem::itemVariablesFunction()
map->attemptSetSceneRect( QRectF( 30, 60, 200, 100 ) );
map->setExtent( extent );
l.addLayoutItem( map );
map->setId( QStringLiteral( "map_id" ) );
map->setId( QStringLiteral( "Map_id" ) );

c = l.createExpressionContext();
r = e.evaluate( &c );
QGSCOMPARENEAR( r.toDouble(), 184764103, 100 );

QgsExpression e2( QStringLiteral( "map_get( item_variables( 'map_id' ), 'map_crs' )" ) );
QgsExpression e2( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_crs' )" ) );
r = e2.evaluate( &c );
QCOMPARE( r.toString(), QString( "EPSG:4326" ) );

QgsExpression e3( QStringLiteral( "map_get( item_variables( 'map_id' ), 'map_crs_definition' )" ) );
QgsExpression e3( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_crs_definition' )" ) );
r = e3.evaluate( &c );
QCOMPARE( r.toString(), QString( "+proj=longlat +datum=WGS84 +no_defs" ) );

QgsExpression e4( QStringLiteral( "map_get( item_variables( 'map_id' ), 'map_units' )" ) );
QgsExpression e4( QStringLiteral( "map_get( item_variables( 'Map_id' ), 'map_units' )" ) );
r = e4.evaluate( &c );
QCOMPARE( r.toString(), QString( "degrees" ) );
}

0 comments on commit 57c442a

Please sign in to comment.
You can’t perform that action at this time.