Skip to content

Commit

Permalink
[canvas] Insure a refreshed canvas due to temporal range changes refl…
Browse files Browse the repository at this point in the history
…ects the last provided range
  • Loading branch information
nirvn committed May 10, 2020
1 parent db7108b commit da23cb6
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
7 changes: 7 additions & 0 deletions python/gui/auto_generated/qgsmapcanvas.sip.in
Expand Up @@ -129,6 +129,13 @@ Check whether images of rendered layers are curerently being cached
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)

.. versionadded:: 2.4
%End

void clearTemporalCache();
%Docstring
Make sure to remove any rendered images of temporal-enabled layers from cache (does nothing if cache is not enabled)

.. versionadded:: 3.14
%End

void waitWhileRendering();
Expand Down
42 changes: 32 additions & 10 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -696,16 +696,27 @@ void QgsMapCanvas::rendererJobFinished()
{
mLastLayerRenderTime.insert( it.key()->id(), it.value() );
}
if ( mUsePreviewJobs )
if ( mUsePreviewJobs && !mTemporalRefreshAfterJob )
startPreviewJobs();
}
else
{
mTemporalRefreshAfterJob = false;
}

// now we are in a slot called from mJob - do not delete it immediately
// so the class is still valid when the execution returns to the class
mJob->deleteLater();
mJob = nullptr;

emit mapCanvasRefreshed();

if ( mTemporalRefreshAfterJob )
{
mTemporalRefreshAfterJob = false;
clearTemporalCache();
refresh();
}
}

void QgsMapCanvas::previewJobFinished()
Expand Down Expand Up @@ -761,28 +772,39 @@ void QgsMapCanvas::setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHa
mDropHandlers = handlers;
}

void QgsMapCanvas::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
void QgsMapCanvas::clearTemporalCache()
{
if ( temporalRange() == dateTimeRange )
return;

mSettings.setTemporalRange( dateTimeRange );

if ( mCache )
{
// we need to discard any previously cached images which have temporal properties enabled, so that these will be updated when
// the canvas is redrawn
const QList<QgsMapLayer *> layerList = mapSettings().layers();
for ( QgsMapLayer *layer : layerList )
{
if ( layer->temporalProperties() && layer->temporalProperties()->isActive() )
mCache->invalidateCacheForLayer( layer );
}
}
}

void QgsMapCanvas::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( temporalRange() == dateTimeRange )
return;

mSettings.setTemporalRange( dateTimeRange );

emit temporalRangeChanged();

autoRefreshTriggered();
if ( !mJob )
{
// we need to discard any previously cached images which have temporal properties enabled, so that these will be updated when
// the canvas is redrawn
clearTemporalCache();
autoRefreshTriggered();
}
else
{
mTemporalRefreshAfterJob = true;
}
}

const QgsDateTimeRange &QgsMapCanvas::temporalRange() const
Expand Down
9 changes: 9 additions & 0 deletions src/gui/qgsmapcanvas.h
Expand Up @@ -177,6 +177,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
*/
void clearCache();

/**
* Make sure to remove any rendered images of temporal-enabled layers from cache (does nothing if cache is not enabled)
* \since QGIS 3.14
*/
void clearTemporalCache();

/**
* Blocks until the rendering job has finished.
*
Expand Down Expand Up @@ -1057,6 +1063,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
//! Flag that allows squashing multiple refresh() calls into just one delayed rendering job
bool mRefreshScheduled = false;

//! Flag that triggers a refresh after an ongoing rendering job finishes and clear cache for temporal-enabled layers
bool mTemporalRefreshAfterJob = false;

//! determines whether user has requested to suppress rendering
bool mRenderFlag = true;

Expand Down

0 comments on commit da23cb6

Please sign in to comment.