Skip to content

Commit da23cb6

Browse files
committedMay 10, 2020
[canvas] Insure a refreshed canvas due to temporal range changes reflects the last provided range
1 parent db7108b commit da23cb6

File tree

3 files changed

+48
-10
lines changed

3 files changed

+48
-10
lines changed
 

‎python/gui/auto_generated/qgsmapcanvas.sip.in

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ Check whether images of rendered layers are curerently being cached
129129
Make sure to remove any rendered images from cache (does nothing if cache is not enabled)
130130

131131
.. versionadded:: 2.4
132+
%End
133+
134+
void clearTemporalCache();
135+
%Docstring
136+
Make sure to remove any rendered images of temporal-enabled layers from cache (does nothing if cache is not enabled)
137+
138+
.. versionadded:: 3.14
132139
%End
133140

134141
void waitWhileRendering();

‎src/gui/qgsmapcanvas.cpp

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -696,16 +696,27 @@ void QgsMapCanvas::rendererJobFinished()
696696
{
697697
mLastLayerRenderTime.insert( it.key()->id(), it.value() );
698698
}
699-
if ( mUsePreviewJobs )
699+
if ( mUsePreviewJobs && !mTemporalRefreshAfterJob )
700700
startPreviewJobs();
701701
}
702+
else
703+
{
704+
mTemporalRefreshAfterJob = false;
705+
}
702706

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

708712
emit mapCanvasRefreshed();
713+
714+
if ( mTemporalRefreshAfterJob )
715+
{
716+
mTemporalRefreshAfterJob = false;
717+
clearTemporalCache();
718+
refresh();
719+
}
709720
}
710721

711722
void QgsMapCanvas::previewJobFinished()
@@ -761,28 +772,39 @@ void QgsMapCanvas::setCustomDropHandlers( const QVector<QPointer<QgsCustomDropHa
761772
mDropHandlers = handlers;
762773
}
763774

764-
void QgsMapCanvas::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
775+
void QgsMapCanvas::clearTemporalCache()
765776
{
766-
if ( temporalRange() == dateTimeRange )
767-
return;
768-
769-
mSettings.setTemporalRange( dateTimeRange );
770-
771777
if ( mCache )
772778
{
773-
// we need to discard any previously cached images which have temporal properties enabled, so that these will be updated when
774-
// the canvas is redrawn
775779
const QList<QgsMapLayer *> layerList = mapSettings().layers();
776780
for ( QgsMapLayer *layer : layerList )
777781
{
778782
if ( layer->temporalProperties() && layer->temporalProperties()->isActive() )
779783
mCache->invalidateCacheForLayer( layer );
780784
}
781785
}
786+
}
787+
788+
void QgsMapCanvas::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
789+
{
790+
if ( temporalRange() == dateTimeRange )
791+
return;
792+
793+
mSettings.setTemporalRange( dateTimeRange );
782794

783795
emit temporalRangeChanged();
784796

785-
autoRefreshTriggered();
797+
if ( !mJob )
798+
{
799+
// we need to discard any previously cached images which have temporal properties enabled, so that these will be updated when
800+
// the canvas is redrawn
801+
clearTemporalCache();
802+
autoRefreshTriggered();
803+
}
804+
else
805+
{
806+
mTemporalRefreshAfterJob = true;
807+
}
786808
}
787809

788810
const QgsDateTimeRange &QgsMapCanvas::temporalRange() const

‎src/gui/qgsmapcanvas.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
177177
*/
178178
void clearCache();
179179

180+
/**
181+
* Make sure to remove any rendered images of temporal-enabled layers from cache (does nothing if cache is not enabled)
182+
* \since QGIS 3.14
183+
*/
184+
void clearTemporalCache();
185+
180186
/**
181187
* Blocks until the rendering job has finished.
182188
*
@@ -1057,6 +1063,9 @@ class GUI_EXPORT QgsMapCanvas : public QGraphicsView
10571063
//! Flag that allows squashing multiple refresh() calls into just one delayed rendering job
10581064
bool mRefreshScheduled = false;
10591065

1066+
//! Flag that triggers a refresh after an ongoing rendering job finishes and clear cache for temporal-enabled layers
1067+
bool mTemporalRefreshAfterJob = false;
1068+
10601069
//! determines whether user has requested to suppress rendering
10611070
bool mRenderFlag = true;
10621071

0 commit comments

Comments
 (0)
Please sign in to comment.