Skip to content
Permalink
Browse files

When only one feature is selected during a selection operation,

show the feature's display expression/field value in the
status bar as part of the "... features selected" message
  • Loading branch information
nyalldawson committed Mar 15, 2021
1 parent 5bceda8 commit e44f8a76e2024d8920e7255f5c0a03c204b118de
Showing with 26 additions and 1 deletion.
  1. +26 −1 src/app/qgisapp.cpp
@@ -97,6 +97,7 @@
#include "qgsmeshlayertemporalproperties.h"
#include "qgsvectorlayersavestyledialog.h"
#include "maptools/qgsappmaptools.h"
#include "qgsexpressioncontextutils.h"

#include "qgsanalysis.h"
#include "qgsgeometrycheckregistry.h"
QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( layer );
if ( vlayer )
{
showStatusMessage( tr( "%n feature(s) selected on layer %1.", "number of selected features", vlayer->selectedFeatureCount() ).arg( vlayer->name() ) );
const int selectedCount = vlayer->selectedFeatureCount();
if ( selectedCount == 1 )
{
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vlayer ) );
QgsExpression exp = vlayer->displayExpression();
exp.prepare( &context );

QgsFeatureRequest request = QgsFeatureRequest().setSubsetOfAttributes( exp.referencedColumns(), vlayer->fields() );
if ( !exp.needsGeometry() )
request.setFlags( request.flags() | QgsFeatureRequest::NoGeometry );

QgsFeature feat;
QgsFeatureIterator featureIt = vlayer->getSelectedFeatures( request );
while ( featureIt.nextFeature( feat ) )
{
context.setFeature( feat );
QString featureTitle = exp.evaluate( &context ).toString();
showStatusMessage( tr( "1 feature selected on layer %1 (%2)." ).arg( vlayer->name(), featureTitle ) );
break;
}
}
else
{
showStatusMessage( tr( "%n features selected on layer %1.", "number of selected features", selectedCount ).arg( vlayer->name() ) );
}
}
if ( layer == activeLayer() )
{

0 comments on commit e44f8a7

Please sign in to comment.