Skip to content

Commit

Permalink
[temporal] Optimize canvas rendering by avoiding needless cache clearing
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed May 10, 2020
1 parent da23cb6 commit 9be36fd
Show file tree
Hide file tree
Showing 11 changed files with 64 additions and 0 deletions.
Expand Up @@ -49,6 +49,7 @@ Constructor for QgsMeshLayerTemporalProperties
%End

public:

virtual QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context );

virtual bool readXml( const QDomElement &element, const QgsReadWriteContext &context );
Expand Down
12 changes: 12 additions & 0 deletions python/core/auto_generated/qgstemporalproperty.sip.in
Expand Up @@ -24,6 +24,13 @@ Base class for temporal property.
#include "qgstemporalproperty.h"
%End
public:
enum Flag
{
NoFlags,
FlagDontInvalidateCachedRendersWhenRangeChanges
};
typedef QFlags<QgsTemporalProperty::Flag> Flags;


QgsTemporalProperty( QObject *parent /TransferThis/ = 0, bool enabled = false );
%Docstring
Expand All @@ -44,6 +51,11 @@ Sets whether the temporal property is ``active``.
Returns ``True`` if the temporal property is active.

.. seealso:: :py:func:`setIsActive`
%End

virtual const QgsTemporalProperty::Flags flags() const;
%Docstring
Returns flags associated to the temporal property.
%End

signals:
Expand Down
Expand Up @@ -54,6 +54,12 @@ Returns the temporal properties mode.
Sets the temporal properties ``mode``.

.. seealso:: :py:func:`mode`
%End

virtual const QgsTemporalProperty::Flags flags() const;

%Docstring
Returns flags associated to the temporal property.
%End

void setFixedTemporalRange( const QgsDateTimeRange &range );
Expand Down
Expand Up @@ -51,6 +51,12 @@ Returns the temporal properties mode.
Sets the temporal properties ``mode``.

.. seealso:: :py:func:`mode`
%End

virtual const QgsTemporalProperty::Flags flags() const;

%Docstring
Returns flags associated to the temporal property.
%End

QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod intervalHandlingMethod() const;
Expand Down
1 change: 1 addition & 0 deletions src/core/mesh/qgsmeshlayertemporalproperties.h
Expand Up @@ -61,6 +61,7 @@ class CORE_EXPORT QgsMeshLayerTemporalProperties : public QgsMapLayerTemporalPro
QgsMeshLayerTemporalProperties( QObject *parent SIP_TRANSFERTHIS = nullptr, bool enabled = true );

public:

QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context ) override;
bool readXml( const QDomElement &element, const QgsReadWriteContext &context ) override;
void setDefaultsFromDataProviderTemporalCapabilities( const QgsDataProviderTemporalCapabilities *capabilities ) override;
Expand Down
11 changes: 11 additions & 0 deletions src/core/qgstemporalproperty.h
Expand Up @@ -37,6 +37,12 @@ class CORE_EXPORT QgsTemporalProperty : public QObject
Q_OBJECT

public:
enum Flag
{
NoFlags = 0,
FlagDontInvalidateCachedRendersWhenRangeChanges = 1 //!< Any cached rendering will not be invalidated when temporal range context is modified
};
Q_DECLARE_FLAGS( Flags, Flag )

/**
* Constructor for QgsTemporalProperty, with the specified \a parent object.
Expand All @@ -59,6 +65,11 @@ class CORE_EXPORT QgsTemporalProperty : public QObject
*/
bool isActive() const;

/**
* Returns flags associated to the temporal property.
*/
virtual const QgsTemporalProperty::Flags flags() const { return QgsTemporalProperty::NoFlags; }

signals:

/**
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayertemporalproperties.cpp
Expand Up @@ -108,6 +108,11 @@ void QgsVectorLayerTemporalProperties::setMode( QgsVectorLayerTemporalProperties
mMode = mode;
}

const QgsTemporalProperty::Flags QgsVectorLayerTemporalProperties::flags() const
{
return mode() == ModeFixedTemporalRange ? QgsTemporalProperty::FlagDontInvalidateCachedRendersWhenRangeChanges : QgsTemporalProperty::NoFlags;
}

void QgsVectorLayerTemporalProperties::setFixedTemporalRange( const QgsDateTimeRange &range )
{
mFixedRange = range;
Expand Down
5 changes: 5 additions & 0 deletions src/core/qgsvectorlayertemporalproperties.h
Expand Up @@ -75,6 +75,11 @@ class CORE_EXPORT QgsVectorLayerTemporalProperties : public QgsMapLayerTemporalP
**/
void setMode( TemporalMode mode );

/**
* Returns flags associated to the temporal property.
*/
const QgsTemporalProperty::Flags flags() const override;

/**
* Sets a temporal \a range to apply to the whole layer. All features from
* the layer will be rendered whenever the current datetime range of
Expand Down
5 changes: 5 additions & 0 deletions src/core/raster/qgsrasterlayertemporalproperties.cpp
Expand Up @@ -70,6 +70,11 @@ void QgsRasterLayerTemporalProperties::setMode( QgsRasterLayerTemporalProperties
mMode = mode;
}

const QgsTemporalProperty::Flags QgsRasterLayerTemporalProperties::flags() const
{
return mode() == ModeFixedTemporalRange ? QgsTemporalProperty::FlagDontInvalidateCachedRendersWhenRangeChanges : QgsTemporalProperty::NoFlags;
}

QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod QgsRasterLayerTemporalProperties::intervalHandlingMethod() const
{
return mIntervalHandlingMethod;
Expand Down
5 changes: 5 additions & 0 deletions src/core/raster/qgsrasterlayertemporalproperties.h
Expand Up @@ -71,6 +71,11 @@ class CORE_EXPORT QgsRasterLayerTemporalProperties : public QgsMapLayerTemporalP
**/
void setMode( TemporalMode mode );

/**
* Returns flags associated to the temporal property.
*/
const QgsTemporalProperty::Flags flags() const override;

/**
* Returns the desired method to use when resolving a temporal interval to matching
* layers or bands in the data provider.
Expand Down
7 changes: 7 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -76,6 +76,8 @@ email : sherman at mrcc.com
#include "qgsreferencedgeometry.h"
#include "qgsprojectviewsettings.h"
#include "qgsmaplayertemporalproperties.h"
#include "qgsrasterlayertemporalproperties.h"
#include "qgsvectorlayertemporalproperties.h"
#include "qgstemporalcontroller.h"

/**
Expand Down Expand Up @@ -780,7 +782,12 @@ void QgsMapCanvas::clearTemporalCache()
for ( QgsMapLayer *layer : layerList )
{
if ( layer->temporalProperties() && layer->temporalProperties()->isActive() )
{
if ( layer->temporalProperties()->flags() & QgsTemporalProperty::FlagDontInvalidateCachedRendersWhenRangeChanges )
continue;

mCache->invalidateCacheForLayer( layer );
}
}
}
}
Expand Down

0 comments on commit 9be36fd

Please sign in to comment.