Fix unnecessary layer reloads triggering after project load, which

also causes a leak
This commit is contained in:
Nyall Dawson 2019-08-12 11:01:28 +10:00
parent e3ad35bb32
commit b3c1719e98
5 changed files with 45 additions and 7 deletions

View File

@ -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();

View File

@ -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() ) );
}

View File

@ -280,7 +280,7 @@ void QgsStatusBarCoordinatesWidget::refreshMapCanvas()
//stop any current rendering
mMapCanvas->stopRendering();
mMapCanvas->refreshAllLayers();
mMapCanvas->redrawAllLayers();
}
void QgsStatusBarCoordinatesWidget::showMouseCoordinates( const QgsPointXY &p )

View File

@ -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();

View File

@ -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();