Skip to content
Permalink
Browse files

added checks for possible null temporal capabilities

  • Loading branch information
Samweli authored and nyalldawson committed Feb 26, 2020
1 parent ccf8a03 commit 51b475f6893a1e28879af68953542eee4ec73931
@@ -14,7 +14,10 @@
class QgsMapLayerTemporalProperties : QgsTemporalProperty
{
%Docstring
An abstract base class for handling map layer temporal properties.
Base class for storage of map layer temporal properties.

QgsMapLayerTemporalProperties expose user-configurable settings for controlling
how an individual QgsMapLayer behaves in a temporal context, e.g. while animating a map object.

.. versionadded:: 3.14
%End
@@ -34,7 +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.
@@ -27,11 +27,6 @@ A widget for configuring the temporal properties for a raster layer.
QgsRasterLayerTemporalPropertiesWidget( QWidget *parent = 0, QgsMapLayer *layer = 0 );
%Docstring
Constructor for QgsRasterLayerTemporalPropertiesWidget.
%End

void setMapCanvas( QgsMapCanvas *canvas );
%Docstring
Sets the map canvas associtated with this temporal widget.
%End

void saveTemporalProperties();
@@ -29,7 +29,10 @@
/**
* \class QgsMapLayerTemporalProperties
* \ingroup core
* An abstract base class for handling map layer temporal properties.
* Base class for storage of map layer temporal properties.
*
* QgsMapLayerTemporalProperties expose user-configurable settings for controlling
* how an individual QgsMapLayer behaves in a temporal context, e.g. while animating a map object.
*
* \since QGIS 3.14
*/
@@ -22,15 +22,6 @@ QgsRasterDataProviderTemporalCapabilities::QgsRasterDataProviderTemporalCapabili
{
}

//QgsRasterDataProviderTemporalProperties &QgsRasterDataProviderTemporalProperties::operator=( const QgsRasterDataProviderTemporalProperties &other )
//{
// mRange = other.mRange;
// mFixedRange = other.mFixedRange;
// mEnableTime = other.mEnableTime;

// return *this;
//}

void QgsRasterDataProviderTemporalCapabilities::setTemporalRange( const QgsDateTimeRange &dateTimeRange )
{
if ( !isActive() )
@@ -41,12 +32,14 @@ void QgsRasterDataProviderTemporalCapabilities::setTemporalRange( const QgsDateT
QDateTime begin;
QDateTime end;

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

if ( dateTimeRange.end() > mFixedRange.end() )
if ( mFixedRange.end().isValid() &&
( dateTimeRange.end() > mFixedRange.end() ) )
end = mFixedRange.end();
else
end = dateTimeRange.end();
@@ -46,8 +46,6 @@ class CORE_EXPORT QgsRasterDataProviderTemporalCapabilities : public QgsDataProv

virtual ~QgsRasterDataProviderTemporalCapabilities() = default;

// QgsRasterDataProviderTemporalCapabilities &operator=( const QgsRasterDataProviderTemporalProperties &other );

/**
* Sets the current active datetime range for the temporal properties.
*
@@ -272,13 +272,18 @@ QgsRasterLayerProperties::QgsRasterLayerProperties( QgsMapLayer *lyr, QgsMapCanv
metadataFrame->setLayout( layout );

// Temporal options

if ( mRasterLayer->temporalProperties()->isActive() ||
mRasterLayer->dataProvider()->temporalCapabilities()->isActive() )
// Check if temporal properties of the raster layer are available and active,
// if not check if the layer has temporal capabilities from its provider
// and they are active.
if ( ( mRasterLayer->temporalProperties() &&
mRasterLayer->temporalProperties()->isActive() ) ||
( mRasterLayer->dataProvider() &&
mRasterLayer->dataProvider()->temporalCapabilities() &&
mRasterLayer->dataProvider()->temporalCapabilities()->isActive()
) )
{
QVBoxLayout *temporalLayout = new QVBoxLayout( temporalFrame );
mTemporalWidget = new QgsRasterLayerTemporalPropertiesWidget( this, mRasterLayer );
mTemporalWidget->setMapCanvas( mMapCanvas );
temporalLayout->addWidget( mTemporalWidget );

}
@@ -87,39 +87,42 @@ void QgsRasterLayerTemporalPropertiesWidget::init()
void QgsRasterLayerTemporalPropertiesWidget::setDateTimeInputsLimit()
{
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( mLayer );
QgsDateTimeRange fixedRange = layer->dataProvider()->temporalCapabilities()->fixedTemporalRange();
QgsDateTimeRange fixedReferenceRange = layer->dataProvider()->temporalCapabilities()->fixedReferenceTemporalRange();
if ( layer->dataProvider() && layer->dataProvider()->temporalCapabilities() )
{
QgsDateTimeRange fixedRange = layer->dataProvider()->temporalCapabilities()->fixedTemporalRange();
QgsDateTimeRange fixedReferenceRange = layer->dataProvider()->temporalCapabilities()->fixedReferenceTemporalRange();

QgsDateTimeRange range = layer->dataProvider()->temporalCapabilities()->temporalRange();
QgsDateTimeRange referenceRange = layer->dataProvider()->temporalCapabilities()->temporalRange();
QgsDateTimeRange range = layer->dataProvider()->temporalCapabilities()->temporalRange();
QgsDateTimeRange referenceRange = layer->dataProvider()->temporalCapabilities()->referenceTemporalRange();

// Set initial date time input values to the layers temporal range only if the
// ranges are valid
if ( range.begin().isValid() && range.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( range.begin() );
mEndTemporalDateTimeEdit->setDateTime( range.end() );
}
else
{
if ( fixedRange.begin().isValid() && fixedRange.end().isValid() )
// Set initial date time input values to the layers temporal range only if the
// ranges are valid
if ( range.begin().isValid() && range.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( fixedRange.begin() );
mEndTemporalDateTimeEdit->setDateTime( fixedRange.end() );
mStartTemporalDateTimeEdit->setDateTime( range.begin() );
mEndTemporalDateTimeEdit->setDateTime( range.end() );
}
else
{
if ( fixedRange.begin().isValid() && fixedRange.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( fixedRange.begin() );
mEndTemporalDateTimeEdit->setDateTime( fixedRange.end() );
}
}
}

if ( referenceRange.begin().isValid() && referenceRange.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( referenceRange.begin() );
mEndTemporalDateTimeEdit->setDateTime( referenceRange.end() );
}
else
{
if ( fixedReferenceRange.begin().isValid() && fixedReferenceRange.end().isValid() )
if ( referenceRange.begin().isValid() && referenceRange.end().isValid() )
{
mStartReferenceDateTimeEdit->setDateTime( fixedReferenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( fixedReferenceRange.end() );
mStartReferenceDateTimeEdit->setDateTime( referenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( referenceRange.end() );
}
else
{
if ( fixedReferenceRange.begin().isValid() && fixedReferenceRange.end().isValid() )
{
mStartReferenceDateTimeEdit->setDateTime( fixedReferenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( fixedReferenceRange.end() );
}
}
}
}
@@ -140,50 +143,50 @@ void QgsRasterLayerTemporalPropertiesWidget::setInputWidgetState( TemporalDimens
}
}

void QgsRasterLayerTemporalPropertiesWidget::setMapCanvas( QgsMapCanvas *canvas )
{
mCanvas = canvas;
}

void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
{
if ( mLayerRadioButton->isChecked() )
{
if ( mLayer->type() == QgsMapLayerType::RasterLayer &&
mLayer->providerType() == "wms" )
if ( mLayer->type() == QgsMapLayerType::RasterLayer )
{
QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
mEndTemporalDateTimeEdit->dateTime() );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( mLayer );
rasterLayer->dataProvider()->temporalCapabilities()->setTemporalRange( normalRange );

if ( mDisableTime->isChecked() )
rasterLayer->dataProvider()->temporalCapabilities()->setEnableTime( false );
else
rasterLayer->dataProvider()->temporalCapabilities()->setEnableTime( true );
if ( rasterLayer->dataProvider() && rasterLayer->dataProvider()->temporalCapabilities() )
{
rasterLayer->dataProvider()->temporalCapabilities()->setTemporalRange( normalRange );

if ( mDisableTime->isChecked() )
rasterLayer->dataProvider()->temporalCapabilities()->setEnableTime( false );
else
rasterLayer->dataProvider()->temporalCapabilities()->setEnableTime( true );

// Update current selection label
updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel );
// Update current selection label
updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel );

if ( mReferenceCheckBox->isChecked() )
{
QgsDateTimeRange referenceRange = QgsDateTimeRange( mStartReferenceDateTimeEdit->dateTime(),
mEndReferenceDateTimeEdit->dateTime() );
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceTemporalRange( referenceRange );
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceEnable( true );
if ( mReferenceCheckBox->isChecked() )
{
QgsDateTimeRange referenceRange = QgsDateTimeRange( mStartReferenceDateTimeEdit->dateTime(),
mEndReferenceDateTimeEdit->dateTime() );

rasterLayer->dataProvider()->temporalCapabilities()->setReferenceEnable( true );
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceTemporalRange( referenceRange );
}
else
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceEnable( false );
}
else
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceEnable( false );
}
}

if ( mProjectRadioButton->isChecked() )
if ( mProjectRadioButton->isChecked() )
{
if ( mLayer->type() == QgsMapLayerType::RasterLayer )
{
if ( mLayer->type() == QgsMapLayerType::RasterLayer &&
mLayer->providerType() == "wms" )
{
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *> ( mLayer );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *> ( mLayer );
// rasterLayer->dataProvider()->temporalCapabilities()->setTemporalRange( projectRange );

if ( rasterLayer->dataProvider() && rasterLayer->dataProvider()->temporalCapabilities() )
{
if ( mReferenceCheckBox->isChecked() )
rasterLayer->dataProvider()->temporalCapabilities()->setReferenceEnable( true );
else
@@ -201,14 +204,18 @@ void QgsRasterLayerTemporalPropertiesWidget::updateRangeLabel( TemporalRangeSour
mLayer->providerType() == "wms" )
{
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *> ( mLayer );
QgsDateTimeRange range = rasterLayer->dataProvider()->temporalCapabilities()->temporalRange();

if ( range.begin().isValid() && range.end().isValid() )
label->setText( tr( "Current layer range: %1 to %2" ).arg(
range.begin().toString(),
range.end().toString() ) );
else
label->setText( tr( "Layer temporal range is not set" ) );

if ( rasterLayer->dataProvider() && rasterLayer->dataProvider()->temporalCapabilities() )
{
QgsDateTimeRange range = rasterLayer->dataProvider()->temporalCapabilities()->temporalRange();

if ( range.begin().isValid() && range.end().isValid() )
label->setText( tr( "Current layer range: %1 to %2" ).arg(
range.begin().toString(),
range.end().toString() ) );
else
label->setText( tr( "Layer temporal range is not set" ) );
}
}
}
else if ( source == TemporalRangeSource::Project )
@@ -43,12 +43,6 @@ class GUI_EXPORT QgsRasterLayerTemporalPropertiesWidget : public QWidget, privat
*/
QgsRasterLayerTemporalPropertiesWidget( QWidget *parent = nullptr, QgsMapLayer *layer = nullptr );

/**
* Sets the map canvas associtated with this temporal widget.
*
*/
void setMapCanvas( QgsMapCanvas *canvas );

/**
* Save widget temporal properties inputs.
*/
@@ -283,7 +283,6 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
{
resolution.year = resolutionValue;
found = true;

}
if ( datesSymbol == 'M' && item.contains( 'M' ) )
{
@@ -309,7 +308,6 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )
number.length() );
found = false;
}

}
if ( !item.contains( 'T' ) )
return resolution;
@@ -353,12 +351,12 @@ QgsWmstResolution QgsWmsSettings::parseWmstResolution( QString item )

