Skip to content
Permalink
Browse files
Ensure correct expression context is used in map select tools,
identify tool, map tips and vertex tool

Fixes #42006
  • Loading branch information
nyalldawson committed May 25, 2021
1 parent aba8dda commit d41c2342676098e9c9991305711b9eea748bb858
@@ -252,7 +252,11 @@ QgsFeatureIds QgsMapToolSelectUtils::getMatchingFeatures( QgsMapCanvas *canvas,
selectionGeometryEngine->prepareGeometry();

QgsRenderContext context = QgsRenderContext::fromMapSettings( canvas->mapSettings() );
context.expressionContext() << QgsExpressionContextUtils::layerScope( vlayer );

QgsExpressionContext expressionContext = canvas->createExpressionContext();
expressionContext << QgsExpressionContextUtils::layerScope( vlayer );
context.setExpressionContext( expressionContext );

std::unique_ptr< QgsFeatureRenderer > r;
if ( vlayer->renderer() )
{
@@ -430,6 +434,7 @@ void QgsMapToolSelectUtils::QgsMapToolSelectMenuActions::startFeatureSearch()
mJobData->ct = QgsCoordinateTransform( mCanvas->mapSettings().destinationCrs(), mVectorLayer->crs(), mJobData->context.transformContext() );
mJobData->featureRenderer.reset( mVectorLayer->renderer()->clone() );

mJobData->context.setExpressionContext( mCanvas->createExpressionContext() );
mJobData->context.expressionContext() << QgsExpressionContextUtils::layerScope( mVectorLayer );
mJobData->selectBehavior = mBehavior;
if ( mBehavior != QgsVectorLayer::SetSelection )
@@ -566,6 +566,7 @@ void QgsVertexTool::cadCanvasReleaseEvent( QgsMapMouseEvent *e )
}

QgsRenderContext context = QgsRenderContext::fromMapSettings( mCanvas->mapSettings() );
context.setExpressionContext( mCanvas->createExpressionContext() );
context.expressionContext() << QgsExpressionContextUtils::layerScope( vlayer );
std::unique_ptr< QgsFeatureRenderer > r;
if ( vlayer->renderer() )
@@ -239,6 +239,7 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
}

QgsRenderContext renderCtx = QgsRenderContext::fromMapSettings( mapCanvas->mapSettings() );
renderCtx.setExpressionContext( mapCanvas->createExpressionContext() );
renderCtx.expressionContext() << QgsExpressionContextUtils::layerScope( vlayer );

bool filter = false;
@@ -635,6 +635,7 @@ bool QgsMapToolIdentify::identifyVectorLayer( QList<QgsMapToolIdentify::Identify
bool filter = false;

QgsRenderContext context( QgsRenderContext::fromMapSettings( mCanvas->mapSettings() ) );
context.setExpressionContext( mCanvas->createExpressionContext() );
context.expressionContext() << QgsExpressionContextUtils::layerScope( layer );
std::unique_ptr< QgsFeatureRenderer > renderer( layer->renderer() ? layer->renderer()->clone() : nullptr );
if ( renderer )

0 comments on commit d41c234

Please sign in to comment.