Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[expression] Add @map_z_range_{lower,upper} pair of variables reflecting the map's z range values #56679

Merged
merged 1 commit into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/core/expression/qgsexpressioncontextutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,13 @@ QgsExpressionContextScope *QgsExpressionContextUtils::mapSettingsScope( const Qg
// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )
Comment on lines 528 to 529
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nirvn should then not be some changes in QgsLayoutItemMap::createExpressionContext() also? Or this block should have been moved instead of copied?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@DelazJ , that was taken care of by @nyalldawson in a different PR.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. Great! Sorry for the noise.


const QgsDoubleRange zRange = mapSettings.zRange();
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_z_range_lower" ), !zRange.isInfinite() ? zRange.lower() : QVariant(), true ) );
scope->addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "map_z_range_upper" ), !zRange.isInfinite() ? zRange.upper() : QVariant(), true ) );

// IMPORTANT: ANY CHANGES HERE ALSO NEED TO BE MADE TO QgsLayoutItemMap::createExpressionContext()
// (rationale is described in QgsLayoutItemMap::createExpressionContext() )

if ( mapSettings.frameRate() >= 0 )
scope->setVariable( QStringLiteral( "frame_rate" ), mapSettings.frameRate(), true );
if ( mapSettings.currentFrame() >= 0 )
Expand Down
17 changes: 17 additions & 0 deletions tests/src/core/testqgsmapsettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,23 @@ void TestQgsMapSettings::testExpressionContext()

QCOMPARE( r.toString(), QStringLiteral( "EPSG:7030" ) );

e = QgsExpression( QStringLiteral( "@map_z_range_lower" ) );
r = e.evaluate( &c );
QVERIFY( !r.isValid() );
e = QgsExpression( QStringLiteral( "@map_z_range_upper" ) );
r = e.evaluate( &c );
QVERIFY( !r.isValid() );

ms.setZRange( QgsDoubleRange( 0.5, 100.5 ) );
c = QgsExpressionContext();
c << QgsExpressionContextUtils::mapSettingsScope( ms );
e = QgsExpression( QStringLiteral( "@map_z_range_lower" ) );
r = e.evaluate( &c );
QCOMPARE( r.toDouble(), 0.5 );
e = QgsExpression( QStringLiteral( "@map_z_range_upper" ) );
r = e.evaluate( &c );
QCOMPARE( r.toDouble(), 100.5 );

e = QgsExpression( QStringLiteral( "@map_start_time" ) );
r = e.evaluate( &c );
QVERIFY( !r.isValid() );
Expand Down
Loading