Skip to content

Commit

Permalink
added current layer range label
Browse files Browse the repository at this point in the history
  • Loading branch information
Samweli authored and nyalldawson committed Mar 5, 2020
1 parent f39a576 commit d7616bf
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 37 deletions.
17 changes: 16 additions & 1 deletion src/core/raster/qgsrasterdataprovidertemporalcapabilities.cpp
Expand Up @@ -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 );

}

Expand Down
80 changes: 57 additions & 23 deletions src/gui/raster/qgsrasterlayertemporalpropertieswidget.cpp
Expand Up @@ -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()
Expand All @@ -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
Expand All @@ -63,7 +63,7 @@ void QgsRasterLayerTemporalPropertiesWidget::projectRadioButton_clicked()
{
mLayerRadioButton->setChecked( false );
setInputWidgetState( TemporalDimension::NormalTemporal, false );
// updateRangeLabel( "project", mRangeLabel );
updateRangeLabel( TemporalRangeSource::Project, mRangeLabel );
}
}

Expand All @@ -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<QgsRasterLayer *>( 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() );
}
}
}

Expand Down Expand Up @@ -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() )
{
Expand Down Expand Up @@ -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<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" ) );
}
}
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." ) );
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/gui/raster/qgsrasterlayertemporalpropertieswidget.h
Expand Up @@ -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:

/**
Expand Down Expand Up @@ -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
Expand Down
17 changes: 8 additions & 9 deletions src/providers/wms/qgswmscapabilities.cpp
Expand Up @@ -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();
Expand Down Expand Up @@ -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 );
Expand All @@ -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 );
}
Expand Down
9 changes: 8 additions & 1 deletion src/ui/raster/qgsrasterlayertemporalpropertieswidgetbase.ui
Expand Up @@ -57,7 +57,7 @@
</property>
<property name="styleSheet">
<string notr="true">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;}</string>
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;}</string>
</property>
<property name="title">
<string>Temporal</string>
Expand Down Expand Up @@ -93,6 +93,13 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
<number>0</number>
</property>
<layout class="QVBoxLayout" name="verticalLayout_11">
<item>
<widget class="QLabel" name="mRangeLabel">
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QRadioButton" name="mLayerRadioButton">
<property name="text">
Expand Down
11 changes: 9 additions & 2 deletions tests/src/core/testqgsrasterdataprovidertemporalcapabilities.cpp
Expand Up @@ -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()
Expand Down

0 comments on commit d7616bf

Please sign in to comment.