Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
When running a map action and clicking over multiple features, ensure
the popup feature menu uses the layer's defined display expression instead
of just showing raw feature ids

This matches the same menu behavior as the identify tool uses
  • Loading branch information
nyalldawson committed Oct 21, 2020
1 parent 3019b82 commit e304d4d
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/app/qgsmaptoolfeatureaction.cpp
Expand Up @@ -138,10 +138,19 @@ bool QgsMapToolFeatureAction::doAction( QgsVectorLayer *layer, int x, int y )
}
else
{
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
QgsExpression exp( layer->displayExpression() );
exp.prepare( &context );

QMenu *featureMenu = new QMenu();
for ( const QgsFeature &feature : qgis::as_const( features ) )
{
QAction *featureAction = featureMenu->addAction( FID_TO_STRING( feature.id() ) );
context.setFeature( feature );
QString featureTitle = exp.evaluate( &context ).toString();
if ( featureTitle.isEmpty() )
featureTitle = FID_TO_STRING( feature.id() );

QAction *featureAction = featureMenu->addAction( featureTitle );
connect( featureAction, &QAction::triggered, this, [ = ] { doActionForFeature( layer, feature, point );} );
}
QAction *allFeatureAction = featureMenu->addAction( tr( "All Features" ) );
Expand Down

0 comments on commit e304d4d

Please sign in to comment.