Skip to content
Permalink
Browse files

Don't automatically set every raster layer loaded with a project

as temporal enabled

And add unit tests for raster layer temporal properties read/write
  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent dbc0b46 commit 79fb8fb1f164e322d6549c0e1f8864c46f52998b
@@ -87,10 +87,6 @@ void QgsRasterLayerTemporalProperties::setTemporalRange( const QgsDateTimeRange
{
// Don't set temporal range outside fixed temporal range limits,
// instead set equal to the fixed temporal range

if ( !isActive() )
setIsActive( true );

if ( mFixedRange.contains( dateTimeRange ) )
mRange = dateTimeRange;
else
@@ -120,6 +116,8 @@ bool QgsRasterLayerTemporalProperties::readXml( const QDomElement &element, cons

QDomElement temporalNode = element.firstChildElement( QStringLiteral( "temporal" ) );

setIsActive( temporalNode.attribute( QStringLiteral( "enabled" ), QStringLiteral( "0" ) ).toInt() );

mMode = static_cast< TemporalMode >( temporalNode.attribute( QStringLiteral( "mode" ), QStringLiteral( "0" ) ). toInt() );
mIntervalHandlingMethod = static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >( temporalNode.attribute( QStringLiteral( "fetchMode" ), QStringLiteral( "0" ) ). toInt() );

@@ -161,6 +159,7 @@ QDomElement QgsRasterLayerTemporalProperties::writeXml( QDomElement &element, QD
return QDomElement();

QDomElement temporalElement = document.createElement( QStringLiteral( "temporal" ) );
temporalElement.setAttribute( QStringLiteral( "enabled" ), isActive() ? QStringLiteral( "1" ) : QStringLiteral( "0" ) );
temporalElement.setAttribute( QStringLiteral( "mode" ), QString::number( mMode ) );
temporalElement.setAttribute( QStringLiteral( "source" ), QString::number( temporalSource() ) );
temporalElement.setAttribute( QStringLiteral( "fetchMode" ), QString::number( mIntervalHandlingMethod ) );
@@ -95,9 +95,41 @@ void TestQgsRasterLayerTemporalProperties::testReadWrite()
// read none existant node
temporalProperties.readXml( node.toElement(), QgsReadWriteContext() );

// should not be active
// must not be active!
QVERIFY( !temporalProperties.isActive() );

temporalProperties.setIsActive( true );
temporalProperties.setMode( QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider );
temporalProperties.setIntervalHandlingMethod( QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );

temporalProperties.writeXml( node, doc, QgsReadWriteContext() );

QgsRasterLayerTemporalProperties temporalProperties2;
temporalProperties2.readXml( node, QgsReadWriteContext() );
QVERIFY( temporalProperties2.isActive() );
QCOMPARE( temporalProperties2.mode(), QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider );
QCOMPARE( temporalProperties2.intervalHandlingMethod(), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );

temporalProperties.setIsActive( false );
QDomElement node2 = doc.createElement( QStringLiteral( "temp" ) );
temporalProperties.writeXml( node2, doc, QgsReadWriteContext() );
QgsRasterLayerTemporalProperties temporalProperties3;
temporalProperties3.readXml( node2, QgsReadWriteContext() );
QVERIFY( !temporalProperties3.isActive() );
QCOMPARE( temporalProperties3.mode(), QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider );
QCOMPARE( temporalProperties3.intervalHandlingMethod(), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );

temporalProperties.setMode( QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
temporalProperties.setFixedTemporalRange( QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 12, 31 ) ) ) );
QDomElement node3 = doc.createElement( QStringLiteral( "temp" ) );
temporalProperties.writeXml( node3, doc, QgsReadWriteContext() );
QgsRasterLayerTemporalProperties temporalProperties4;
temporalProperties4.readXml( node3, QgsReadWriteContext() );
QVERIFY( !temporalProperties4.isActive() );
QCOMPARE( temporalProperties4.mode(), QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
QCOMPARE( temporalProperties4.fixedTemporalRange(), QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ),
QDateTime( QDate( 2020, 12, 31 ) ) ) );

}

0 comments on commit 79fb8fb

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