Skip to content
Permalink
Browse files

WMS-T settings cleanup part 2

- Use a cleaner stacked widget approach to disabling the static
wms-t time range settings whenever the layer is set to dynamic
temporal control

- When a layer isn't using dynamic temporal control, use three
radio button states to represent the static wms-t mode instead
of 2 buttons and checkbox. (The three states are "server default",
"predefined range" and "follow project's temporal range")

- Use a cleaner approach to showing warnings about why the project
temporal range option is disabled
  • Loading branch information
nyalldawson committed Mar 24, 2021
1 parent 331aad6 commit 4be88aac5d6a06ae17ee007112936b7b93e403a0
@@ -38,14 +38,30 @@ QgsWmstSettingsWidget::QgsWmstSettingsWidget( QgsMapLayer *layer, QgsMapCanvas *
{
mEndStaticDateTimeEdit->setDateTime( mStartStaticDateTimeEdit->dateTime() );
} );
connect( mProjectTemporalRange, &QRadioButton::toggled, this, &QgsWmstSettingsWidget::passProjectTemporalRange_toggled );

connect( mStaticTemporalRange, &QRadioButton::toggled, mStaticWmstFrame, &QWidget::setEnabled );
connect( mStaticTemporalRangeRadio, &QRadioButton::toggled, mStaticWmstFrame, &QWidget::setEnabled );

syncToLayer( mRasterLayer );

if ( mRasterLayer->temporalProperties() )
connect( mRasterLayer->temporalProperties(), &QgsRasterLayerTemporalProperties::changed, this, &QgsWmstSettingsWidget::temporalPropertiesChange );

QgsDateTimeRange range;
if ( QgsProject::instance()->timeSettings() )
range = QgsProject::instance()->timeSettings()->temporalRange();

if ( range.begin().isValid() && range.end().isValid() )
mProjectTemporalRangeLabel->setText( tr( "Project temporal range is set from %1 to %2" ).arg(
range.begin().toString( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) ),
range.end().toString( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) )
) );
else
{
mProjectTemporalRangeRadio->setEnabled( false );
mProjectTemporalRangeLabel->setText( tr( "The project does not have a temporal range set. "
"Update the project temporal range via the Project Properties "
"with valid values in order to use it here." ) );
mProjectTemporalRangeLabel->setEnabled( false );
}
}

void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )
@@ -118,35 +134,24 @@ void QgsWmstSettingsWidget::syncToLayer( QgsMapLayer *layer )
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( qobject_cast< QgsRasterLayerTemporalProperties * >( mRasterLayer->temporalProperties() )->intervalHandlingMethod() ) );

const QString temporalSource = uri.value( QStringLiteral( "temporalSource" ) ).toString();
bool enableTime = uri.value( QStringLiteral( "enableTime" ), true ).toBool();

if ( temporalSource == QLatin1String( "provider" ) )
mStaticTemporalRange->setChecked( !time.isEmpty() );
else if ( temporalSource == QLatin1String( "project" ) )
mProjectTemporalRange->setChecked( !time.isEmpty() );

mDisableTime->setChecked( !enableTime );
mDisableTime->setChecked( !uri.value( QStringLiteral( "enableTime" ), true ).toBool() );

mWmstOptions->setEnabled( !mRasterLayer->temporalProperties()->isActive() );
const bool useTemporal = uri.value( QStringLiteral( "allowTemporalUpdates" ), false ).toBool();
if ( useTemporal && temporalSource == QLatin1String( "provider" ) && !time.isEmpty() )
mStaticTemporalRangeRadio->setChecked( true );
else if ( useTemporal && temporalSource == QLatin1String( "project" ) && !time.isEmpty() )
mProjectTemporalRangeRadio->setChecked( true );
else
mDefaultRadio->setChecked( true );

if ( mRasterLayer->temporalProperties()->isActive() )
mWmstOptionsLabel->setText( tr( "The static temporal options below are disabled because the layer "
"temporal properties are active, to enable them disable temporal properties "
"in the temporal tab. " ) );
QgsDateTimeRange range;
if ( QgsProject::instance()->timeSettings() )
range = QgsProject::instance()->timeSettings()->temporalRange();

if ( !range.begin().isValid() || !range.end().isValid() )
{
mProjectTemporalRange->setEnabled( false );
mProjectTemporalRangeLabel->setText( tr( "The option below is disabled because the project temporal range "
"is not valid, update the project temporal range in the project properties "
"with valid values in order to use it here." ) );
mStaticWmstStackedWidget->setCurrentIndex( 0 );
}
else
{
mStaticWmstStackedWidget->setCurrentIndex( 1 );
}

mWmstGroup->setChecked( uri.contains( QStringLiteral( "allowTemporalUpdates" ) ) &&
uri.value( QStringLiteral( "allowTemporalUpdates" ), true ).toBool() );
}
}

