Skip to content

Commit

Permalink
[maptips] iterate through all matching features within radius
Browse files Browse the repository at this point in the history
and return first not empty string
  • Loading branch information
nirvn committed Jul 19, 2018
1 parent abcee3a commit 1f3b7d1
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/gui/qgsmaptip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,27 +181,35 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg

r = mapCanvas->mapSettings().mapToLayerCoordinates( layer, r );

QgsFeature feature;

if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) ).nextFeature( feature ) )
return QString();

QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vlayer ) );
if ( mapCanvas )
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mapCanvas->mapSettings() ) );

context.setFeature( feature );

QString mapTip = vlayer->mapTipTemplate();
if ( !mapTip.isEmpty() )
{
return QgsExpression::replaceExpressionText( mapTip, &context );
}
else
QgsFeature feature;
QgsFeatureIterator it = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) );
while ( it.nextFeature( feature ) )
{
QgsExpression exp( vlayer->displayExpression() );
return exp.evaluate( &context ).toString();
QString tipString;

context.setFeature( feature );
if ( !mapTip.isEmpty() )
{
tipString = QgsExpression::replaceExpressionText( mapTip, &context );
}
else
{
QgsExpression exp( vlayer->displayExpression() );
tipString = exp.evaluate( &context ).toString();
}

if ( !tipString.isEmpty() )
{
return tipString;
}
}

return QString();
}

//This slot handles all clicks
Expand Down

0 comments on commit 1f3b7d1

Please sign in to comment.