Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[maptips] iterate through all matching features within radius
and return first not empty string
  • Loading branch information
nirvn committed Jul 19, 2018
1 parent c65afbd commit 6ffa39d
Showing 1 changed file with 22 additions and 14 deletions.
36 changes: 22 additions & 14 deletions src/gui/qgsmaptip.cpp
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 6ffa39d

Please sign in to comment.