Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Allow QgsMapLayer::triggerRepaint to defer updates
By calling QgsMapLayer::triggerRepaint( true ) any cached
version of the layer will be invalidated, but a map canvas
refresh won't automatically be triggered

This allows invalidation of cached images while deferring
the actual map update until the next canvas refresh.
  • Loading branch information
nyalldawson committed Feb 12, 2017
1 parent 92091c5 commit 04d392b
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 24 deletions.
13 changes: 2 additions & 11 deletions python/core/qgsmaplayer.sip
Expand Up @@ -634,13 +634,7 @@ class QgsMapLayer : QObject
*/
void setScaleBasedVisibility( const bool enabled );

/**
* Will advice the map canvas (and any other interested party) that this layer requires to be repainted.
* Will emit a repaintRequested() signal.
*
* @note in 2.6 function moved from vector/raster subclasses to QgsMapLayer
*/
void triggerRepaint();
void triggerRepaint( bool deferredUpdate = false );

/** \brief Obtain Metadata for this layer */
virtual QString metadata() const;
Expand Down Expand Up @@ -687,10 +681,7 @@ class QgsMapLayer : QObject
/** Emit a signal that layer's CRS has been reset */
void crsChanged();

/** 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();
void repaintRequested( bool deferredUpdate = false );

/** This is used to send a request that any mapcanvas using this layer update its extents */
void recalculateExtents() const;
Expand Down
2 changes: 1 addition & 1 deletion src/app/qgisapp.cpp
Expand Up @@ -10408,7 +10408,7 @@ void QgisApp::layersWereAdded( const QList<QgsMapLayer *>& theLayers )

if ( provider )
{
connect( provider, &QgsDataProvider::dataChanged, layer, &QgsMapLayer::triggerRepaint );
connect( provider, &QgsDataProvider::dataChanged, layer, [layer] { layer->triggerRepaint(); } );
connect( provider, &QgsDataProvider::dataChanged, mMapCanvas, &QgsMapCanvas::refresh );
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/browser/qgsbrowser.cpp
Expand Up @@ -439,7 +439,7 @@ void QgsBrowser::updateCurrentTab()
QgsRasterLayer *rlayer = qobject_cast< QgsRasterLayer * >( mLayer );
if ( rlayer )
{
connect( rlayer->dataProvider(), &QgsRasterDataProvider::dataChanged, rlayer, &QgsRasterLayer::triggerRepaint );
connect( rlayer->dataProvider(), &QgsRasterDataProvider::dataChanged, rlayer, [rlayer] { rlayer->triggerRepaint(); } );
connect( rlayer->dataProvider(), &QgsRasterDataProvider::dataChanged, mapCanvas, &QgsMapCanvas::refresh );
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/core/qgsmaplayer.cpp
Expand Up @@ -1591,9 +1591,9 @@ QgsMapLayerStyleManager* QgsMapLayer::styleManager() const
return mStyleManager;
}

void QgsMapLayer::triggerRepaint()
void QgsMapLayer::triggerRepaint( bool deferredUpdate )
{
emit repaintRequested();
emit repaintRequested( deferredUpdate );
}

QString QgsMapLayer::metadata() const
Expand Down
10 changes: 7 additions & 3 deletions src/core/qgsmaplayer.h
Expand Up @@ -678,12 +678,14 @@ class CORE_EXPORT QgsMapLayer : public QObject
void setScaleBasedVisibility( const bool enabled );

/**
* Will advice the map canvas (and any other interested party) that this layer requires to be repainted.
* Will advise the map canvas (and any other interested party) that this layer requires to be repainted.
* Will emit a repaintRequested() signal.
* If \a deferredUpdate is true then the layer will only be repainted when the canvas is next
* re-rendered, and will not trigger any canvas redraws itself.
*
* @note in 2.6 function moved from vector/raster subclasses to QgsMapLayer
*/
void triggerRepaint();
void triggerRepaint( bool deferredUpdate = false );

//! \brief Obtain Metadata for this layer
virtual QString metadata() const;
Expand Down Expand Up @@ -732,8 +734,10 @@ class CORE_EXPORT QgsMapLayer : public QObject

/** 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.
* If \a deferredUpdate is true then the layer will only be repainted when the canvas is next
* re-rendered, and will not trigger any canvas redraws itself.
*/
void repaintRequested();
void repaintRequested( bool deferredUpdate = false );

//! This is used to send a request that any mapcanvas using this layer update its extents
void recalculateExtents() const;
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayer.cpp
Expand Up @@ -164,7 +164,7 @@ QgsVectorLayer::QgsVectorLayer( const QString& vectorLayerPath,
setDataSource( vectorLayerPath, baseName, providerKey, loadDefaultStyleFlag );
}

connect( this, &QgsVectorLayer::selectionChanged, this, &QgsVectorLayer::repaintRequested );
connect( this, &QgsVectorLayer::selectionChanged, this, [=]{ emit repaintRequested(); } );
connect( QgsProject::instance()->relationManager(), &QgsRelationManager::relationsLoaded, this, &QgsVectorLayer::onRelationsLoaded );

// Default simplify drawing settings
Expand Down
10 changes: 8 additions & 2 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -295,7 +295,7 @@ void QgsMapCanvas::setLayers( const QList<QgsMapLayer*>& layers )

Q_FOREACH ( QgsMapLayer* layer, oldLayers )
{
disconnect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::refresh );
disconnect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
disconnect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
if ( QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
{
Expand All @@ -307,7 +307,7 @@ void QgsMapCanvas::setLayers( const QList<QgsMapLayer*>& layers )

Q_FOREACH ( QgsMapLayer* layer, layers )
{
connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::refresh );
connect( layer, &QgsMapLayer::repaintRequested, this, &QgsMapCanvas::layerRepaintRequested );
connect( layer, &QgsMapLayer::crsChanged, this, &QgsMapCanvas::layerCrsChange );
if ( QgsVectorLayer* vlayer = qobject_cast<QgsVectorLayer *>( layer ) )
{
Expand Down Expand Up @@ -1668,6 +1668,12 @@ void QgsMapCanvas::updateDatumTransformEntries()
}
}

void QgsMapCanvas::layerRepaintRequested( bool deferred )
{
if ( !deferred )
refresh();
}



QgsMapTool* QgsMapCanvas::mapTool()
Expand Down
4 changes: 4 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -612,6 +612,10 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Make sure the datum transform store is properly populated
void updateDatumTransformEntries();

private slots:

void layerRepaintRequested( bool deferred );

private:
/// this class is non-copyable

Expand Down
5 changes: 3 additions & 2 deletions src/gui/qgsmapoverviewcanvas.cpp
Expand Up @@ -207,9 +207,10 @@ void QgsMapOverviewCanvas::mapRenderingFinished()
update();
}

void QgsMapOverviewCanvas::layerRepaintRequested()
void QgsMapOverviewCanvas::layerRepaintRequested( bool deferred )
{
refresh();
if ( !deferred )
refresh();
}


Expand Down
6 changes: 5 additions & 1 deletion src/gui/qgsmapoverviewcanvas.h
Expand Up @@ -75,7 +75,11 @@ class GUI_EXPORT QgsMapOverviewCanvas : public QWidget

protected slots:
void mapRenderingFinished();
void layerRepaintRequested();

/**
* Triggered when a layer in the overview requests a repaint.
*/
void layerRepaintRequested( bool deferred = false );

protected:

Expand Down

0 comments on commit 04d392b

Please sign in to comment.