Skip to content
Permalink
Browse files

moved temporal range from provider to layer temporal properties

  • Loading branch information
Samweli authored and nyalldawson committed Mar 4, 2020
1 parent 51b475f commit 391f606f78dcbb1552098763a60497ee70156546
@@ -34,36 +34,6 @@ Constructor for :py:class:`QgsRasterDataProviderTemporalProperties`.

virtual ~QgsRasterDataProviderTemporalCapabilities();

void setTemporalRange( const QgsDateTimeRange &dateTimeRange );
%Docstring
Sets the current active datetime range for the temporal properties.

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

const QgsDateTimeRange &temporalRange() const;
%Docstring
Returns the current active datetime range for these temporal properties.

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

void setReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange );
%Docstring
Sets the current active reference datetime range for the temporal properties.

This will be used by bi-temporal dimensional data providers.

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

const QgsDateTimeRange &referenceTemporalRange() const;
%Docstring
Returns the current active reference datetime range for these temporal properties.

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

void setFixedTemporalRange( const QgsDateTimeRange &dateTimeRange );
%Docstring
Sets the fixed datetime range for the temporal properties.
@@ -79,6 +79,36 @@ Returns the fixed temporal range for the layer.
QgsRasterLayerTemporalProperties.ModeFixedTemporalRange

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

void setTemporalRange( const QgsDateTimeRange &dateTimeRange );
%Docstring
Sets the current active datetime range for the temporal properties.

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

const QgsDateTimeRange &temporalRange() const;
%Docstring
Returns the current active datetime range for these temporal properties.

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

void setReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange );
%Docstring
Sets the current active reference datetime range for the temporal properties.

This will be used by bi-temporal dimensional data providers.

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

const QgsDateTimeRange &referenceTemporalRange() const;
%Docstring
Returns the current active reference datetime range for these temporal properties.

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

virtual QDomElement writeXml( QDomElement &element, QDomDocument &doc, const QgsReadWriteContext &context );
@@ -15,6 +15,7 @@

#include <QMutexLocker>
#include "qgsdataprovider.h"
#include "qgsdataprovidertemporalcapabilities.h"

#define SUBLAYER_SEPARATOR QStringLiteral( "!!::!!" )

@@ -28,10 +28,10 @@
#include "qgscoordinatetransformcontext.h"
#include "qgslayermetadata.h"
#include "qgserror.h"
#include "qgsdataprovidertemporalcapabilities.h"

class QgsRectangle;
class QgsCoordinateReferenceSystem;
class QgsDataProviderTemporalCapabilities;


/**
@@ -22,37 +22,6 @@ QgsRasterDataProviderTemporalCapabilities::QgsRasterDataProviderTemporalCapabili
{
}

void QgsRasterDataProviderTemporalCapabilities::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !isActive() )
setIsActive( true );

// Don't set temporal range outside fixed temporal range limits,
// instead set equal to the fixed temporal range
QDateTime begin;
QDateTime end;

if ( mFixedRange.begin().isValid() &&
( dateTimeRange.begin() < mFixedRange.begin() ) )
begin = mFixedRange.begin();
else
begin = dateTimeRange.begin();

if ( mFixedRange.end().isValid() &&
( dateTimeRange.end() > mFixedRange.end() ) )
end = mFixedRange.end();
else
end = dateTimeRange.end();

mRange = QgsDateTimeRange( begin, end );

}

const QgsDateTimeRange &QgsRasterDataProviderTemporalCapabilities::temporalRange() const
{
return mRange;
}

void QgsRasterDataProviderTemporalCapabilities::setFixedTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !isActive() )
@@ -77,20 +46,6 @@ bool QgsRasterDataProviderTemporalCapabilities::isTimeEnabled() const
return mEnableTime;
}

void QgsRasterDataProviderTemporalCapabilities::setReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !isActive() )
setIsActive( true );

mReferenceRange = dateTimeRange;

}

const QgsDateTimeRange &QgsRasterDataProviderTemporalCapabilities::referenceTemporalRange() const
{
return mReferenceRange;
}

void QgsRasterDataProviderTemporalCapabilities::setFixedReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !isActive() )
@@ -46,36 +46,6 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv

virtual ~QgsRasterDataProviderTemporalCapabilities() = default;

/**
* Sets the current active datetime range for the temporal properties.
*
* \see temporalRange()
*/
void setTemporalRange( const QgsDateTimeRange &dateTimeRange );

/**
* Returns the current active datetime range for these temporal properties.
*
* \see setTemporalRange()
*/
const QgsDateTimeRange &temporalRange() const;

/**
* Sets the current active reference datetime range for the temporal properties.
*
* This will be used by bi-temporal dimensional data providers.
*
* \see referenceTemporalRange()
*/
void setReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange );

/**
* Returns the current active reference datetime range for these temporal properties.
*
* \see setReferenceTemporalRange()
*/
const QgsDateTimeRange &referenceTemporalRange() const;

/**
* Sets the fixed datetime range for the temporal properties.
*
@@ -147,8 +117,6 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
bool isReferenceEnable() const;

private:
//! Represents current active datetime range member.
QgsDateTimeRange mRange;

/**
* Represents fixed data provider datetime range.
@@ -171,11 +139,6 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv
*/
bool mEnableTime = true;

