Skip to content
Permalink
Browse files

Don't show label hover highlights while a map redraw is in progress,

because these will show for outdated label positions
  • Loading branch information
nyalldawson committed Mar 15, 2021
1 parent 879f892 commit 5bceda82fe10b35bb6c4ff9677d1cd281c66650f
@@ -106,9 +106,12 @@ Resets the ``flags`` for the canvas' map settings.
.. versionadded:: 3.0
%End

const QgsLabelingResults *labelingResults() const;
const QgsLabelingResults *labelingResults( bool allowOutdatedResults = true ) const;
%Docstring
Gets access to the labeling results (may be ``None``)
Gets access to the labeling results (may be ``None``).

Since QGIS 3.20, if the ``allowOutdatedResults`` flag is ``False`` then outdated labeling results (e.g.
as a result of an ongoing canvas render) will not be returned, and instead ``None`` will be returned.

.. versionadded:: 2.4
%End
@@ -62,7 +62,7 @@ void QgsMapToolLabel::deactivate()
bool QgsMapToolLabel::labelAtPosition( QMouseEvent *e, QgsLabelPosition &p )
{
QgsPointXY pt = toMapCoordinates( e->pos() );
const QgsLabelingResults *labelingResults = mCanvas->labelingResults();
const QgsLabelingResults *labelingResults = mCanvas->labelingResults( false );
if ( !labelingResults )
return false;

@@ -123,7 +123,7 @@ bool QgsMapToolLabel::labelAtPosition( QMouseEvent *e, QgsLabelPosition &p )
bool QgsMapToolLabel::calloutAtPosition( QMouseEvent *e, QgsCalloutPosition &p, bool &isOrigin )
{
QgsPointXY pt = toMapCoordinates( e->pos() );
const QgsLabelingResults *labelingResults = mCanvas->labelingResults();
const QgsLabelingResults *labelingResults = mCanvas->labelingResults( false );
if ( !labelingResults )
return false;

@@ -167,10 +167,9 @@ void QgsMapToolPinLabels::highlightPinnedLabels()
QgsDebugMsg( QStringLiteral( "Highlighting pinned labels" ) );

// get list of all drawn labels from all layers within given extent
const QgsLabelingResults *labelingResults = mCanvas->labelingResults();
const QgsLabelingResults *labelingResults = mCanvas->labelingResults( false );
if ( !labelingResults )
{
QgsDebugMsg( QStringLiteral( "No labeling engine" ) );
return;
}

@@ -238,10 +237,9 @@ void QgsMapToolPinLabels::pinUnpinLabels( const QgsRectangle &ext, QMouseEvent *
bool toggleUnpinOrPin = e->modifiers() & Qt::ControlModifier;

// get list of all drawn labels from all layers within, or touching, chosen extent
const QgsLabelingResults *labelingResults = mCanvas->labelingResults();
const QgsLabelingResults *labelingResults = mCanvas->labelingResults( false );
if ( !labelingResults )
{
QgsDebugMsg( QStringLiteral( "No labeling engine" ) );
return;
}

@@ -284,10 +284,9 @@ bool QgsMapToolShowHideLabels::selectedLabelFeatures( QgsVectorLayer *vlayer,
listPos.clear();

// get list of all drawn labels from current layer that intersect rubberband
const QgsLabelingResults *labelingResults = mCanvas->labelingResults();
const QgsLabelingResults *labelingResults = mCanvas->labelingResults( false );
if ( !labelingResults )
{
QgsDebugMsg( QStringLiteral( "No labeling engine" ) );
return false;
}

@@ -469,8 +469,11 @@ void QgsMapCanvas::setMapSettingsFlags( QgsMapSettings::Flags flags )
refresh();
}

const QgsLabelingResults *QgsMapCanvas::labelingResults() const
const QgsLabelingResults *QgsMapCanvas::labelingResults( bool allowOutdatedResults ) const
{
if ( !allowOutdatedResults && mLabelingResultsOutdated )
return nullptr;

return mLabelingResults.get();
}

@@ -567,6 +570,8 @@ void QgsMapCanvas::refresh()

// schedule a refresh
mRefreshTimer->start( 1 );

mLabelingResultsOutdated = true;
}

void QgsMapCanvas::refreshMap()
@@ -692,6 +697,7 @@ void QgsMapCanvas::rendererJobFinished()
{
mLabelingResults.reset( mJob->takeLabelingResults() );
}
mLabelingResultsOutdated = false;

QImage img = mJob->renderedImage();

@@ -161,10 +161,14 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
void setMapSettingsFlags( QgsMapSettings::Flags flags );

/**
* Gets access to the labeling results (may be NULLPTR)
* Gets access to the labeling results (may be NULLPTR).
*
* Since QGIS 3.20, if the \a allowOutdatedResults flag is FALSE then outdated labeling results (e.g.
* as a result of an ongoing canvas render) will not be returned, and instead NULLPTR will be returned.
*
* \since QGIS 2.4
*/
const QgsLabelingResults *labelingResults() const;
const QgsLabelingResults *labelingResults( bool allowOutdatedResults = true ) const;

/**
* Set whether to cache images of rendered layers
@@ -1255,6 +1259,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Labeling results from the recently rendered map
std::unique_ptr< QgsLabelingResults > mLabelingResults;

//! TRUE if the labeling results stored in mLabelingResults are outdated (e.g. as a result of an ongoing canvas render)
bool mLabelingResultsOutdated = false;

//! Whether layers are rendered sequentially or in parallel
bool mUseParallelRendering = false;

0 comments on commit 5bceda8

Please sign in to comment.