Skip to content

Commit

Permalink
Fix new map canvas CRS is not accessible to QgsMapCanvasItem subclasses
Browse files Browse the repository at this point in the history
in QgsMapCanvasItem::updatePosition() when this function is called
as a result of map canvas CRS changes
  • Loading branch information
nyalldawson committed Jan 18, 2021
1 parent a9b89d3 commit dc740eb
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -417,11 +417,16 @@ void QgsMapCanvas::setDestinationCrs( const QgsCoordinateReferenceSystem &crs )

if ( !rect.isEmpty() )
{
// we will be manually calling updateCanvasItemPositions() later, AFTER setting the updating the mSettings destination CRS, and we don't
// want to do that twice!
mBlockItemPositionUpdates++;
setExtent( rect );
mBlockItemPositionUpdates--;
}

mSettings.setDestinationCrs( crs );
updateScale();
updateCanvasItemPositions();

QgsDebugMsgLevel( QStringLiteral( "refreshing after destination CRS changed" ), 2 );
refresh();
Expand Down Expand Up @@ -1996,6 +2001,9 @@ void QgsMapCanvas::paintEvent( QPaintEvent *e )

void QgsMapCanvas::updateCanvasItemPositions()
{
if ( mBlockItemPositionUpdates )
return;

const QList<QGraphicsItem *> items = mScene->items();
for ( QGraphicsItem *gi : items )
{
Expand Down
2 changes: 2 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -1304,6 +1304,8 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

QList< QgsMapCanvasInteractionBlocker * > mInteractionBlockers;

int mBlockItemPositionUpdates = 0;

/**
* Returns the last cursor position on the canvas in geographical coordinates
* \since QGIS 3.4
Expand Down

0 comments on commit dc740eb

Please sign in to comment.