Skip to content
Permalink
Browse files

[maptips] iterate through all matching features within radius

and return first not empty string
  • Loading branch information
nirvn committed Jul 17, 2018
1 parent c65afbd commit 6ffa39d75060ee02acbfcd4bc55e535678f23581
Showing with 22 additions and 14 deletions.
  1. +22 −14 src/gui/qgsmaptip.cpp
@@ -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

0 comments on commit 6ffa39d

Please sign in to comment.
You can’t perform that action at this time.