Skip to content
Permalink
Browse files

Check if feature is rendered before displaying its map tips. Fixes #3…

  • Loading branch information
pblottiere committed Oct 15, 2020
1 parent 252976b commit ece1dfae221911bb4f2d802a934e632ea967b334
Showing with 22 additions and 0 deletions.
  1. +22 −0 src/gui/qgsmaptip.cpp
@@ -23,6 +23,7 @@
#include "qgswebview.h"
#include "qgswebframe.h"
#include "qgsapplication.h"
#include "qgsrenderer.h"
#include "qgsexpressioncontextutils.h"

// Qt includes
@@ -212,12 +213,30 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
exp.prepare( &context );
request.setSubsetOfAttributes( exp.referencedColumns(), vlayer->fields() );
}

QgsRenderContext renderCtx = QgsRenderContext::fromMapSettings( mapCanvas->mapSettings() );
renderCtx.expressionContext() << QgsExpressionContextUtils::layerScope( vlayer );

std::unique_ptr< QgsFeatureRenderer > renderer;
if ( vlayer->renderer() )
{
renderer.reset( vlayer->renderer()->clone() );
renderer->startRender( renderCtx, vlayer->fields() );
}

QgsFeatureIterator it = vlayer->getFeatures( request );
QElapsedTimer timer;
timer.start();
while ( it.nextFeature( feature ) )
{
context.setFeature( feature );

renderCtx.expressionContext().setFeature( feature );
if ( renderer && !renderer->willRenderFeature( feature, renderCtx ) )
{
continue;
}

if ( !mapTip.isEmpty() )
{
tipString = QgsExpression::replaceExpressionText( mapTip, &context );
@@ -233,6 +252,9 @@ QString QgsMapTip::fetchFeature( QgsMapLayer *layer, QgsPointXY &mapPosition, Qg
}
}

if ( renderer )
renderer->stopRender( renderCtx );

return tipString;
}

0 comments on commit ece1dfa

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