@@ -157,31 +162,39 @@ void QgsWmstSettingsWidget::apply()

QVariantMap uri = currentUri;

if ( mWmstGroup->isVisibleTo( this ) )
uri[ QStringLiteral( "allowTemporalUpdates" ) ] = mWmstGroup->isChecked();
if ( mStaticWmstStackedWidget->currentIndex() == 1 )
uri[ QStringLiteral( "allowTemporalUpdates" ) ] = !mDefaultRadio->isChecked();
else
uri[ QStringLiteral( "allowTemporalUpdates" ) ] = true; // using dynamic temporal mode

if ( mWmstGroup->isEnabled() &&
mRasterLayer->dataProvider() &&
if ( mRasterLayer->dataProvider() &&
mRasterLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
bool enableTime = !mDisableTime->isChecked();

uri[ QStringLiteral( "enableTime" ) ] = enableTime;
uri[ QStringLiteral( "enableTime" ) ] = !mDisableTime->isChecked();
qobject_cast< QgsRasterLayerTemporalProperties * >( mRasterLayer->temporalProperties() )->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >(
mFetchModeComboBox->currentData().toInt() ) );

if ( mReferenceTimeGroupBox->isChecked() )
{
QString referenceTime = mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri[ QStringLiteral( "referenceTime" ) ] = referenceTime;
}
else
{
uri.remove( QStringLiteral( "referenceTime" ) );
}

// Don't do static temporal updates if temporal properties are active
if ( !mRasterLayer->temporalProperties()->isActive() )
if ( !mRasterLayer->temporalProperties()->isActive() && !mDefaultRadio->isChecked() )
{
if ( mStaticTemporalRange->isChecked() )
if ( mStaticTemporalRangeRadio->isChecked() )
{
QString time = mStartStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs ) + '/' +
mEndStaticDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri[ QStringLiteral( "time" ) ] = time;
uri[ QStringLiteral( "temporalSource" ) ] = QLatin1String( "provider" );
}

if ( mProjectTemporalRange->isChecked() )
else if ( mProjectTemporalRangeRadio->isChecked() )
{
QgsDateTimeRange range;

@@ -197,53 +210,23 @@ void QgsWmstSettingsWidget::apply()
}
}
}

if ( mReferenceTimeGroupBox->isChecked() )
{
QString referenceTime = mReferenceDateTimeEdit->dateTime().toString( Qt::ISODateWithMs );
uri[ QStringLiteral( "referenceTime" ) ] = referenceTime;
}
else
{
if ( uri.contains( QStringLiteral( "referenceTime" ) ) )
uri.remove( QStringLiteral( "referenceTime" ) );
uri.remove( QStringLiteral( "temporalSource" ) );
uri.remove( QStringLiteral( "time" ) );
}
}

if ( currentUri != uri )
mRasterLayer->setDataSource( metadata->encodeUri( uri ), mRasterLayer->name(), mRasterLayer->providerType(), QgsDataProvider::ProviderOptions() );
}

void QgsWmstSettingsWidget::passProjectTemporalRange_toggled( bool checked )
{
if ( checked )
{
QgsDateTimeRange range;
if ( QgsProject::instance()->timeSettings() )
range = QgsProject::instance()->timeSettings()->temporalRange();

if ( range.begin().isValid() && range.end().isValid() )
mProjectTemporalRangeLabel->setText( tr( "Project temporal range is set from %1 to %2" ).arg(
range.begin().toString( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) ),
range.end().toString( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) )
) );
else
mProjectTemporalRangeLabel->setText( tr( "The option below is disabled because the project temporal range "
"is not valid, update the project temporal range in the project properties "
"with valid values in order to use it here." ) );
}
}

void QgsWmstSettingsWidget::temporalPropertiesChange()
{
if ( mRasterLayer->temporalProperties()->isActive() )
mWmstOptionsLabel->setText( tr( "The static temporal options below are disabled because the layer "
"temporal properties are active, to enable them disable temporal properties "
"in the temporal tab." ) );
mStaticWmstStackedWidget->setCurrentIndex( 0 );
else
mWmstOptionsLabel->clear();

mWmstOptions->setEnabled( !mRasterLayer->temporalProperties()->isActive() );
mStaticWmstStackedWidget->setCurrentIndex( 1 );
}


@@ -34,7 +34,6 @@ class QgsWmstSettingsWidget : public QgsMapLayerConfigWidget, private Ui::QgsWms
void syncToLayer( QgsMapLayer *layer ) override;
void apply() override;
private slots:
void passProjectTemporalRange_toggled( bool checked );
void temporalPropertiesChange();

private:

0 comments on commit 4be88aa

Please sign in to comment.