Skip to content
Permalink
Browse files

[maptips] optimize feature fetching, avoid long freeze

  • Loading branch information
nirvn committed Jul 18, 2018
1 parent 3e6db63 commit 516705417d85ecbc0b33d0d35d63f1315ba45bf6
Showing with 14 additions and 7 deletions.
  1. +14 −7 src/gui/qgsmaptip.cpp
@@ -183,30 +183,37 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
context.appendScope( QgsExpressionContextUtils::mapSettingsScope( mapCanvas->mapSettings() ) );

QString mapTip = vlayer->mapTipTemplate();
QString tipString;
QgsExpression exp( vlayer->displayExpression() );
QgsFeature feature;
QgsFeatureIterator it = vlayer->getFeatures( QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect ) );
QgsFeatureRequest request = QgsFeatureRequest().setFilterRect( r ).setFlags( QgsFeatureRequest::ExactIntersect );
if ( mapTip.isEmpty() )
{
exp.prepare( &context );
request.setSubsetOfAttributes( exp.referencedColumns(), vlayer->fields() );
}
QgsFeatureIterator it = vlayer->getFeatures( request );
QTime timer;
timer.start();
while ( it.nextFeature( feature ) )
{
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() )
if ( !tipString.isEmpty() || timer.elapsed() >= 1000 )
{
return tipString;
break;
}
}

return QString();
return tipString;
}

// This slot handles all clicks

0 comments on commit 5167054

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