From b3c1719e98121f497499ea92297a9e66de55cb38 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 12 Aug 2019 11:01:28 +1000 Subject: [PATCH] Fix unnecessary layer reloads triggering after project load, which also causes a leak --- python/gui/auto_generated/qgsmapcanvas.sip.in | 20 ++++++++++++++++++- src/app/layout/qgslayoutdesignerdialog.cpp | 2 +- src/app/qgsstatusbarcoordinateswidget.cpp | 2 +- src/gui/qgsmapcanvas.cpp | 11 +++++++--- src/gui/qgsmapcanvas.h | 17 +++++++++++++++- 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/python/gui/auto_generated/qgsmapcanvas.sip.in b/python/gui/auto_generated/qgsmapcanvas.sip.in index 5b7da7d57a8..77951733150 100644 --- a/python/gui/auto_generated/qgsmapcanvas.sip.in +++ b/python/gui/auto_generated/qgsmapcanvas.sip.in @@ -728,9 +728,27 @@ Repaints the canvas map void refreshAllLayers(); %Docstring -Reload all layers, clear the cache and refresh the canvas +Reload all layers (including refreshing layer properties from their data sources), +clears the cache and refreshes the canvas. + +.. note:: + + Consider using the less expensive redrawAllLayers() method if a layer reload + from the data provider is not required. .. versionadded:: 2.9 +%End + + void redrawAllLayers(); +%Docstring +Clears all cached images and redraws all layers. + +.. note:: + + Unlike refreshAllLayers(), this does NOT reload layers themselves, and accordingly + is more "lightweight". Use this method when only an update of the layer's renderers is required. + +.. versionadded:: 3.10 %End void selectionChangedSlot(); diff --git a/src/app/layout/qgslayoutdesignerdialog.cpp b/src/app/layout/qgslayoutdesignerdialog.cpp index 9378591774b..b4ee6e593ff 100644 --- a/src/app/layout/qgslayoutdesignerdialog.cpp +++ b/src/app/layout/qgslayoutdesignerdialog.cpp @@ -4308,7 +4308,7 @@ void QgsLayoutDesignerDialog::atlasFeatureChanged( const QgsFeature &feature ) mapCanvas->expressionContextScope().addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_featureid" ), feature.id(), true ) ); mapCanvas->expressionContextScope().addVariable( QgsExpressionContextScope::StaticVariable( QStringLiteral( "atlas_geometry" ), QVariant::fromValue( feature.geometry() ), true ) ); mapCanvas->stopRendering(); - mapCanvas->refreshAllLayers(); + mapCanvas->redrawAllLayers(); mView->setSectionLabel( atlas->nameForPage( atlas->currentFeatureNumber() ) ); } diff --git a/src/app/qgsstatusbarcoordinateswidget.cpp b/src/app/qgsstatusbarcoordinateswidget.cpp index 56cbc560ed2..a722f05db85 100644 --- a/src/app/qgsstatusbarcoordinateswidget.cpp +++ b/src/app/qgsstatusbarcoordinateswidget.cpp @@ -280,7 +280,7 @@ void QgsStatusBarCoordinatesWidget::refreshMapCanvas() //stop any current rendering mMapCanvas->stopRendering(); - mMapCanvas->refreshAllLayers(); + mMapCanvas->redrawAllLayers(); } void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p ) diff --git a/src/gui/qgsmapcanvas.cpp b/src/gui/qgsmapcanvas.cpp index 386536e993a..e31da4fd361 100644 --- a/src/gui/qgsmapcanvas.cpp +++ b/src/gui/qgsmapcanvas.cpp @@ -154,10 +154,10 @@ QgsMapCanvas::QgsMapCanvas( QWidget *parent ) } ); // refresh canvas when a remote svg/image has finished downloading - connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsMapCanvas::refreshAllLayers ); - connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsMapCanvas::refreshAllLayers ); + connect( QgsApplication::svgCache(), &QgsSvgCache::remoteSvgFetched, this, &QgsMapCanvas::redrawAllLayers ); + connect( QgsApplication::imageCache(), &QgsImageCache::remoteImageFetched, this, &QgsMapCanvas::redrawAllLayers ); // refresh canvas when project color scheme is changed -- if layers use project colors, they need to be redrawn - connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsMapCanvas::refreshAllLayers ); + connect( QgsProject::instance(), &QgsProject::projectColorsChanged, this, &QgsMapCanvas::redrawAllLayers ); //segmentation parameters QgsSettings settings; @@ -2211,6 +2211,11 @@ void QgsMapCanvas::refreshAllLayers() layer->reload(); } + redrawAllLayers(); +} + +void QgsMapCanvas::redrawAllLayers() +{ // clear the cache clearCache(); diff --git a/src/gui/qgsmapcanvas.h b/src/gui/qgsmapcanvas.h index bb21051d8f3..8205a15c6c8 100644 --- a/src/gui/qgsmapcanvas.h +++ b/src/gui/qgsmapcanvas.h @@ -645,11 +645,26 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView void refresh(); /** - * Reload all layers, clear the cache and refresh the canvas + * Reload all layers (including refreshing layer properties from their data sources), + * clears the cache and refreshes the canvas. + * + * \note Consider using the less expensive redrawAllLayers() method if a layer reload + * from the data provider is not required. + * * \since QGIS 2.9 */ void refreshAllLayers(); + /** + * Clears all cached images and redraws all layers. + * + * \note Unlike refreshAllLayers(), this does NOT reload layers themselves, and accordingly + * is more "lightweight". Use this method when only an update of the layer's renderers is required. + * + * \since QGIS 3.10 + */ + void redrawAllLayers(); + //! Receives signal about selection change, and pass it on with layer info void selectionChangedSlot();