Skip to content

Commit 1f3b7d1

Browse files
committed
[maptips] iterate through all matching features within radius
and return first not empty string
1 parent abcee3a commit 1f3b7d1

File tree

1 file changed

+22
-14
lines changed

1 file changed

+22
-14
lines changed

src/gui/qgsmaptip.cpp

Lines changed: 22 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,27 +181,35 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
181181

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

184-
QgsFeature feature;
185-
186-
if ( !vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) ).nextFeature( feature ) )
187-
return QString();
188-
189184
QgsExpressionContext context( QgsExpressionContextUtils::globalProjectLayerScopes( vlayer ) );
190185
if ( mapCanvas )
191186
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mapCanvas->mapSettings() ) );
192187

193-
context.setFeature( feature );
194-
195188
QString mapTip = vlayer->mapTipTemplate();
196-
if ( !mapTip.isEmpty() )
197-
{
198-
return QgsExpression::replaceExpressionText( mapTip, &context );
199-
}
200-
else
189+
QgsFeature feature;
190+
QgsFeatureIterator it = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) );
191+
while ( it.nextFeature( feature ) )
201192
{
202-
QgsExpression exp( vlayer->displayExpression() );
203-
return exp.evaluate( &context ).toString();
193+
QString tipString;
194+
195+
context.setFeature( feature );
196+
if ( !mapTip.isEmpty() )
197+
{
198+
tipString = QgsExpression::replaceExpressionText( mapTip, &context );
199+
}
200+
else
201+
{
202+
QgsExpression exp( vlayer->displayExpression() );
203+
tipString = exp.evaluate( &context ).toString();
204+
}
205+
206+
if ( !tipString.isEmpty() )
207+
{
208+
return tipString;
209+
}
204210
}
211+
212+
return QString();
205213
}
206214

207215
//This slot handles all clicks

0 commit comments

Comments
 (0)