Skip to content
Permalink
Browse files

[canvas] Insure a refreshed canvas due to temporal range changes refl…

…ects the last provided range
  • Loading branch information
nirvn committed May 8, 2020
1 parent db7108b commit da23cb6ee09b9a655bc9f39bc9d2ab85da06ad02
Showing with 48 additions and 10 deletions.
  1. +7 −0 python/gui/auto_generated/qgsmapcanvas.sip.in
  2. +32 −10 src/gui/qgsmapcanvas.cpp
  3. +9 −0 src/gui/qgsmapcanvas.h
@@ -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();
@@ -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()
@@ -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
@@ -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.
*
@@ -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;

0 comments on commit da23cb6

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