Skip to content
Permalink
Browse files

[FEATURE] For wms-t layers which expose a non-contiguous set of

available temporal instances, show a combo box in the layer
temporal properties with available times instead of requiring
users to manually enter date time ranges themselves

Refs Natural resources Canada Contract: 3000720707
  • Loading branch information
nyalldawson committed Mar 24, 2021
1 parent 5b6ff74 commit 1ec894d45d1c98eccfc79dff8e6e872be556d967
Showing with 92 additions and 31 deletions.
  1. +40 −6 src/providers/wms/qgswmstsettingswidget.cpp
  2. +52 −25 src/ui/qgswmstsettingswidgetbase.ui
@@ -38,7 +38,11 @@ QgsWmstSettingsWidget::QgsWmstSettingsWidget( QgsMapLayer *layer, QgsMapCanvas *
{
mEndStaticDateTimeEdit->setDateTime( mStartStaticDateTimeEdit->dateTime() );
} );
connect( mStaticTemporalRangeRadio, &QRadioButton::toggled, mStaticWmstFrame, &QWidget::setEnabled );
connect( mStaticTemporalRangeRadio, &QRadioButton::toggled, mStaticWmstRangeFrame, &QWidget::setEnabled );
connect( mStaticTemporalRangeRadio, &QRadioButton::toggled, mStaticWmstChoiceFrame, &QWidget::setEnabled );

mStaticWmstRangeFrame->setEnabled( false );
mStaticWmstChoiceFrame->setEnabled( false );

syncToLayer( mRasterLayer );

@@ -72,6 +76,24 @@ void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )
const QgsDateTimeRange availableProviderRange = mRasterLayer->dataProvider()->temporalCapabilities()->availableTemporalRange();
const QgsDateTimeRange availableReferenceRange = mRasterLayer->dataProvider()->temporalCapabilities()->availableReferenceTemporalRange();

const QList< QgsDateTimeRange > allAvailableRanges = mRasterLayer->dataProvider()->temporalCapabilities()->allAvailableTemporalRanges();
// determine if available ranges are a set of non-contiguous instants, and if so, we show a combobox to users instead of the free-form date widgets
if ( std::all_of( allAvailableRanges.cbegin(), allAvailableRanges.cend(), []( const QgsDateTimeRange & range ) { return range.isInstant(); } ) )
{
mStaticWmstRangeFrame->hide();
mStaticWmstChoiceFrame->show();
mStaticWmstRangeCombo->clear();
for ( const QgsDateTimeRange &range : allAvailableRanges )
{
mStaticWmstRangeCombo->addItem( range.begin().toString( Qt::ISODate ), QVariant::fromValue( range ) );
}
}
else
{
mStaticWmstRangeFrame->show();
mStaticWmstChoiceFrame->hide();
}

QgsProviderMetadata *metadata = QgsProviderRegistry::instance()->providerMetadata(
mRasterLayer->providerType() );

@@ -101,9 +123,20 @@ void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )
const QString time = uri.value( QStringLiteral( "time" ) ).toString();
if ( !time.isEmpty() )
{
QStringList parts = time.split( '/' );
mStartStaticDateTimeEdit->setDateTime( QDateTime::fromString( parts.at( 0 ), Qt::ISODateWithMs ) );
mEndStaticDateTimeEdit->setDateTime( QDateTime::fromString( parts.at( 1 ), Qt::ISODateWithMs ) );
const QStringList parts = time.split( '/' );
const QgsDateTimeRange range( QDateTime::fromString( parts.at( 0 ), Qt::ISODateWithMs ), QDateTime::fromString( parts.at( 1 ), Qt::ISODateWithMs ) );

mStartStaticDateTimeEdit->setDateTime( range.begin() );
mEndStaticDateTimeEdit->setDateTime( range.end() );

if ( const int index = mStaticWmstRangeCombo->findData( QVariant::fromValue( range ) ); index >= 0 )
mStaticWmstRangeCombo->setCurrentIndex( index );
else if ( mStaticWmstRangeCombo->count() > 0 )
mStaticWmstRangeCombo->setCurrentIndex( 0 );
}
else if ( mStaticWmstRangeCombo->count() > 0 )
{
mStaticWmstRangeCombo->setCurrentIndex( 0 );
}

const QString referenceTimeExtent = uri.value( QStringLiteral( "referenceTimeDimensionExtent" ) ).toString();
@@ -189,8 +222,9 @@ void QgsWmstSettingsWidget::apply()
{
if ( mStaticTemporalRangeRadio->isChecked() )
{
QString time = mStartStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs ) + '/' +
mEndStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
const QString time = mStaticWmstRangeCombo->count() > 0
? ( mStaticWmstRangeCombo->currentData().value< QgsDateTimeRange >().begin().toString( Qt::ISODateWithMs ) + '/' + mStaticWmstRangeCombo->currentData().value< QgsDateTimeRange >().end().toString( Qt::ISODateWithMs ) )
: ( mStartStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs ) + '/' + mEndStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs ) );
uri[ QStringLiteral( "time" ) ] = time;
uri[ QStringLiteral( "temporalSource" ) ] = QLatin1String( "provider" );
}
@@ -78,7 +78,7 @@
<widget class="QgsDateTimeEdit" name="mReferenceDateTimeEdit">
<property name="dateTime">
<datetime>
<hour>14</hour>
<hour>4</hour>
<minute>20</minute>
<second>36</second>
<year>2020</year>
@@ -187,7 +187,7 @@
<number>0</number>
</property>
<item row="2" column="0">
<widget class="QFrame" name="mStaticWmstFrame">
<widget class="QFrame" name="mStaticWmstRangeFrame">
<property name="enabled">
<bool>false</bool>
</property>
@@ -210,18 +210,28 @@
<property name="bottomMargin">
<number>0</number>
</property>
<item row="2" column="1" colspan="2">
<widget class="QPushButton" name="mSetEndAsStartStaticButton">
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Set end same as start</string>
<string>Start date</string>
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="label_10">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;If the capabilities of this layer move out of this time range the range will be reset to layer's advertised default layer time range.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="0" column="1" colspan="2">
<widget class="QgsDateTimeEdit" name="mStartStaticDateTimeEdit">
<property name="dateTime">
<datetime>
<hour>17</hour>
<hour>7</hour>
<minute>3</minute>
<second>57</second>
<year>2020</year>
@@ -243,20 +253,6 @@
</property>
</widget>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label_13">
<property name="text">
<string>Start date</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>End date</string>
</property>
</widget>
</item>
<item row="1" column="1" colspan="2">
<widget class="QgsDateTimeEdit" name="mEndStaticDateTimeEdit">
<property name="displayFormat">
@@ -270,13 +266,17 @@
</property>
</widget>
</item>
<item row="3" column="0" colspan="3">
<widget class="QLabel" name="label_10">
<item row="2" column="1" colspan="2">
<widget class="QPushButton" name="mSetEndAsStartStaticButton">
<property name="text">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-style:italic;&quot;&gt;If the capabilities of this layer move out of this time range the range will be reset to layer's advertised default layer time range.&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
<string>Set end same as start</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>End date</string>
</property>
</widget>
</item>
@@ -338,6 +338,33 @@
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QFrame" name="mStaticWmstChoiceFrame">
<property name="frameShape">
<enum>QFrame::NoFrame</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_4">
<property name="leftMargin">
<number>20</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QComboBox" name="mStaticWmstRangeCombo"/>
</item>
</layout>
</widget>
</item>
</layout>
</widget>
</widget>

0 comments on commit 1ec894d

Please sign in to comment.