Followup map settings variable commit

This commit is contained in:
Nyall Dawson 2019-01-22 12:09:56 +10:00
parent f514516d07
commit 85a6b1ac92
5 changed files with 26 additions and 26 deletions

View File

@ -749,7 +749,7 @@ void QgsExpression::initVariableHelp()
sVariableHelpTexts.insert( QStringLiteral( "map_units" ), QCoreApplication::translate( "variable_help", "Units for map measurements." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_definition" ), QCoreApplication::translate( "variable_help", "Coordinate reference system of map (full definition)." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_acronym" ), QCoreApplication::translate( "variable_help", "Acronym of the coordinate reference system of the map." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_ellipsoid_acr" ), QCoreApplication::translate( "variable_help", "Acronym of the ellipsoid of the coordinate reference system of the map." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_ellipsoid" ), QCoreApplication::translate( "variable_help", "Acronym of the ellipsoid of the coordinate reference system of the map." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_proj4" ), QCoreApplication::translate( "variable_help", "Proj4 definition of the coordinate reference system." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_crs_wkt" ), QCoreApplication::translate( "variable_help", "WKT definition of the coordinate reference system." ) );
sVariableHelpTexts.insert( QStringLiteral( "map_layer_ids" ), QCoreApplication::translate( "variable_help", "List of map layer IDs visible in the map." ) );

View File

@ -1266,7 +1266,7 @@ QgsExpressionContext QgsLayoutItemMap::createExpressionContext() const
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_description" ), mapCrs.description(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapCrs.mapUnits() ), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_acronym" ), mapCrs.projectionAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_ellipsoid_acr" ), mapCrs.ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_ellipsoid" ), mapCrs.ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapCrs.toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_wkt" ), mapCrs.toWkt(), true ) );

View File

@ -1013,7 +1013,7 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_units" ), QgsUnitTypes::toString( mapSettings.mapUnits() ), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_description" ), mapSettings.destinationCrs().description(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_acronym" ), mapSettings.destinationCrs().projectionAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_ellipsoid_acr" ), mapSettings.destinationCrs().ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_ellipsoid" ), mapSettings.destinationCrs().ellipsoidAcronym(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_proj4" ), mapSettings.destinationCrs().toProj4(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_crs_wkt" ), mapSettings.destinationCrs().toWkt(), true ) );

View File

@ -626,15 +626,15 @@ void TestQgsLayoutMap::expressionContext()
r = e6.evaluate( &c );
QCOMPARE( r.toString(), QString( "longlat" ) );
//QgsExpression e7( QStringLiteral( "@map_crs_pro4" ) );
//r = e7.evaluate( &c );
//QCOMPARE( r.toString(), QString( "+proj=longlat +datum=WGS84 +no_defs" ) );
QgsExpression e7( QStringLiteral( "@map_crs_proj4" ) );
r = e7.evaluate( &c );
QCOMPARE( r.toString(), QString( "+proj=longlat +datum=WGS84 +no_defs" ) );
//QgsExpression e8( QStringLiteral( "@map_crs_wkt" ) );
//r = e8.evaluate( &c );
//QVERIFY( r.toString().length() >= 15 );
QgsExpression e8( QStringLiteral( "@map_crs_wkt" ) );
r = e8.evaluate( &c );
QVERIFY( r.toString().length() >= 15 );
QgsExpression e9( QStringLiteral( "@map_ellipsoid_acr" ) );
QgsExpression e9( QStringLiteral( "@map_crs_ellipsoid" ) );
r = e9.evaluate( &c );
QCOMPARE( r.toString(), QString( "WGS84" ) );

View File

@ -441,27 +441,27 @@ void TestQgsMapSettings::testExpressionContext()
e = QgsExpression( QStringLiteral( "@map_units" ) );
r = e.evaluate( &c );
QCOMPARE( r.toString(), QStringLiteral( "degrees" ) );\
QCOMPARE( r.toString(), QStringLiteral( "degrees" ) );
QgsExpression e5( QStringLiteral( "@map_crs_description" ) );
r = e5.evaluate( &c );
QCOMPARE( r.toString(), QString( "WGS 84" ) );
e = QgsExpression( QStringLiteral( "@map_crs_description" ) );
r = e.evaluate( &c );
QCOMPARE( r.toString(), QStringLiteral( "WGS 84" ) );
QgsExpression e6( QStringLiteral( "@map_crs_acronym" ) );
r = e6.evaluate( &c );
QCOMPARE( r.toString(), QString( "longlat" ) );
e = QgsExpression( QStringLiteral( "@map_crs_acronym" ) );
r = e.evaluate( &c );
QCOMPARE( r.toString(), QStringLiteral( "longlat" ) );
//QgsExpression e7( QStringLiteral( "@map_crs_pro4" ) );
//r = e7.evaluate( &c );
//QCOMPARE( r.toString(), QString( "+proj=longlat +datum=WGS84 +no_defs" ) );
e = QgsExpression( QStringLiteral( "@map_crs_proj4" ) );
r = e.evaluate( &c );
QCOMPARE( r.toString(), QStringLiteral( "+proj=longlat +datum=WGS84 +no_defs" ) );
//QgsExpression e8( QStringLiteral( "@map_crs_wkt" ) );
//r = e8.evaluate( &c );
//QVERIFY( r.toString().length() > 15 );
e = QgsExpression( QStringLiteral( "@map_crs_wkt" ) );
r = e.evaluate( &c );
QVERIFY( r.toString().length() > 15 );
QgsExpression e9( QStringLiteral( "@map_ellipsoid_acr" ) );
r = e9.evaluate( &c );
QCOMPARE( r.toString(), QString( "WGS84" ) );
e = QgsExpression( QStringLiteral( "@map_crs_ellipsoid" ) );
r = e.evaluate( &c );
QCOMPARE( r.toString(), QStringLiteral( "WGS84" ) );
}
QGSTEST_MAIN( TestQgsMapSettings )