mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-04 00:30:59 -05:00
Fix identify menu when an expression is used as display name
This commit is contained in:
parent
ef108f3538
commit
879294df72
@ -25,6 +25,7 @@
|
||||
#include "qgslogger.h"
|
||||
#include "qgssettings.h"
|
||||
#include "qgsgui.h"
|
||||
#include "qgsexpressioncontextutils.h"
|
||||
|
||||
//TODO 4.0 add explicitly qobject parent to constructor
|
||||
QgsIdentifyMenu::QgsIdentifyMenu( QgsMapCanvas *canvas )
|
||||
@ -282,7 +283,12 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
|
||||
if ( !createMenu )
|
||||
{
|
||||
// case 1
|
||||
QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
|
||||
|
||||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
|
||||
QgsExpression exp( layer->displayExpression() );
|
||||
exp.prepare( &context );
|
||||
context.setFeature( results[0].mFeature );
|
||||
QString featureTitle = exp.evaluate( &context ).toString();
|
||||
if ( featureTitle.isEmpty() )
|
||||
featureTitle = QStringLiteral( "%1" ).arg( results[0].mFeature.id() );
|
||||
layerAction = new QAction( QStringLiteral( "%1 (%2)" ).arg( layer->name(), featureTitle ), this );
|
||||
@ -304,7 +310,11 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
|
||||
// case 2b
|
||||
else
|
||||
{
|
||||
QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
|
||||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
|
||||
QgsExpression exp( layer->displayExpression() );
|
||||
exp.prepare( &context );
|
||||
context.setFeature( results[0].mFeature );
|
||||
QString featureTitle = exp.evaluate( &context ).toString();
|
||||
if ( featureTitle.isEmpty() )
|
||||
featureTitle = QStringLiteral( "%1" ).arg( results[0].mFeature.id() );
|
||||
layerMenu = new QMenu( QStringLiteral( "%1 (%2)" ).arg( layer->name(), featureTitle ), this );
|
||||
@ -364,7 +374,11 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer *layer, const QList<QgsMapT
|
||||
}
|
||||
|
||||
// feature title
|
||||
QString featureTitle = result.mFeature.attribute( layer->displayField() ).toString();
|
||||
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( layer ) );
|
||||
QgsExpression exp( layer->displayExpression() );
|
||||
exp.prepare( &context );
|
||||
context.setFeature( result.mFeature );
|
||||
QString featureTitle = exp.evaluate( &context ).toString();
|
||||
if ( featureTitle.isEmpty() )
|
||||
featureTitle = QStringLiteral( "%1" ).arg( result.mFeature.id() );
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user