Skip to content

Commit f82b8c6

Browse files
committedAug 24, 2015
[identify menu] display feature title next to layer title when single feature is identified
1 parent 4611465 commit f82b8c6

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed
 

‎src/gui/qgsidentifymenu.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,10 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapT
271271
if ( !createMenu )
272272
{
273273
// case 1
274-
layerAction = new QAction( layer->name(), this );
274+
QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
275+
if ( featureTitle.isEmpty() )
276+
featureTitle = QString( "%1" ).arg( results[0].mFeature.id() );
277+
layerAction = new QAction( QString( "%1 (%2)" ).arg( layer->name() ).arg( featureTitle ), this );
275278
}
276279
else
277280
{
@@ -282,8 +285,20 @@ void QgsIdentifyMenu::addVectorLayer( QgsVectorLayer* layer, const QList<QgsMapT
282285
}
283286
else
284287
{
285-
// case 2
286-
layerMenu = new QMenu( layer->name(), this );
288+
// case 2a
289+
if ( results.count() > 1 )
290+
{
291+
layerMenu = new QMenu( layer->name(), this );
292+
layerAction = layerMenu->menuAction();
293+
}
294+
// case 2b
295+
else
296+
{
297+
QString featureTitle = results[0].mFeature.attribute( layer->displayField() ).toString();
298+
if ( featureTitle.isEmpty() )
299+
featureTitle = QString( "%1" ).arg( results[0].mFeature.id() );
300+
layerMenu = new QMenu( QString( "%1 (%2)" ).arg( layer->name() ).arg( featureTitle ), this );
301+
}
287302
layerAction = layerMenu->menuAction();
288303
}
289304
}

0 commit comments

Comments
 (0)
Please sign in to comment.