diff --git a/src/app/qgisapp.cpp b/src/app/qgisapp.cpp index a4a5d942c682..149b8c05cd25 100644 --- a/src/app/qgisapp.cpp +++ b/src/app/qgisapp.cpp @@ -446,6 +446,8 @@ #include "devtools/querylogger/qgsappquerylogger.h" #include "devtools/querylogger/qgsqueryloggerwidgetfactory.h" #include "devtools/profiler/qgsprofilerwidgetfactory.h" +#include "qgsrendereditemresults.h" +#include "qgsrenderedcalculatedresults.h" #include "browser/qgsinbuiltdataitemproviders.h" @@ -1071,6 +1073,7 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipBadLayers mMapCanvas = new QgsMapCanvas( centralWidget ); mMapCanvas->setObjectName( QStringLiteral( "theMapCanvas" ) ); mMapCanvas->setFlags( Qgis::MapCanvasFlag::ShowMainAnnotationLayer ); + connect( mMapCanvas, &QgsMapCanvas::calculatedRenderDetailsChanged, this, &QgisApp::onCalculatedRenderDetailsChanged ); // before anything, let's freeze canvas redraws QgsCanvasRefreshBlocker refreshBlocker; @@ -17588,3 +17591,38 @@ void QgisApp::showEvent( QShowEvent *event ) } } ); } + +void QgisApp::onCalculatedRenderDetailsChanged() +{ + const QgsRenderedItemResults *renderedItemResults = mMapCanvas->renderedItemResults( false ); + if ( !renderedItemResults ) + { + return; + } + + const QList items = renderedItemResults->renderedItems(); + QList computedLayerIds; + for ( const QgsRenderedItemDetails *item : renderedItemResults->renderedItems() ) + { + if ( const QgsRenderedCalculatedResults *calculatedResults = dynamic_cast< const QgsRenderedCalculatedResults *>( item ) ) + { + computedLayerIds.append( calculatedResults->layerId() ); + } + } + + if ( !computedLayerIds.empty() ) + { + for ( QgsMapLayer *layer : mMapCanvas->layers() ) + { + // refresh the legend and style of the raster layer + if ( QgsRasterLayer *rasterLayer = qobject_cast( layer ) ) + { + if ( computedLayerIds.contains( rasterLayer->id() ) ) + { + rasterLayer->emitStyleChanged(); + emit rasterLayer->rendererChanged(); + } + } + } + } +} diff --git a/src/app/qgisapp.h b/src/app/qgisapp.h index 7514bb96ccde..ce3323bd985b 100644 --- a/src/app/qgisapp.h +++ b/src/app/qgisapp.h @@ -1445,6 +1445,8 @@ class APP_EXPORT QgisApp : public QMainWindow, private Ui::MainWindow void onSnappingConfigChanged(); + void onCalculatedRenderDetailsChanged(); + /** * Triggers validation of the specified \a crs. */ diff --git a/src/core/raster/qgsrasterlayer.cpp b/src/core/raster/qgsrasterlayer.cpp index 04f70f668ed2..bc518636fc0f 100644 --- a/src/core/raster/qgsrasterlayer.cpp +++ b/src/core/raster/qgsrasterlayer.cpp @@ -1613,9 +1613,6 @@ bool QgsRasterLayer::refreshRenderer( QgsRasterRenderer *rasterRenderer, const Q } } - emit repaintRequested(); - emitStyleChanged(); - emit rendererChanged(); return true; } @@ -1650,8 +1647,6 @@ bool QgsRasterLayer::refreshRenderer( QgsRasterRenderer *rasterRenderer, const Q } } - emitStyleChanged(); - emit rendererChanged(); refreshed = true; } }