Skip to content

Commit

Permalink
qgsmapcanvas: Emit a signal when calculated render details have changed
Browse files Browse the repository at this point in the history
  • Loading branch information
ptitjano committed Nov 14, 2024
1 parent be05cf5 commit 8dcabd9
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion python/PyQt6/gui/auto_additions/qgsmapcanvas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The following has been generated automatically from src/gui/qgsmapcanvas.h
try:
QgsMapCanvas.__attribute_docs__ = {'xyCoordinates': 'Emits current mouse position\n\n.. note::\n\n changed in 1.3\n', 'scaleChanged': 'Emitted when the scale of the map changes\n', 'scaleLockChanged': 'Emitted when the scale locked state of the map changes\n\n:param locked: true if the scale is locked\n\n.. seealso:: :py:func:`setScaleLocked`\n\n.. versionadded:: 3.18\n', 'extentsChanged': 'Emitted when the extents of the map change\n', 'rotationChanged': 'Emitted when the rotation of the map changes\n', 'magnificationChanged': 'Emitted when the scale of the map changes\n', 'canvasColorChanged': 'Emitted when canvas background color changes\n', 'renderComplete': 'Emitted when the canvas has rendered.\nPasses a pointer to the painter on which the map was drawn. This is\nuseful for plugins that wish to draw on the map after it has been\nrendered. Passing the painter allows plugins to work when the map is\nbeing rendered onto a pixmap other than the mapCanvas own pixmap member.\n\n- anything related to rendering progress is not visible outside of map canvas\n- additional drawing shall be done directly within the renderer job or independently as a map canvas item\n', 'mapCanvasRefreshed': 'Emitted when canvas finished a refresh request.\n', 'renderStarting': 'Emitted when the canvas is about to be rendered.\n', 'mapRefreshCanceled': 'Emitted when the pending map refresh has been canceled\n\n.. versionadded:: 3.18\n', 'layersChanged': 'Emitted when a new set of layers has been received\n', 'keyPressed': 'Emit key press event\n', 'keyReleased': 'Emit key release event\n', 'mapToolSet': 'Emit map tool changed with the old tool\n', 'selectionChanged': 'Emitted when selection in any ``layer`` gets changed.\n\n.. note::\n\n Since QGIS 3.28 this signal is emitted for multiple layer types, including :py:class:`QgsVectorLayer` and :py:class:`QgsVectorTileLayer`\n', 'zoomLastStatusChanged': 'Emitted when zoom last status changed\n', 'zoomNextStatusChanged': 'Emitted when zoom next status changed\n', 'destinationCrsChanged': 'Emitted when map CRS has changed\n', 'transformContextChanged': 'Emitted when the canvas transform context is changed.\n', 'currentLayerChanged': 'Emitted when the current layer is changed\n', 'layerStyleOverridesChanged': 'Emitted when the configuration of overridden layer styles changes\n', 'themeChanged': 'Emitted when the canvas has been assigned a different map theme.\n\n.. seealso:: :py:func:`setTheme`\n', 'messageEmitted': 'emit a message (usually to be displayed in a message bar)\n', 'renderErrorOccurred': 'Emitted whenever an error is encountered during a map render operation.\n\nThe ``layer`` argument indicates the associated map layer, if available.\n\n.. versionadded:: 3.10.0\n', 'panDistanceBearingChanged': 'Emitted whenever the distance or bearing of an in-progress panning\noperation is changed.\n\nThis signal will be emitted during a pan operation as the user moves the map,\ngiving the total distance and bearing between the map position at the\nstart of the pan and the current pan position.\n\n.. versionadded:: 3.12\n', 'tapAndHoldGestureOccurred': 'Emitted whenever a tap and hold ``gesture`` occurs at the specified map point.\n\n.. versionadded:: 3.12\n', 'temporalRangeChanged': 'Emitted when the map canvas temporal range changes.\n\n.. versionadded:: 3.14\n', 'zRangeChanged': 'Emitted when the map canvas z (elevation) range changes.\n\n.. seealso:: :py:func:`zRange`\n\n.. seealso:: :py:func:`setZRange`\n\n.. versionadded:: 3.18\n', 'contextMenuAboutToShow': 'Emitted before the map canvas context menu will be shown.\nCan be used to extend the context menu.\n\n.. versionadded:: 3.16\n'}
QgsMapCanvas.__attribute_docs__ = {'xyCoordinates': 'Emits current mouse position\n\n.. note::\n\n changed in 1.3\n', 'scaleChanged': 'Emitted when the scale of the map changes\n', 'scaleLockChanged': 'Emitted when the scale locked state of the map changes\n\n:param locked: true if the scale is locked\n\n.. seealso:: :py:func:`setScaleLocked`\n\n.. versionadded:: 3.18\n', 'extentsChanged': 'Emitted when the extents of the map change\n', 'rotationChanged': 'Emitted when the rotation of the map changes\n', 'magnificationChanged': 'Emitted when the scale of the map changes\n', 'canvasColorChanged': 'Emitted when canvas background color changes\n', 'renderComplete': 'Emitted when the canvas has rendered.\nPasses a pointer to the painter on which the map was drawn. This is\nuseful for plugins that wish to draw on the map after it has been\nrendered. Passing the painter allows plugins to work when the map is\nbeing rendered onto a pixmap other than the mapCanvas own pixmap member.\n\n- anything related to rendering progress is not visible outside of map canvas\n- additional drawing shall be done directly within the renderer job or independently as a map canvas item\n', 'mapCanvasRefreshed': 'Emitted when canvas finished a refresh request.\n', 'renderStarting': 'Emitted when the canvas is about to be rendered.\n', 'mapRefreshCanceled': 'Emitted when the pending map refresh has been canceled\n\n.. versionadded:: 3.18\n', 'layersChanged': 'Emitted when a new set of layers has been received\n', 'keyPressed': 'Emit key press event\n', 'keyReleased': 'Emit key release event\n', 'mapToolSet': 'Emit map tool changed with the old tool\n', 'selectionChanged': 'Emitted when selection in any ``layer`` gets changed.\n\n.. note::\n\n Since QGIS 3.28 this signal is emitted for multiple layer types, including :py:class:`QgsVectorLayer` and :py:class:`QgsVectorTileLayer`\n', 'zoomLastStatusChanged': 'Emitted when zoom last status changed\n', 'zoomNextStatusChanged': 'Emitted when zoom next status changed\n', 'destinationCrsChanged': 'Emitted when map CRS has changed\n', 'transformContextChanged': 'Emitted when the canvas transform context is changed.\n', 'currentLayerChanged': 'Emitted when the current layer is changed\n', 'layerStyleOverridesChanged': 'Emitted when the configuration of overridden layer styles changes\n', 'themeChanged': 'Emitted when the canvas has been assigned a different map theme.\n\n.. seealso:: :py:func:`setTheme`\n', 'messageEmitted': 'emit a message (usually to be displayed in a message bar)\n', 'renderErrorOccurred': 'Emitted whenever an error is encountered during a map render operation.\n\nThe ``layer`` argument indicates the associated map layer, if available.\n\n.. versionadded:: 3.10.0\n', 'panDistanceBearingChanged': 'Emitted whenever the distance or bearing of an in-progress panning\noperation is changed.\n\nThis signal will be emitted during a pan operation as the user moves the map,\ngiving the total distance and bearing between the map position at the\nstart of the pan and the current pan position.\n\n.. versionadded:: 3.12\n', 'tapAndHoldGestureOccurred': 'Emitted whenever a tap and hold ``gesture`` occurs at the specified map point.\n\n.. versionadded:: 3.12\n', 'temporalRangeChanged': 'Emitted when the map canvas temporal range changes.\n\n.. versionadded:: 3.14\n', 'zRangeChanged': 'Emitted when the map canvas z (elevation) range changes.\n\n.. seealso:: :py:func:`zRange`\n\n.. seealso:: :py:func:`setZRange`\n\n.. versionadded:: 3.18\n', 'contextMenuAboutToShow': 'Emitted before the map canvas context menu will be shown.\nCan be used to extend the context menu.\n\n.. versionadded:: 3.16\n', 'calculatedRenderDetailsChanged': 'Emitted when the calculated render details of a raster have changed\n\n.. versionadded:: 3.42\n'}
QgsMapCanvas.__signal_arguments__ = {'xyCoordinates': ['p: QgsPointXY'], 'scaleChanged': ['scale: float'], 'scaleLockChanged': ['locked: bool'], 'rotationChanged': ['rotation: float'], 'magnificationChanged': ['magnification: float'], 'renderComplete': ['painter: QPainter'], 'keyPressed': ['e: QKeyEvent'], 'keyReleased': ['e: QKeyEvent'], 'mapToolSet': ['newTool: QgsMapTool', 'oldTool: QgsMapTool'], 'selectionChanged': ['layer: QgsMapLayer'], 'zoomLastStatusChanged': ['available: bool'], 'zoomNextStatusChanged': ['available: bool'], 'currentLayerChanged': ['layer: QgsMapLayer'], 'themeChanged': ['theme: str'], 'messageEmitted': ['title: str', 'message: str', 'level: Qgis.MessageLevel = Qgis.MessageLevel.Info'], 'renderErrorOccurred': ['error: str', 'layer: QgsMapLayer'], 'panDistanceBearingChanged': ['distance: float', 'unit: Qgis.DistanceUnit', 'bearing: float'], 'tapAndHoldGestureOccurred': ['mapPoint: QgsPointXY', 'gesture: QTapAndHoldGesture'], 'contextMenuAboutToShow': ['menu: QMenu', 'event: QgsMapMouseEvent']}
except NameError:
pass
7 changes: 7 additions & 0 deletions python/PyQt6/gui/auto_generated/qgsmapcanvas.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,13 @@ Emitted before the map canvas context menu will be shown.
Can be used to extend the context menu.

