Skip to content

Commit

Permalink
Make API a little more future-proof
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed May 25, 2020
1 parent 25a3ced commit 7e8d27e
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 52 deletions.
36 changes: 33 additions & 3 deletions python/core/auto_generated/qgsvectorlayertemporalproperties.sip.in
Expand Up @@ -11,6 +11,36 @@



class QgsVectorLayerTemporalContext
{
%Docstring
Encapsulates the context in which a QgsVectorLayer's temporal capabilities
will be applied

.. versionadded:: 3.14
%End

%TypeHeaderCode
#include "qgsvectorlayertemporalproperties.h"
%End
public:

QgsVectorLayer *layer() const;
%Docstring
Returns the associated layer.

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

void setLayer( QgsVectorLayer *layer );
%Docstring
Sets the associated ``layer``.

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

};

class QgsVectorLayerTemporalProperties : QgsMapLayerTemporalProperties
{
%Docstring
Expand Down Expand Up @@ -298,10 +328,10 @@ occur before or within the map's temporal range should be rendered).
.. seealso:: :py:func:`accumulateFeatures`
%End

QString createFilterString( QgsVectorLayer *layer, const QgsDateTimeRange &range ) const;
QString createFilterString( const QgsVectorLayerTemporalContext &context, const QgsDateTimeRange &range ) const;
%Docstring
Creates a QGIS expression filter string for filtering features from ``layer``
to those within the specified time ``range``.
Creates a QGIS expression filter string for filtering features within
the specified ``context`` to those within the specified time ``range``.

The returned expression string considers the mode() and other related
settings (such as startField()) when building the filter string.
Expand Down
4 changes: 3 additions & 1 deletion src/core/qgsvectorlayerrenderer.cpp
Expand Up @@ -63,7 +63,9 @@ QgsVectorLayerRenderer::QgsVectorLayerRenderer( QgsVectorLayer *layer, QgsRender

if ( context.isTemporal() )
{
mTemporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( layer, context.temporalRange() );
QgsVectorLayerTemporalContext temporalContext;
temporalContext.setLayer( layer );
mTemporalFilter = qobject_cast< const QgsVectorLayerTemporalProperties * >( layer->temporalProperties() )->createFilterString( temporalContext, context.temporalRange() );
}

// if there's already a simplification method specified via the context, we respect that. Otherwise, we fall back
Expand Down
12 changes: 11 additions & 1 deletion src/core/qgsvectorlayertemporalproperties.cpp
Expand Up @@ -411,7 +411,7 @@ QString dateTimeExpressionLiteral( const QDateTime &datetime )
.arg( datetime.time().second() + datetime.time().msec() / 1000.0 );
}

QString QgsVectorLayerTemporalProperties::createFilterString( QgsVectorLayer *, const QgsDateTimeRange &range ) const
QString QgsVectorLayerTemporalProperties::createFilterString( const QgsVectorLayerTemporalContext &, const QgsDateTimeRange &range ) const
{
if ( !isActive() )
return QString();
Expand Down Expand Up @@ -651,3 +651,13 @@ void QgsVectorLayerTemporalProperties::guessDefaultsFromFields( const QgsFields
// note -- NEVER auto enable temporal properties here! It's just a helper designed
// to shortcut the initial field selection
}

QgsVectorLayer *QgsVectorLayerTemporalContext::layer() const
{
return mLayer;
}

void QgsVectorLayerTemporalContext::setLayer( QgsVectorLayer *layer )
{
mLayer = layer;
}
37 changes: 34 additions & 3 deletions src/core/qgsvectorlayertemporalproperties.h
Expand Up @@ -29,6 +29,37 @@
class QgsVectorLayer;
class QgsFields;

/**
* \class QgsVectorLayerTemporalContext
* \ingroup core
* Encapsulates the context in which a QgsVectorLayer's temporal capabilities
* will be applied
*
* \since QGIS 3.14
*/
class CORE_EXPORT QgsVectorLayerTemporalContext
{
public:

/**
* Returns the associated layer.
*
* \see setLayer()
*/
QgsVectorLayer *layer() const;

/**
* Sets the associated \a layer.
*
* \see layer()
*/
void setLayer( QgsVectorLayer *layer );

private:

QgsVectorLayer *mLayer = nullptr;
};

/**
* \class QgsVectorLayerTemporalProperties
* \ingroup core
Expand Down Expand Up @@ -283,8 +314,8 @@ class CORE_EXPORT QgsVectorLayerTemporalProperties : public QgsMapLayerTemporalP
void setAccumulateFeatures( bool accumulate );

/**
* Creates a QGIS expression filter string for filtering features from \a layer
* to those within the specified time \a range.
* Creates a QGIS expression filter string for filtering features within
* the specified \a context to those within the specified time \a range.
*
* The returned expression string considers the mode() and other related
* settings (such as startField()) when building the filter string.
Expand All @@ -294,7 +325,7 @@ class CORE_EXPORT QgsVectorLayerTemporalProperties : public QgsMapLayerTemporalP
* isVisibleInTemporalRange() when testing whether features from a layer set to the
* ModeFixedTemporalRange should ALL be filtered out.
*/
QString createFilterString( QgsVectorLayer *layer, const QgsDateTimeRange &range ) const;
QString createFilterString( const QgsVectorLayerTemporalContext &context, const QgsDateTimeRange &range ) const;

/**
* Attempts to setup the temporal properties by scanning a set of \a fields
Expand Down

0 comments on commit 7e8d27e

Please sign in to comment.