Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[maptips] optimize feature fetching, avoid long freeze
  • Loading branch information
nirvn committed Jul 19, 2018
1 parent 0fb352b commit 62347b6
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions src/gui/qgsmaptip.cpp
Expand Up @@ -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
Expand Down

0 comments on commit 62347b6

Please sign in to comment.