diff --git a/python/core/composer/qgscomposermap.sip b/python/core/composer/qgscomposermap.sip index 4c05d2dff9c..e1f86aca253 100644 --- a/python/core/composer/qgscomposermap.sip +++ b/python/core/composer/qgscomposermap.sip @@ -757,9 +757,12 @@ class QgsComposerMap : QgsComposerItem public slots: - /**Called if map canvas has changed*/ + /**Forces an update of the cached map image*/ void updateCachedImage(); - /**Call updateCachedImage if item is in render mode*/ + + /**Updates the cached map image if the map is set to Render mode + * @see updateCachedImage + */ void renderModeUpdateCachedImage(); /**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle */ @@ -769,4 +772,13 @@ class QgsComposerMap : QgsComposerItem void overviewExtentChanged(); virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties ); + + protected slots: + + /**Called when layers are added or removed from the layer registry. Updates the maps + * layer set and redraws the map if required. + * @note added in QGIS 2.9 + */ + void layersChanged(); + }; diff --git a/src/core/composer/qgscomposermap.cpp b/src/core/composer/qgscomposermap.cpp index a2104f854b3..dd2346ed05d 100644 --- a/src/core/composer/qgscomposermap.cpp +++ b/src/core/composer/qgscomposermap.cpp @@ -486,9 +486,8 @@ bool QgsComposerMap::shouldDrawPart( PartType part ) const return true; // for Layer } -void QgsComposerMap::updateCachedImage( void ) +void QgsComposerMap::updateCachedImage() { - syncLayerSet(); //layer list may have changed mCacheUpdated = false; cache(); QGraphicsRectItem::update(); @@ -502,6 +501,12 @@ void QgsComposerMap::renderModeUpdateCachedImage() } } +void QgsComposerMap::layersChanged() +{ + syncLayerSet(); + renderModeUpdateCachedImage(); +} + void QgsComposerMap::setCacheUpdated( bool u ) { mCacheUpdated = u; @@ -1169,8 +1174,8 @@ void QgsComposerMap::connectUpdateSlot() QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance(); if ( layerRegistry ) { - connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) ); - connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) ); + connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layersChanged() ) ); + connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layersChanged() ) ); } } diff --git a/src/core/composer/qgscomposermap.h b/src/core/composer/qgscomposermap.h index 5de3496b463..e87c2ea9a04 100644 --- a/src/core/composer/qgscomposermap.h +++ b/src/core/composer/qgscomposermap.h @@ -796,9 +796,12 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem public slots: - /**Called if map canvas has changed*/ + /**Forces an update of the cached map image*/ void updateCachedImage(); - /**Call updateCachedImage if item is in render mode*/ + + /**Updates the cached map image if the map is set to Render mode + * @see updateCachedImage + */ void renderModeUpdateCachedImage(); /**Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle */ @@ -809,6 +812,14 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties ) override; + protected slots: + + /**Called when layers are added or removed from the layer registry. Updates the maps + * layer set and redraws the map if required. + * @note added in QGIS 2.9 + */ + void layersChanged(); + private: /**Unique identifier*/