Skip to content

Commit 837c7ee

Browse files
committed
[composer] Don't redraw map if layers change and map is set to cached
Previously map was being redrawn every time a layer was added or removed from the registry, which blocked the ui until the map redraw is complete. Now the map will only be redrawn as a result of layer changes if it's set to Render mode. Possible fix for 12234 and 12125. (refs #12234, #12125)
1 parent 012ee0b commit 837c7ee

File tree

3 files changed

+36
-8
lines changed

3 files changed

+36
-8
lines changed

python/core/composer/qgscomposermap.sip

+14-2
Original file line numberDiff line numberDiff line change
@@ -757,9 +757,12 @@ class QgsComposerMap : QgsComposerItem
757757

758758
public slots:
759759

760-
/**Called if map canvas has changed*/
760+
/**Forces an update of the cached map image*/
761761
void updateCachedImage();
762-
/**Call updateCachedImage if item is in render mode*/
762+
763+
/**Updates the cached map image if the map is set to Render mode
764+
* @see updateCachedImage
765+
*/
763766
void renderModeUpdateCachedImage();
764767

765768
/**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
769772
void overviewExtentChanged();
770773

771774
virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties );
775+
776+
protected slots:
777+
778+
/**Called when layers are added or removed from the layer registry. Updates the maps
779+
* layer set and redraws the map if required.
780+
* @note added in QGIS 2.9
781+
*/
782+
void layersChanged();
783+
772784
};

src/core/composer/qgscomposermap.cpp

+9-4
Original file line numberDiff line numberDiff line change
@@ -486,9 +486,8 @@ bool QgsComposerMap::shouldDrawPart( PartType part ) const
486486
return true; // for Layer
487487
}
488488

489-
void QgsComposerMap::updateCachedImage( void )
489+
void QgsComposerMap::updateCachedImage()
490490
{
491-
syncLayerSet(); //layer list may have changed
492491
mCacheUpdated = false;
493492
cache();
494493
QGraphicsRectItem::update();
@@ -502,6 +501,12 @@ void QgsComposerMap::renderModeUpdateCachedImage()
502501
}
503502
}
504503

504+
void QgsComposerMap::layersChanged()
505+
{
506+
syncLayerSet();
507+
renderModeUpdateCachedImage();
508+
}
509+
505510
void QgsComposerMap::setCacheUpdated( bool u )
506511
{
507512
mCacheUpdated = u;
@@ -1169,8 +1174,8 @@ void QgsComposerMap::connectUpdateSlot()
11691174
QgsMapLayerRegistry* layerRegistry = QgsMapLayerRegistry::instance();
11701175
if ( layerRegistry )
11711176
{
1172-
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( updateCachedImage() ) );
1173-
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( updateCachedImage() ) );
1177+
connect( layerRegistry, SIGNAL( layerWillBeRemoved( QString ) ), this, SLOT( layersChanged() ) );
1178+
connect( layerRegistry, SIGNAL( layerWasAdded( QgsMapLayer* ) ), this, SLOT( layersChanged() ) );
11741179
}
11751180
}
11761181

src/core/composer/qgscomposermap.h

+13-2
Original file line numberDiff line numberDiff line change
@@ -796,9 +796,12 @@ class CORE_EXPORT QgsComposerMap : public QgsComposerItem
796796

797797
public slots:
798798

799-
/**Called if map canvas has changed*/
799+
/**Forces an update of the cached map image*/
800800
void updateCachedImage();
801-
/**Call updateCachedImage if item is in render mode*/
801+
802+
/**Updates the cached map image if the map is set to Render mode
803+
* @see updateCachedImage
804+
*/
802805
void renderModeUpdateCachedImage();
803806

804807
/**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
809812

810813
virtual void refreshDataDefinedProperty( const QgsComposerObject::DataDefinedProperty property = QgsComposerObject::AllProperties ) override;
811814

815+
protected slots:
816+
817+
/**Called when layers are added or removed from the layer registry. Updates the maps
818+
* layer set and redraws the map if required.
819+
* @note added in QGIS 2.9
820+
*/
821+
void layersChanged();
822+
812823
private:
813824

814825
/**Unique identifier*/

0 commit comments

Comments
 (0)