Skip to content
Permalink
Browse files

Make API a little more future-proof

  • Loading branch information
nyalldawson committed May 25, 2020
1 parent 25a3ced commit 7e8d27e657f0b24bdd897fe58ac71d7eea056172
@@ -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
@@ -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.
@@ -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
@@ -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();
@@ -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;
}
@@ -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
@@ -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.
@@ -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

0 comments on commit 7e8d27e

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