Skip to content
Permalink
Browse files

Invalidate cached image when layer's data or appearance is modified

  • Loading branch information
wonder-sk committed Dec 10, 2013
1 parent 9164ae9 commit e814e8df92c512a890c6a35677463e72fa0fc181
@@ -79,6 +79,10 @@ class QgsMapCanvas : QGraphicsView
//! @note added in 2.1
bool isCachingEnabled() const;

//! Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
//! @note added in 2.1
void clearCache();

//! Set whether the layers are rendered in parallel or sequentially
//! @note added in 2.1
void setParallelRenderingEnabled( bool enabled );
@@ -5681,6 +5681,8 @@ void QgisApp::refreshMapCanvas()
{
//reload cached provider data
QgsMapLayerRegistry::instance()->reloadAllLayers();

mMapCanvas->clearCache();
//then refresh
mMapCanvas->refresh();
}
@@ -6726,7 +6728,7 @@ void QgisApp::adjustBrightnessContrast( int delta, bool updateBrightness )
brightnessFilter->setContrast( brightnessFilter->contrast() + delta );
}

mMapCanvas->refresh();
myRasterLayer->triggerRepaint();
}

void QgisApp::helpContents()
@@ -407,8 +407,8 @@ class CORE_EXPORT QgsMapLayer : public QObject
*/
void layerCrsChanged();

/** This signal should be connected with the slot QgsMapCanvas::refresh()
* \todo to be removed - GUI dependency
/** By emitting this signal the layer tells that either appearance or content have been changed
* and any view showing the rendered layer should refresh itself.
*/
void repaintRequested();

@@ -168,6 +168,8 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,

connect( this, SIGNAL( selectionChanged( QgsFeatureIds, QgsFeatureIds, bool ) ), this, SIGNAL( selectionChanged() ) );

connect( this, SIGNAL( selectionChanged( QgsFeatureIds, QgsFeatureIds, bool ) ), this, SIGNAL( repaintRequested() ) );

connect( QgsProject::instance()->relationManager(), SIGNAL( relationsLoaded() ), this, SLOT( onRelationsLoaded() ) );
} // QgsVectorLayer ctor

@@ -888,6 +890,9 @@ bool QgsVectorLayer::setSubsetString( QString subset )
mDataSource = mDataProvider->dataSourceUri();
updateExtents();

if ( res )
emit repaintRequested();

return res;
}

@@ -2325,6 +2330,8 @@ bool QgsVectorLayer::commitChanges()
updateFields();
mDataProvider->updateExtents();

emit repaintRequested();

return success;
}

@@ -2366,6 +2373,7 @@ bool QgsVectorLayer::rollBack( bool deleteBuffer )
mCache->deleteCachedGeometries();
}

emit repaintRequested();
return true;
}

@@ -931,6 +931,8 @@ void QgsRasterLayer::setContrastEnhancement( QgsContrastEnhancement::ContrastEnh
if ( myEnhancements.value( 1 ) ) myMultiBandRenderer->setGreenContrastEnhancement( myEnhancements.value( 1 ) );
if ( myEnhancements.value( 2 ) ) myMultiBandRenderer->setBlueContrastEnhancement( myEnhancements.value( 2 ) );
}

emit repaintRequested();
}

void QgsRasterLayer::setDefaultContrastEnhancement()
@@ -370,7 +370,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
// Add check if vector layer when disconnecting from selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
disconnect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
disconnect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( layerRequestedRepaint() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
@@ -385,7 +385,7 @@ void QgsMapCanvas::setLayerSet( QList<QgsMapCanvasLayer> &layers )
// Add check if vector layer when connecting to selectionChanged slot
// Ticket #811 - racicot
QgsMapLayer *currentLayer = layer( i );
connect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( refresh() ) );
connect( currentLayer, SIGNAL( repaintRequested() ), this, SLOT( layerRequestedRepaint() ) );
QgsVectorLayer *isVectLyr = qobject_cast<QgsVectorLayer *>( currentLayer );
if ( isVectLyr )
{
@@ -509,6 +509,12 @@ bool QgsMapCanvas::isCachingEnabled() const
return mCache != 0;
}

void QgsMapCanvas::clearCache()
{
if ( mCache )
mCache->clear();
}

void QgsMapCanvas::setParallelRenderingEnabled( bool enabled )
{
mUseParallelRendering = enabled;
@@ -640,6 +646,19 @@ void QgsMapCanvas::refreshMap()
mMapUpdateTimer.start();
}

void QgsMapCanvas::layerRequestedRepaint()
{
// make sure to clear the cached image
if ( mCache )
{
QgsMapLayer* layer = qobject_cast<QgsMapLayer*>( sender() );
if ( layer )
mCache->setCacheImage( layer->id(), QImage() );
}

refresh();
}

void QgsMapCanvas::rendererJobFinished()
{
qDebug("CANVAS finish! %d", !mJobCancelled );
@@ -150,6 +150,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! @note added in 2.1
bool isCachingEnabled() const;

//! Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
//! @note added in 2.1
void clearCache();

//! Set whether the layers are rendered in parallel or sequentially
//! @note added in 2.1
void setParallelRenderingEnabled( bool enabled );
@@ -367,6 +371,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView

void refreshMap();

//! Layer says something has changed that affects its appearance
void layerRequestedRepaint();

signals:
/** Let the owner know how far we are with render operations */
//! @deprecated since 2.1 - already unused in 2.0 anyway

0 comments on commit e814e8d

Please sign in to comment.
You can’t perform that action at this time.