.. versionadded:: 3.16
%End

void calculatedRenderDetailsChanged();
%Docstring
Emitted when the calculated render details of a raster have changed

.. versionadded:: 3.42
%End

protected:
Expand Down
2 changes: 1 addition & 1 deletion python/gui/auto_additions/qgsmapcanvas.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The following has been generated automatically from src/gui/qgsmapcanvas.h
try:
QgsMapCanvas.__attribute_docs__ = {'xyCoordinates': 'Emits current mouse position\n\n.. note::\n\n changed in 1.3\n', 'scaleChanged': 'Emitted when the scale of the map changes\n', 'scaleLockChanged': 'Emitted when the scale locked state of the map changes\n\n:param locked: true if the scale is locked\n\n.. seealso:: :py:func:`setScaleLocked`\n\n.. versionadded:: 3.18\n', 'extentsChanged': 'Emitted when the extents of the map change\n', 'rotationChanged': 'Emitted when the rotation of the map changes\n', 'magnificationChanged': 'Emitted when the scale of the map changes\n', 'canvasColorChanged': 'Emitted when canvas background color changes\n', 'renderComplete': 'Emitted when the canvas has rendered.\nPasses a pointer to the painter on which the map was drawn. This is\nuseful for plugins that wish to draw on the map after it has been\nrendered. Passing the painter allows plugins to work when the map is\nbeing rendered onto a pixmap other than the mapCanvas own pixmap member.\n\n- anything related to rendering progress is not visible outside of map canvas\n- additional drawing shall be done directly within the renderer job or independently as a map canvas item\n', 'mapCanvasRefreshed': 'Emitted when canvas finished a refresh request.\n', 'renderStarting': 'Emitted when the canvas is about to be rendered.\n', 'mapRefreshCanceled': 'Emitted when the pending map refresh has been canceled\n\n.. versionadded:: 3.18\n', 'layersChanged': 'Emitted when a new set of layers has been received\n', 'keyPressed': 'Emit key press event\n', 'keyReleased': 'Emit key release event\n', 'mapToolSet': 'Emit map tool changed with the old tool\n', 'selectionChanged': 'Emitted when selection in any ``layer`` gets changed.\n\n.. note::\n\n Since QGIS 3.28 this signal is emitted for multiple layer types, including :py:class:`QgsVectorLayer` and :py:class:`QgsVectorTileLayer`\n', 'zoomLastStatusChanged': 'Emitted when zoom last status changed\n', 'zoomNextStatusChanged': 'Emitted when zoom next status changed\n', 'destinationCrsChanged': 'Emitted when map CRS has changed\n', 'transformContextChanged': 'Emitted when the canvas transform context is changed.\n', 'currentLayerChanged': 'Emitted when the current layer is changed\n', 'layerStyleOverridesChanged': 'Emitted when the configuration of overridden layer styles changes\n', 'themeChanged': 'Emitted when the canvas has been assigned a different map theme.\n\n.. seealso:: :py:func:`setTheme`\n', 'messageEmitted': 'emit a message (usually to be displayed in a message bar)\n', 'renderErrorOccurred': 'Emitted whenever an error is encountered during a map render operation.\n\nThe ``layer`` argument indicates the associated map layer, if available.\n\n.. versionadded:: 3.10.0\n', 'panDistanceBearingChanged': 'Emitted whenever the distance or bearing of an in-progress panning\noperation is changed.\n\nThis signal will be emitted during a pan operation as the user moves the map,\ngiving the total distance and bearing between the map position at the\nstart of the pan and the current pan position.\n\n.. versionadded:: 3.12\n', 'tapAndHoldGestureOccurred': 'Emitted whenever a tap and hold ``gesture`` occurs at the specified map point.\n\n.. versionadded:: 3.12\n', 'temporalRangeChanged': 'Emitted when the map canvas temporal range changes.\n\n.. versionadded:: 3.14\n', 'zRangeChanged': 'Emitted when the map canvas z (elevation) range changes.\n\n.. seealso:: :py:func:`zRange`\n\n.. seealso:: :py:func:`setZRange`\n\n.. versionadded:: 3.18\n', 'contextMenuAboutToShow': 'Emitted before the map canvas context menu will be shown.\nCan be used to extend the context menu.\n\n.. versionadded:: 3.16\n'}
QgsMapCanvas.__attribute_docs__ = {'xyCoordinates': 'Emits current mouse position\n\n.. note::\n\n changed in 1.3\n', 'scaleChanged': 'Emitted when the scale of the map changes\n', 'scaleLockChanged': 'Emitted when the scale locked state of the map changes\n\n:param locked: true if the scale is locked\n\n.. seealso:: :py:func:`setScaleLocked`\n\n.. versionadded:: 3.18\n', 'extentsChanged': 'Emitted when the extents of the map change\n', 'rotationChanged': 'Emitted when the rotation of the map changes\n', 'magnificationChanged': 'Emitted when the scale of the map changes\n', 'canvasColorChanged': 'Emitted when canvas background color changes\n', 'renderComplete': 'Emitted when the canvas has rendered.\nPasses a pointer to the painter on which the map was drawn. This is\nuseful for plugins that wish to draw on the map after it has been\nrendered. Passing the painter allows plugins to work when the map is\nbeing rendered onto a pixmap other than the mapCanvas own pixmap member.\n\n- anything related to rendering progress is not visible outside of map canvas\n- additional drawing shall be done directly within the renderer job or independently as a map canvas item\n', 'mapCanvasRefreshed': 'Emitted when canvas finished a refresh request.\n', 'renderStarting': 'Emitted when the canvas is about to be rendered.\n', 'mapRefreshCanceled': 'Emitted when the pending map refresh has been canceled\n\n.. versionadded:: 3.18\n', 'layersChanged': 'Emitted when a new set of layers has been received\n', 'keyPressed': 'Emit key press event\n', 'keyReleased': 'Emit key release event\n', 'mapToolSet': 'Emit map tool changed with the old tool\n', 'selectionChanged': 'Emitted when selection in any ``layer`` gets changed.\n\n.. note::\n\n Since QGIS 3.28 this signal is emitted for multiple layer types, including :py:class:`QgsVectorLayer` and :py:class:`QgsVectorTileLayer`\n', 'zoomLastStatusChanged': 'Emitted when zoom last status changed\n', 'zoomNextStatusChanged': 'Emitted when zoom next status changed\n', 'destinationCrsChanged': 'Emitted when map CRS has changed\n', 'transformContextChanged': 'Emitted when the canvas transform context is changed.\n', 'currentLayerChanged': 'Emitted when the current layer is changed\n', 'layerStyleOverridesChanged': 'Emitted when the configuration of overridden layer styles changes\n', 'themeChanged': 'Emitted when the canvas has been assigned a different map theme.\n\n.. seealso:: :py:func:`setTheme`\n', 'messageEmitted': 'emit a message (usually to be displayed in a message bar)\n', 'renderErrorOccurred': 'Emitted whenever an error is encountered during a map render operation.\n\nThe ``layer`` argument indicates the associated map layer, if available.\n\n.. versionadded:: 3.10.0\n', 'panDistanceBearingChanged': 'Emitted whenever the distance or bearing of an in-progress panning\noperation is changed.\n\nThis signal will be emitted during a pan operation as the user moves the map,\ngiving the total distance and bearing between the map position at the\nstart of the pan and the current pan position.\n\n.. versionadded:: 3.12\n', 'tapAndHoldGestureOccurred': 'Emitted whenever a tap and hold ``gesture`` occurs at the specified map point.\n\n.. versionadded:: 3.12\n', 'temporalRangeChanged': 'Emitted when the map canvas temporal range changes.\n\n.. versionadded:: 3.14\n', 'zRangeChanged': 'Emitted when the map canvas z (elevation) range changes.\n\n.. seealso:: :py:func:`zRange`\n\n.. seealso:: :py:func:`setZRange`\n\n.. versionadded:: 3.18\n', 'contextMenuAboutToShow': 'Emitted before the map canvas context menu will be shown.\nCan be used to extend the context menu.\n\n.. versionadded:: 3.16\n', 'calculatedRenderDetailsChanged': 'Emitted when the calculated render details of a raster have changed\n\n.. versionadded:: 3.42\n'}
QgsMapCanvas.__signal_arguments__ = {'xyCoordinates': ['p: QgsPointXY'], 'scaleChanged': ['scale: float'], 'scaleLockChanged': ['locked: bool'], 'rotationChanged': ['rotation: float'], 'magnificationChanged': ['magnification: float'], 'renderComplete': ['painter: QPainter'], 'keyPressed': ['e: QKeyEvent'], 'keyReleased': ['e: QKeyEvent'], 'mapToolSet': ['newTool: QgsMapTool', 'oldTool: QgsMapTool'], 'selectionChanged': ['layer: QgsMapLayer'], 'zoomLastStatusChanged': ['available: bool'], 'zoomNextStatusChanged': ['available: bool'], 'currentLayerChanged': ['layer: QgsMapLayer'], 'themeChanged': ['theme: str'], 'messageEmitted': ['title: str', 'message: str', 'level: Qgis.MessageLevel = Qgis.MessageLevel.Info'], 'renderErrorOccurred': ['error: str', 'layer: QgsMapLayer'], 'panDistanceBearingChanged': ['distance: float', 'unit: Qgis.DistanceUnit', 'bearing: float'], 'tapAndHoldGestureOccurred': ['mapPoint: QgsPointXY', 'gesture: QTapAndHoldGesture'], 'contextMenuAboutToShow': ['menu: QMenu', 'event: QgsMapMouseEvent']}
except NameError:
pass
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsmapcanvas.sip.in
Original file line number Diff line number Diff line change
Expand Up @@ -1260,6 +1260,13 @@ Emitted before the map canvas context menu will be shown.
Can be used to extend the context menu.

