Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Flesh out QgsVectorDataProviderTemporalCapabilities and implement
setDefaultsFromDataProviderTemporalCapabilities for QgsVectorLayerTemporalProperties

 Please enter the commit message for your changes. Lines starting
  • Loading branch information
nyalldawson committed May 8, 2020
1 parent 4f11d8b commit 731ad8d
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 0 deletions.
Expand Up @@ -26,11 +26,32 @@ and should only be set by the QgsDataProvider itself.
%End
public:

enum TemporalMode
{
ProviderHasFixedTemporalRange,
ProviderStoresFeatureDateTimeInstantInField,
ProviderStoresFeatureDateTimeStartAndEndInSeparateFields,
};

QgsVectorDataProviderTemporalCapabilities( bool enabled = false );
%Docstring
Constructor for QgsVectorDataProviderTemporalCapabilities.

The ``enabled`` argument specifies whether the data provider has temporal capabilities.
%End

TemporalMode mode() const;
%Docstring
Returns the temporal properties mode.

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

void setMode( TemporalMode mode );
%Docstring
Sets the temporal properties ``mode``.

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

void setAvailableTemporalRange( const QgsDateTimeRange &range );
Expand All @@ -45,6 +66,46 @@ Sets the datetime ``range`` extent from which temporal data is available from th
Returns the datetime range extent from which temporal data is available from the provider.

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

QString startField() const;
%Docstring
Returns the name of the start datetime field, which contains the start time for the feature's time spans.

If mode() is ProviderStoresFeatureDateTimeInstantInField, then this field stores both the start AND end times.

.. seealso:: :py:func:`setStartField`

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

void setStartField( const QString &field );
%Docstring
Sets the name of the start datetime ``field``, which stores the start time for the feature's time spans.

If mode() is ModeFeatureDateTimeInstantFromField, then this field stores both the start AND end times.

.. seealso:: :py:func:`startField`

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

QString endField() const;
%Docstring
Returns the name of the end datetime field, which stores the end time for the feature's time spans.

.. seealso:: :py:func:`setEndField`

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

void setEndField( const QString &field );
%Docstring
Sets the name of the end datetime ``field``, which stores the end time for the feature's time spans.

.. seealso:: :py:func:`endField`

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

};
Expand Down
30 changes: 30 additions & 0 deletions src/core/qgsvectordataprovidertemporalcapabilities.cpp
Expand Up @@ -22,6 +22,16 @@ QgsVectorDataProviderTemporalCapabilities::QgsVectorDataProviderTemporalCapabili
{
}

QgsVectorDataProviderTemporalCapabilities::TemporalMode QgsVectorDataProviderTemporalCapabilities::mode() const
{
return mMode;
}

void QgsVectorDataProviderTemporalCapabilities::setMode( QgsVectorDataProviderTemporalCapabilities::TemporalMode mode )
{
mMode = mode;
}

void QgsVectorDataProviderTemporalCapabilities::setAvailableTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !hasTemporalCapabilities() )
Expand All @@ -34,3 +44,23 @@ const QgsDateTimeRange &QgsVectorDataProviderTemporalCapabilities::availableTemp
{
return mAvailableTemporalRange;
}

QString QgsVectorDataProviderTemporalCapabilities::startField() const
{
return mStartField;
}

void QgsVectorDataProviderTemporalCapabilities::setStartField( const QString &field )
{
mStartField = field;
}

QString QgsVectorDataProviderTemporalCapabilities::endField() const
{
return mEndField;
}

void QgsVectorDataProviderTemporalCapabilities::setEndField( const QString &field )
{
mEndField = field;
}
65 changes: 65 additions & 0 deletions src/core/qgsvectordataprovidertemporalcapabilities.h
Expand Up @@ -38,13 +38,37 @@ class CORE_EXPORT QgsVectorDataProviderTemporalCapabilities : public QgsDataProv
{
public:

/**
* Provider temporal handling mode
**/
enum TemporalMode
{
ProviderHasFixedTemporalRange = 0, //!< Entire dataset from provider has a fixed start and end datetime.
ProviderStoresFeatureDateTimeInstantInField, //!< Dataset has feature datetime instants stored in a single field
ProviderStoresFeatureDateTimeStartAndEndInSeparateFields, //!< Dataset stores feature start and end datetimes in separate fields
};

/**
* Constructor for QgsVectorDataProviderTemporalCapabilities.
*
* The \a enabled argument specifies whether the data provider has temporal capabilities.
*/
QgsVectorDataProviderTemporalCapabilities( bool enabled = false );

/**
* Returns the temporal properties mode.
*
*\see setMode()
**/
TemporalMode mode() const;

/**
* Sets the temporal properties \a mode.
*
*\see mode()
**/
void setMode( TemporalMode mode );

/**
* Sets the datetime \a range extent from which temporal data is available from the provider.
*
Expand All @@ -59,6 +83,42 @@ class CORE_EXPORT QgsVectorDataProviderTemporalCapabilities : public QgsDataProv
*/
const QgsDateTimeRange &availableTemporalRange() const;

/**
* Returns the name of the start datetime field, which contains the start time for the feature's time spans.
*
* If mode() is ProviderStoresFeatureDateTimeInstantInField, then this field stores both the start AND end times.
*
* \see setStartField()
* \see endField()
*/
QString startField() const;

/**
* Sets the name of the start datetime \a field, which stores the start time for the feature's time spans.
*
* If mode() is ModeFeatureDateTimeInstantFromField, then this field stores both the start AND end times.
*
* \see startField()
* \see setEndField()
*/
void setStartField( const QString &field );

/**
* Returns the name of the end datetime field, which stores the end time for the feature's time spans.
*
* \see setEndField()
* \see startField()
*/
QString endField() const;

/**
* Sets the name of the end datetime \a field, which stores the end time for the feature's time spans.
*
* \see endField()
* \see setStartField()
*/
void setEndField( const QString &field );

private:

/**
Expand All @@ -71,6 +131,11 @@ class CORE_EXPORT QgsVectorDataProviderTemporalCapabilities : public QgsDataProv
*/
QgsDateTimeRange mAvailableTemporalRange;

TemporalMode mMode = ProviderHasFixedTemporalRange;

QString mStartField;
QString mEndField;

};

#endif // QGSVECTORDATAPROVIDERTEMPORALCAPABILITIES_H
14 changes: 14 additions & 0 deletions src/core/qgsvectorlayertemporalproperties.cpp
Expand Up @@ -128,6 +128,20 @@ void QgsVectorLayerTemporalProperties::setDefaultsFromDataProviderTemporalCapabi
{
setIsActive( vectorCaps->hasTemporalCapabilities() );
setFixedTemporalRange( vectorCaps->availableTemporalRange() );
setStartField( vectorCaps->startField() );
setEndField( vectorCaps->endField() );
switch ( vectorCaps->mode() )
{
case QgsVectorDataProviderTemporalCapabilities::ProviderHasFixedTemporalRange:
setMode( ModeFixedTemporalRange );
break;
case QgsVectorDataProviderTemporalCapabilities::ProviderStoresFeatureDateTimeInstantInField:
setMode( ModeFeatureDateTimeInstantFromField );
break;
case QgsVectorDataProviderTemporalCapabilities::ProviderStoresFeatureDateTimeStartAndEndInSeparateFields:
setMode( ModeFeatureDateTimeStartAndEndFromFields );
break;
}
}
}

Expand Down

0 comments on commit 731ad8d

Please sign in to comment.