QDateTime QgsWmsSettings::parseWmstDateTimes( QString item )
{
// Standard item will have YYYY-MM-DDThh:mm:ss.SSSZ
// format a Qt::ISODateWithMs
// Standard item will have a YYYY-MM-DDThh:mm:ss.SSSZ
// format similar to Qt::ISODateWithMs

QString format = "YYYY-MM-DDThh:mm:ss.SSSZ";

// Check if it does not have time part
// Check if it does not have the time part
if ( !item.contains( 'T' ) )
return QDateTime::fromString( item, "yyyy-MM-dd" );
else
@@ -366,17 +366,14 @@ QString QgsWMSLayerItem::createUri()
mDataSourceUri.setParam( QStringLiteral( "styles" ), style );

// Check for layer dimensions
if ( !mLayerProperty.dimensions.empty() )
for ( const QgsWmsDimensionProperty &dimension : qgis::as_const( mLayerProperty.dimensions ) )
{
for ( const QgsWmsDimensionProperty &dimension : qgis::as_const( mLayerProperty.dimensions ) )
// add temporal dimensions only
if ( dimension.name == "time" || dimension.name == "reference_time" )
{
// add temporal dimensions only
if ( dimension.name == "time" || dimension.name == "reference_time" )
{
if ( !( mDataSourceUri.param( "type" ) == "wmst" ) )
mDataSourceUri.setParam( "type", "wmst" );
mDataSourceUri.setParam( dimension.name, dimension.extent );
}
if ( !( mDataSourceUri.param( "type" ) == "wmst" ) )
mDataSourceUri.setParam( "type", "wmst" );
mDataSourceUri.setParam( dimension.name, dimension.extent );
}
}

@@ -154,11 +154,14 @@ QgsWmsProvider::QgsWmsProvider( QString const &uri, const ProviderOptions &optio
// Setup temporal properties for layers in WMS-T
if ( mSettings.mIsTemporal )
{
temporalCapabilities()->setFixedTemporalRange( mSettings.mFixedRange );
if ( mSettings.mIsBiTemporal )
if ( temporalCapabilities() )
{
temporalCapabilities()->setFixedReferenceTemporalRange( mSettings.mFixedReferenceRange );
temporalCapabilities()->setHasReference( true );
temporalCapabilities()->setFixedTemporalRange( mSettings.mFixedRange );
if ( mSettings.mIsBiTemporal )
{
temporalCapabilities()->setFixedReferenceTemporalRange( mSettings.mFixedReferenceRange );
temporalCapabilities()->setHasReference( true );
}
}
}
}
@@ -1044,7 +1047,8 @@ QUrl QgsWmsProvider::createRequestUrlWMS( const QgsRectangle &viewExtent, int pi
setQueryItem( query, QStringLiteral( "STYLES" ), styles );

// For WMS-T layers
if ( temporalCapabilities()->isActive() )
if ( temporalCapabilities() &&
temporalCapabilities()->isActive() )
{
addWmstParameters( query );
}
@@ -1105,7 +1109,7 @@ void QgsWmsProvider::addWmstParameters( QUrlQuery &query )

if ( referenceRange.begin() == referenceRange.end() )
setQueryItem( query, QStringLiteral( "DIM_REFERENCE_TIME" ),
range.begin().toString( format ) );
referenceRange.begin().toString( format ) );
else
{
QString extent = referenceRange.begin().toString( format );

0 comments on commit 51b475f

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