Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[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)
  • Loading branch information
nyalldawson committed Mar 25, 2015
1 parent 012ee0b commit 837c7ee
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
16 changes: 14 additions & 2 deletions python/core/composer/qgscomposermap.sip
Expand Up @@ -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 */
Expand All @@ -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();

};
13 changes: 9 additions & 4 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -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();
Expand All @@ -502,6 +501,12 @@ void QgsComposerMap::renderModeUpdateCachedImage()
}
}

void QgsComposerMap::layersChanged()
{
syncLayerSet();
renderModeUpdateCachedImage();
}

void QgsComposerMap::setCacheUpdated( bool u )
{
mCacheUpdated = u;
Expand Down Expand Up @@ -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() ) );
}
}

Expand Down
15 changes: 13 additions & 2 deletions src/core/composer/qgscomposermap.h
Expand Up @@ -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 */
Expand All @@ -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*/
Expand Down

0 comments on commit 837c7ee

Please sign in to comment.