Skip to content
Permalink
Browse files

[wms] Use a combobox for selecting from available reference times

for wms-t layers instead of a freeform date widget

Otherwise the user has no guidance in picking valid date values
which correspond to reference times where the server has data
available
  • Loading branch information
nyalldawson committed Mar 25, 2021
1 parent ccdba4e commit 89491b5cffc0d0a111cc92bf4ae8d2530c7a98e8
Showing with 44 additions and 12 deletions.
  1. +31 −2 src/providers/wms/qgswmstsettingswidget.cpp
  2. +13 −10 src/ui/qgswmstsettingswidgetbase.ui
@@ -23,6 +23,7 @@
#include "qgsrasterlayertemporalproperties.h"
#include "qgsproviderregistry.h"
#include "qgsprovidermetadata.h"
#include "qgstemporalutils.h"

QgsWmstSettingsWidget::QgsWmstSettingsWidget( QgsMapLayer *layer, QgsMapCanvas *canvas, QWidget *parent )
: QgsMapLayerConfigWidget( layer, canvas, parent )
@@ -43,6 +44,8 @@ QgsWmstSettingsWidget::QgsWmstSettingsWidget( QgsMapLayer *layer, QgsMapCanvas *

mStaticWmstRangeFrame->setEnabled( false );
mStaticWmstChoiceFrame->setEnabled( false );
mReferenceTimeCombo->hide();
mReferenceDateTimeEdit->show();

syncToLayer( mRasterLayer );

@@ -173,10 +176,35 @@ void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )
mReferenceTimeExtentLabel->setText( tr( "Reported reference time extent: <i>%1</i>" ).arg( referenceTimeExtent ) );
mReferenceTimeGroupBox->setEnabled( true );
mReferenceTimeGroupBox->setChecked( !referenceTime.isEmpty() );

bool ok = false;
bool maxValuesExceeded = false;
const QList< QDateTime > availableReferenceTimes = QgsTemporalUtils::calculateDateTimesFromISO8601( referenceTimeExtent, ok, maxValuesExceeded, 30 );
mReferenceTimeCombo->clear();
if ( ok && !maxValuesExceeded )
{
mReferenceTimeCombo->show();
mReferenceDateTimeEdit->hide();
for ( const QDateTime &date : availableReferenceTimes )
{
mReferenceTimeCombo->addItem( date.toString( Qt::ISODate ), QVariant::fromValue( date ) );
}
}
else
{
mReferenceTimeCombo->hide();
mReferenceDateTimeEdit->show();
}
}
if ( !referenceTime.isEmpty() && !referenceTimeExtent.isEmpty() )
{
mReferenceDateTimeEdit->setDateTime( QDateTime::fromString( referenceTime, Qt::ISODateWithMs ) );
const QDateTime referenceDateTime = QDateTime::fromString( referenceTime, Qt::ISODateWithMs );
mReferenceDateTimeEdit->setDateTime( referenceDateTime );

if ( const int index = mReferenceTimeCombo->findData( QVariant::fromValue( referenceDateTime ) ); index >= 0 )
mReferenceTimeCombo->setCurrentIndex( index );
else if ( mReferenceTimeCombo->count() > 0 )
mReferenceTimeCombo->setCurrentIndex( 0 );
}

mFetchModeComboBox->addItem( tr( "Use Whole Temporal Range" ), QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange );
@@ -235,7 +263,8 @@ void QgsWmstSettingsWidget::apply()

if ( mReferenceTimeGroupBox->isChecked() )
{
QString referenceTime = mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
const QString referenceTime = mReferenceTimeCombo->count() > 0 ? mReferenceTimeCombo->currentData().value< QDateTime >().toString( Qt::ISODateWithMs )
: mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri[ QStringLiteral( "referenceTime" ) ] = referenceTime;
}
else
@@ -331,16 +331,6 @@
<bool>true</bool>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="mReferenceTimeExtentLabel">
<property name="text">
<string>No reference time is reported in the layer's capabilities.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="0" colspan="2">
<widget class="QgsDateTimeEdit" name="mReferenceDateTimeEdit">
<property name="dateTime">
@@ -377,6 +367,19 @@
</property>
</widget>
</item>
<item row="0" column="0" colspan="2">
<widget class="QLabel" name="mReferenceTimeExtentLabel">
<property name="text">
<string>No reference time is reported in the layer's capabilities.</string>
</property>
<property name="wordWrap">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="0" colspan="2">
<widget class="QComboBox" name="mReferenceTimeCombo"/>
</item>
</layout>
</widget>
</item>

0 comments on commit 89491b5

Please sign in to comment.