diff --git a/src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp b/src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp index a672faa59b88..df4f668dd9b7 100644 --- a/src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp +++ b/src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp @@ -36,7 +36,22 @@ void QgsRasterDataProviderTemporalCapabilities::setTemporalRange( const QgsDateT if ( !isActive() ) setIsActive( true ); - mRange = dateTimeRange; + // Don't set temporal range outside fixed temporal range limits, + // instead set equal to the fixed temporal range + QDateTime begin; + QDateTime end; + + if ( dateTimeRange.begin() < mFixedRange.begin() ) + begin = mFixedRange.begin(); + else + begin = dateTimeRange.begin(); + + if ( dateTimeRange.end() > mFixedRange.end() ) + end = mFixedRange.end(); + else + end = dateTimeRange.end(); + + mRange = QgsDateTimeRange( begin, end ); } diff --git a/src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp b/src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp index 8e86c9b43fcf..cdd84797e876 100644 --- a/src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp +++ b/src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp @@ -37,7 +37,7 @@ void QgsRasterLayerTemporalPropertiesWidget::setEndAsStartNormalButton_clicked() { mEndTemporalDateTimeEdit->setDateTime( mStartTemporalDateTimeEdit->dateTime() ); // Update current selection label - // updateRangeLabel( "layer", mRangeLabel ); + updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel ); } void QgsRasterLayerTemporalPropertiesWidget::setEndAsStartReferenceButton_clicked() @@ -50,7 +50,7 @@ void QgsRasterLayerTemporalPropertiesWidget::layerRadioButton_clicked() if ( mLayerRadioButton->isChecked() ) { setInputWidgetState( TemporalDimension::NormalTemporal, true ); - // updateRangeLabel( "layer", mRangeLabel ); + updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel ); mProjectRadioButton->setChecked( false ); } else @@ -63,7 +63,7 @@ void QgsRasterLayerTemporalPropertiesWidget::projectRadioButton_clicked() { mLayerRadioButton->setChecked( false ); setInputWidgetState( TemporalDimension::NormalTemporal, false ); - // updateRangeLabel( "project", mRangeLabel ); + updateRangeLabel( TemporalRangeSource::Project, mRangeLabel ); } } @@ -81,24 +81,46 @@ void QgsRasterLayerTemporalPropertiesWidget::init() setInputWidgetState( TemporalDimension::BiTemporal, false ); setDateTimeInputsLimit(); - // updateRangeLabel( "layer", mRangeLabel ); + updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel ); } void QgsRasterLayerTemporalPropertiesWidget::setDateTimeInputsLimit() { QgsRasterLayer *layer = qobject_cast( mLayer ); - QgsDateTimeRange range = layer->dataProvider()->temporalCapabilities()->fixedTemporalRange(); - QgsDateTimeRange referenceRange = layer->dataProvider()->temporalCapabilities()->fixedReferenceTemporalRange(); + QgsDateTimeRange fixedRange = layer->dataProvider()->temporalCapabilities()->fixedTemporalRange(); + QgsDateTimeRange fixedReferenceRange = layer->dataProvider()->temporalCapabilities()->fixedReferenceTemporalRange(); + QgsDateTimeRange range = layer->dataProvider()->temporalCapabilities()->temporalRange(); + QgsDateTimeRange referenceRange = layer->dataProvider()->temporalCapabilities()->temporalRange(); + + // 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() ) + { + mStartTemporalDateTimeEdit->setDateTime( fixedRange.begin() ); + mEndTemporalDateTimeEdit->setDateTime( fixedRange.end() ); + } + } + if ( referenceRange.begin().isValid() && referenceRange.end().isValid() ) { - mStartReferenceDateTimeEdit->setDateTime( referenceRange.begin() ); - mEndReferenceDateTimeEdit->setDateTime( referenceRange.end() ); + mStartTemporalDateTimeEdit->setDateTime( referenceRange.begin() ); + mEndTemporalDateTimeEdit->setDateTime( referenceRange.end() ); + } + else + { + if ( fixedReferenceRange.begin().isValid() && fixedReferenceRange.end().isValid() ) + { + mStartReferenceDateTimeEdit->setDateTime( fixedReferenceRange.begin() ); + mEndReferenceDateTimeEdit->setDateTime( fixedReferenceRange.end() ); + } } } @@ -141,7 +163,7 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties() rasterLayer->dataProvider()->temporalCapabilities()->setEnableTime( true ); // Update current selection label - // updateRangeLabel( "layer", mRangeLabel ); + updateRangeLabel( TemporalRangeSource::Layer, mRangeLabel ); if ( mReferenceCheckBox->isChecked() ) { @@ -171,22 +193,34 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties() } } -void QgsRasterLayerTemporalPropertiesWidget::updateRangeLabel( QString type, QLabel *label ) +void QgsRasterLayerTemporalPropertiesWidget::updateRangeLabel( TemporalRangeSource source, QLabel *label ) { - if ( type == "layer" ) - label->setText( tr( "Current selection range: %1 to %2" ).arg( - mStartReferenceDateTimeEdit->dateTime().toString(), - mEndReferenceDateTimeEdit->dateTime().toString() ) ); - else if ( type == "project" ) + if ( source == TemporalRangeSource::Layer ) + { + if ( mLayer->type() == QgsMapLayerType::RasterLayer && + mLayer->providerType() == "wms" ) + { + QgsRasterLayer *rasterLayer = qobject_cast ( 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" ) ); + } + } + else if ( source == TemporalRangeSource::Project ) { - QgsDateTimeRange range = mCanvas->mapSettings().temporalRange(); - - if ( range.begin().isValid() && range.end().isValid() ) - label->setText( tr( "Current selection range: %1 to %2 from the project settings" ).arg( - range.begin().toString(), - range.end().toString() ) ); - else - label->setText( tr( "Date time range from the project is invalid, change it in Project options before using it here." ) ); +// QgsDateTimeRange range = QgsProject::instance()->timeSettings()->temporalRange(); + +// if ( range.begin().isValid() && range.end().isValid() ) +// label->setText( tr( "Current selection range: %1 to %2 from the project settings" ).arg( +// range.begin().toString(), +// range.end().toString() ) ); +// else +// label->setText( tr( "Date time range from the project is invalid, change it in Project options before using it here." ) ); } } diff --git a/src/gui/raster/qgsrasterlayertemporalpropertieswidget.h b/src/gui/raster/qgsrasterlayertemporalpropertieswidget.h index 2e0065ed1373..5b15395f398e 100644 --- a/src/gui/raster/qgsrasterlayertemporalpropertieswidget.h +++ b/src/gui/raster/qgsrasterlayertemporalpropertieswidget.h @@ -87,6 +87,16 @@ class GUI_EXPORT QgsRasterLayerTemporalPropertiesWidget : public QWidget, privat BiTemporal }; + /** + * Source where the temporal range will be taken from to update the layers + * temporal range. + */ + enum TemporalRangeSource + { + Layer, //! When current temporal range is from layer properties. + Project //! Using Project time settings temporal range + }; + private slots: /** @@ -127,7 +137,7 @@ class GUI_EXPORT QgsRasterLayerTemporalPropertiesWidget : public QWidget, privat * Updates the range label with current set datetime range. * **/ - void updateRangeLabel( QString type, QLabel *label ); + void updateRangeLabel( TemporalRangeSource source, QLabel *label ); /** * Sets the temporal date time inputs with layer's lower and upper diff --git a/src/providers/wms/qgswmscapabilities.cpp b/src/providers/wms/qgswmscapabilities.cpp index 93ada7d26f32..87f113cd370c 100644 --- a/src/providers/wms/qgswmscapabilities.cpp +++ b/src/providers/wms/qgswmscapabilities.cpp @@ -193,11 +193,6 @@ QgsDateTimeRange QgsWmsSettings::parseTemporalExtent( QgsWmstDimensionExtent dim QStringListIterator iter( parts ); - QgsWmstExtentPair pair; - - QgsWmstResolution resolution = pair.resolution; - QgsWmstDates datesList = pair.dates; - while ( iter.hasNext() ) { QString item = iter.next(); @@ -238,6 +233,11 @@ QgsDateTimeRange QgsWmsSettings::parseTemporalExtent( QgsWmstDimensionExtent dim continue; } + QgsWmstExtentPair pair; + + QgsWmstResolution resolution = pair.resolution; + QgsWmstDates datesList = pair.dates; + if ( item.startsWith( 'P' ) ) { resolution = parseWmstResolution( item ); @@ -255,14 +255,13 @@ QgsDateTimeRange QgsWmsSettings::parseTemporalExtent( QgsWmstDimensionExtent dim containResolution = false; } - - // Return the provider temporal take the begin date in first temporal range and - // and the end date in last temporal range + // Return the provider temporal take the date in first temporal range and + // and the date in last temporal range in the dimension ranges list if ( dimensionExtent.datesResolutionList.first().dates.dateTimes.size() > 0 ) { QDateTime begin = dimensionExtent.datesResolutionList.first().dates.dateTimes.first(); - QDateTime end = dimensionExtent.datesResolutionList.first().dates.dateTimes.last(); + QDateTime end = dimensionExtent.datesResolutionList.last().dates.dateTimes.last(); return QgsDateTimeRange( begin, end ); } diff --git a/src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui b/src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui index 2f4117a5600d..90459696f328 100644 --- a/src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui +++ b/src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui @@ -57,7 +57,7 @@ QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;} -background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;} +background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;}QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::title { subcontrol-origin: margin; subcontrol-position: top left; margin-left: 20px; margin-right: 5px; left: 0px; top: 1px;} Temporal @@ -93,6 +93,13 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti 0 + + + + + + + diff --git a/tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp b/tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp index 89dcf4b36a0c..ba2bdbdc1c08 100644 --- a/tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp +++ b/tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp @@ -87,12 +87,19 @@ void TestQgsRasterDataProviderTemporalCapabilities::checkTemporalRange() QDateTime( QDate( 2020, 12, 31 ) ) ); QgsDateTimeRange dateTimeRange = QgsDateTimeRange( QDateTime( QDate( 2020, 1, 1 ) ), QDateTime( QDate( 2020, 3, 1 ) ) ); + QgsDateTimeRange outOfLimitsRange = QgsDateTimeRange( QDateTime( QDate( 2019, 1, 1 ) ), + QDateTime( QDate( 2021, 3, 1 ) ) ); - temporalCapabilities->setTemporalRange( dateTimeRange ); temporalCapabilities->setFixedTemporalRange( fixedDateTimeRange ); + temporalCapabilities->setTemporalRange( dateTimeRange ); - QCOMPARE( temporalCapabilities->temporalRange(), dateTimeRange ); QCOMPARE( temporalCapabilities->fixedTemporalRange(), fixedDateTimeRange ); + QCOMPARE( temporalCapabilities->temporalRange(), dateTimeRange ); + + // Test setting out of fixed temporal range limits, should default to + // using fixed temporal range + temporalCapabilities->setTemporalRange( outOfLimitsRange ); + QCOMPARE( temporalCapabilities->temporalRange(), fixedDateTimeRange ); } void TestQgsRasterDataProviderTemporalCapabilities::checkReferenceTemporalRange()