.. versionadded:: 3.16
%End

void calculatedRenderDetailsChanged();
%Docstring
Emitted when the calculated render details of a raster have changed

.. versionadded:: 3.42
%End

protected:
Expand Down
13 changes: 13 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ email : sherman at mrcc.com
#include "qgsscreenhelper.h"
#include "qgs2dmapcontroller.h"
#include "qgsoverlaywidgetlayout.h"
#include "qgsrenderedcalculatedresults.h"

/**
* \ingroup gui
Expand Down Expand Up @@ -950,6 +951,18 @@ void QgsMapCanvas::rendererJobFinished()
mRenderedItemResults = std::move( renderedItemResults );
mRenderedItemResultsOutdated = false;

for ( const QgsRenderedItemDetails *details : mRenderedItemResults->renderedItems() )
{
// if the min-max of a raster have changed - update the style and the legend
const QgsRenderedCalculatedResults *renderedDetails = dynamic_cast<const QgsRenderedCalculatedResults *>( details );
QgsMapLayer *layer = renderedDetails ? QgsProject::instance()->mapLayer( renderedDetails->layerId() ) : nullptr;
if ( layer )
{
emit calculatedRenderDetailsChanged();
break;
}
}

QImage img = mJob->renderedImage();

// emit renderComplete to get our decorations drawn
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmapcanvas.h
Original file line number Diff line number Diff line change
Expand Up @@ -1228,6 +1228,13 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView, public QgsExpressionContex
*/
void contextMenuAboutToShow( QMenu *menu, QgsMapMouseEvent *event );

/**
* Emitted when the calculated render details of a raster have changed
*
* \since QGIS 3.42
*/
void calculatedRenderDetailsChanged();

protected:

bool event( QEvent *e ) override;
Expand Down

0 comments on commit 8dcabd9

Please sign in to comment.