/**
* Stores reference temporal range
*/
QgsDateTimeRange mReferenceRange;

/**
* Stores the fixed reference temporal range
*/
@@ -36,17 +36,53 @@ void QgsRasterLayerTemporalProperties::setMode( QgsRasterLayerTemporalProperties

void QgsRasterLayerTemporalProperties::setFixedTemporalRange( const QgsDateTimeRange &range )
{
if ( range == mRange )
return;

mRange = range;
mFixedRange = range;
}

const QgsDateTimeRange &QgsRasterLayerTemporalProperties::fixedTemporalRange() const
{
return mFixedRange;
}

void QgsRasterLayerTemporalProperties::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
// Don't set temporal range outside fixed temporal range limits,
// instead set equal to the fixed temporal range
QDateTime begin;
QDateTime end;

if ( mFixedRange.begin().isValid() &&
( dateTimeRange.begin() < mFixedRange.begin() ) )
begin = mFixedRange.begin();
else
begin = dateTimeRange.begin();

if ( mFixedRange.end().isValid() &&
( dateTimeRange.end() > mFixedRange.end() ) )
end = mFixedRange.end();
else
end = dateTimeRange.end();

mRange = QgsDateTimeRange( begin, end );

}

const QgsDateTimeRange &QgsRasterLayerTemporalProperties::temporalRange() const
{
return mRange;
}


void QgsRasterLayerTemporalProperties::setReferenceTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
mReferenceRange = dateTimeRange;
}

const QgsDateTimeRange &QgsRasterLayerTemporalProperties::referenceTemporalRange() const
{
return mReferenceRange;
}

bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, const QgsReadWriteContext &context )
{
Q_UNUSED( context )
@@ -57,46 +93,64 @@ bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, cons
TemporalMode mode = indexToMode( temporalNode.toElement().attribute( QStringLiteral( "mode" ), QStringLiteral( "0" ) ). toInt() );
setMode( mode );

QDomNode rangeElement = temporalNode.namedItem( QStringLiteral( "range" ) );

QDomNode begin = rangeElement.namedItem( QStringLiteral( "start" ) );
QDomNode end = rangeElement.namedItem( QStringLiteral( "end" ) );
for ( QString rangeString : { "fixedRange", "normalRange", "referenceRange" } )
{
QDomNode rangeElement = temporalNode.namedItem( QStringLiteral( rangeString ) );

QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );
QDomNode begin = rangeElement.namedItem( QStringLiteral( "start" ) );
QDomNode end = rangeElement.namedItem( QStringLiteral( "end" ) );

QgsDateTimeRange range = QgsDateTimeRange( beginDate, endDate );
QDateTime beginDate = QDateTime::fromString( begin.toElement().text(), Qt::ISODate );
QDateTime endDate = QDateTime::fromString( end.toElement().text(), Qt::ISODate );

setFixedTemporalRange( range );
QgsDateTimeRange range = QgsDateTimeRange( beginDate, endDate );

if ( rangeString == QLatin1String( "fixedRange" ) )
setFixedTemporalRange( range );
if ( rangeString == QLatin1String( "normalRange" ) )
setTemporalRange( range );
if ( rangeString == QLatin1String( "referenceRange" ) )
setReferenceTemporalRange( range );
}
return true;
}

QDomElement QgsRasterLayerTemporalProperties::writeXml( QDomElement &element, QDomDocument &document, const QgsReadWriteContext &context )
{
Q_UNUSED( context );
Q_UNUSED( context )
if ( element.isNull() )
return QDomElement();

QDomElement temporalElement = document.createElement( QStringLiteral( "temporal" ) );
temporalElement.setAttribute( QStringLiteral( "mode" ), QString::number( mMode ) );

QDomElement rangeElement = document.createElement( QStringLiteral( "range" ) );
for ( QString rangeString : { "fixedRange", "normalRange", "referenceRange" } )
{
QgsDateTimeRange range;

if ( rangeString == QLatin1String( "fixedRange" ) )
range = mFixedRange;
if ( rangeString == QLatin1String( "normalRange" ) )
range = mRange;
if ( rangeString == QLatin1String( "referenceRange" ) )
range = mReferenceRange;

QDomElement startElement = document.createElement( QStringLiteral( "start" ) );
QDomElement endElement = document.createElement( QStringLiteral( "end" ) );
QDomElement rangeElement = document.createElement( QStringLiteral( rangeString ) );

QDomText startText = document.createTextNode( mRange.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
QDomText endText = document.createTextNode( mRange.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
QDomElement startElement = document.createElement( QStringLiteral( "start" ) );
QDomElement endElement = document.createElement( QStringLiteral( "end" ) );

startElement.appendChild( startText );
endElement.appendChild( endText );
QDomText startText = document.createTextNode( range.begin().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );
QDomText endText = document.createTextNode( range.end().toTimeSpec( Qt::OffsetFromUTC ).toString( Qt::ISODate ) );

rangeElement.appendChild( startElement );
rangeElement.appendChild( endElement );
startElement.appendChild( startText );
endElement.appendChild( endText );

temporalElement.appendChild( rangeElement );
rangeElement.appendChild( startElement );
rangeElement.appendChild( endElement );

temporalElement.appendChild( rangeElement );
}
element.appendChild( temporalElement );

return element;

0 comments on commit 391f606

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