Skip to content
Permalink
Browse files

Raster layer temporal widget fixups

- Add checkbox to disable temporal handling for layer
- Don't apply changes to layer outside of saveTemporalProperties(), otherwise
changes cannot be correctly canceled
- Minor code cleanups
  • Loading branch information
nyalldawson committed Mar 13, 2020
1 parent 79fb8fb commit f37da160eca45701eeb3ec7832be66d4f37c0596
@@ -35,6 +35,15 @@ QgsRasterLayerTemporalPropertiesWidget::QgsRasterLayerTemporalPropertiesWidget(
connect( mProjectRadioButton, &QRadioButton::toggled, this, &QgsRasterLayerTemporalPropertiesWidget::projectRadioButton_toggled );
connect( mReferenceCheckBox, &QCheckBox::clicked, this, &QgsRasterLayerTemporalPropertiesWidget::referenceCheckBox_clicked );

mFetchModeComboBox->addItem( tr( "Use Whole Temporal Range" ), QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange );
mFetchModeComboBox->addItem( tr( "Match to Start of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange );
mFetchModeComboBox->addItem( tr( "Match to End of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );

mSetEndAsStartNormalButton->setToolTip( tr( "Set the end datetime same as the start datetime" ) );
mSetEndAsStartReferenceButton->setToolTip( tr( "Set the end datetime same as the start datetime" ) );
mResetDatesButton->setToolTip( tr( "Reset the start and end datetime inputs" ) );
mDisableTime->setToolTip( "Use only the date in the datetime inputs to update the temporal range" );

init();
}

@@ -44,24 +53,14 @@ void QgsRasterLayerTemporalPropertiesWidget::init()
setDateTimeInputsLimit();
setDateTimeInputsLocale();

mFetchModeComboBox->addItem( tr( "Use Whole Temporal Range" ), QgsRasterDataProviderTemporalCapabilities::MatchUsingWholeRange );
mFetchModeComboBox->addItem( tr( "Match to Start of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange );
mFetchModeComboBox->addItem( tr( "Match to End of Range" ), QgsRasterDataProviderTemporalCapabilities::MatchExactUsingEndOfRange );

if ( QgsRasterLayerTemporalProperties *temporalProperties = mLayer->temporalProperties() )
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( temporalProperties->intervalHandlingMethod() ) );
else
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( QgsRasterDataProviderTemporalCapabilities::MatchExactUsingStartOfRange ) );
mTemporalGroupBox->setChecked( mLayer->temporalProperties()->isActive() );
mFetchModeComboBox->setCurrentIndex( mFetchModeComboBox->findData( mLayer->temporalProperties()->intervalHandlingMethod() ) );

if ( mLayer->temporalProperties()->temporalSource() == QgsMapLayerTemporalProperties::TemporalSource::Project )
mProjectRadioButton->setChecked( true );

updateRangeLabel( mLabel );

mSetEndAsStartNormalButton->setToolTip( tr( "Set the end datetime same as the start datetime" ) );
mSetEndAsStartReferenceButton->setToolTip( tr( "Set the end datetime same as the start datetime" ) );
mResetDatesButton->setToolTip( tr( "Reset the start and end datetime inputs" ) );
mDisableTime->setToolTip( "Use only the date in the datetime inputs to update the temporal range" );
}

void QgsRasterLayerTemporalPropertiesWidget::setInputWidgetState( TemporalDimension dimension, bool enabled )
@@ -96,49 +95,45 @@ void QgsRasterLayerTemporalPropertiesWidget::setDateTimeInputsLocale()

void QgsRasterLayerTemporalPropertiesWidget::setDateTimeInputsLimit()
{
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( mLayer );
if ( layer && layer->temporalProperties() )
{
QgsDateTimeRange fixedRange = layer->temporalProperties()->fixedTemporalRange();
QgsDateTimeRange fixedReferenceRange = layer->temporalProperties()->fixedReferenceTemporalRange();
QgsDateTimeRange fixedRange = mLayer->temporalProperties()->fixedTemporalRange();
QgsDateTimeRange fixedReferenceRange = mLayer->temporalProperties()->fixedReferenceTemporalRange();

QgsDateTimeRange range = layer->temporalProperties()->temporalRange();
QgsDateTimeRange referenceRange = layer->temporalProperties()->referenceTemporalRange();
QgsDateTimeRange range = mLayer->temporalProperties()->temporalRange();
QgsDateTimeRange referenceRange = mLayer->temporalProperties()->referenceTemporalRange();

// Set initial date time input values to the layers temporal range only if the
// ranges are valid
// Set initial date time input values to the layers temporal range only if the
// ranges are valid

mStartTemporalDateTimeEdit->setDateTimeRange( fixedRange.begin(), fixedRange.end() );
mEndTemporalDateTimeEdit->setDateTimeRange( fixedRange.begin(), fixedRange.end() );
mStartReferenceDateTimeEdit->setDateTimeRange( fixedReferenceRange.begin(), fixedReferenceRange.end() );
mEndReferenceDateTimeEdit->setDateTimeRange( fixedReferenceRange.begin(), fixedReferenceRange.end() );
mStartTemporalDateTimeEdit->setDateTimeRange( fixedRange.begin(), fixedRange.end() );
mEndTemporalDateTimeEdit->setDateTimeRange( fixedRange.begin(), fixedRange.end() );
mStartReferenceDateTimeEdit->setDateTimeRange( fixedReferenceRange.begin(), fixedReferenceRange.end() );
mEndReferenceDateTimeEdit->setDateTimeRange( fixedReferenceRange.begin(), fixedReferenceRange.end() );

if ( range.begin().isValid() && range.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( range.begin() );
mEndTemporalDateTimeEdit->setDateTime( range.end() );
}
else
if ( range.begin().isValid() && range.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( range.begin() );
mEndTemporalDateTimeEdit->setDateTime( range.end() );
}
else
{
if ( fixedRange.begin().isValid() && fixedRange.end().isValid() )
{
if ( fixedRange.begin().isValid() && fixedRange.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( fixedRange.begin() );
mEndTemporalDateTimeEdit->setDateTime( fixedRange.end() );
}
mStartTemporalDateTimeEdit->setDateTime( fixedRange.begin() );
mEndTemporalDateTimeEdit->setDateTime( fixedRange.end() );
}
}

if ( referenceRange.begin().isValid() && referenceRange.end().isValid() )
{
mStartReferenceDateTimeEdit->setDateTime( referenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( referenceRange.end() );
}
else
if ( referenceRange.begin().isValid() && referenceRange.end().isValid() )
{
mStartReferenceDateTimeEdit->setDateTime( referenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( referenceRange.end() );
}
else
{
if ( fixedReferenceRange.begin().isValid() && fixedReferenceRange.end().isValid() )
{
if ( fixedReferenceRange.begin().isValid() && fixedReferenceRange.end().isValid() )
{
mStartReferenceDateTimeEdit->setDateTime( fixedReferenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( fixedReferenceRange.end() );
}
mStartReferenceDateTimeEdit->setDateTime( fixedReferenceRange.begin() );
mEndReferenceDateTimeEdit->setDateTime( fixedReferenceRange.end() );
}
}
}
@@ -191,8 +186,6 @@ void QgsRasterLayerTemporalPropertiesWidget::layerRadioButton_toggled( bool chec
{
if ( checked )
{
mLayer->temporalProperties()->setTemporalSource(
QgsMapLayerTemporalProperties::TemporalSource::Layer );
updateRangeLabel( mLabel );
}
}
@@ -201,19 +194,15 @@ void QgsRasterLayerTemporalPropertiesWidget::projectRadioButton_toggled( bool ch
{
if ( checked )
{
mLayer->temporalProperties()->setTemporalSource(
QgsMapLayerTemporalProperties::TemporalSource::Project );
updateRangeLabel( mLabel );
}
}

void QgsRasterLayerTemporalPropertiesWidget::resetDatesButton_clicked()
{
QgsRasterLayer *layer = qobject_cast<QgsRasterLayer *>( mLayer );
QgsDateTimeRange layerFixedRange;

if ( layer && layer->temporalProperties() )
layerFixedRange = layer->temporalProperties()->fixedTemporalRange();
layerFixedRange = mLayer->temporalProperties()->fixedTemporalRange();
if ( layerFixedRange.begin().isValid() && layerFixedRange.end().isValid() )
{
mStartTemporalDateTimeEdit->setDateTime( layerFixedRange.begin() );
@@ -234,58 +223,35 @@ void QgsRasterLayerTemporalPropertiesWidget::referenceCheckBox_clicked()

void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
{
mLayer->temporalProperties()->setIsActive( mTemporalGroupBox->isChecked() );

if ( mLayerRadioButton->isChecked() )
{
if ( mLayer->type() == QgsMapLayerType::RasterLayer )
{
QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
mEndTemporalDateTimeEdit->dateTime() );
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *>( mLayer );

if ( rasterLayer && rasterLayer->temporalProperties() )
{
rasterLayer->temporalProperties()->setTemporalRange( normalRange );
rasterLayer->temporalProperties()->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Layer );

rasterLayer->temporalProperties()->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >( mFetchModeComboBox->currentData().toInt() ) );

if ( mReferenceCheckBox->isChecked() )
{
QgsDateTimeRange referenceRange = QgsDateTimeRange( mStartReferenceDateTimeEdit->dateTime(),
mEndReferenceDateTimeEdit->dateTime() );
rasterLayer->temporalProperties()->setReferenceTemporalRange( referenceRange );
}
}
}
QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
mEndTemporalDateTimeEdit->dateTime() );
mLayer->temporalProperties()->setTemporalRange( normalRange );
mLayer->temporalProperties()->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Layer );
}

if ( mProjectRadioButton->isChecked() )
else if ( mProjectRadioButton->isChecked() )
{
if ( mLayer->type() == QgsMapLayerType::RasterLayer )
{
QgsRasterLayer *rasterLayer = qobject_cast<QgsRasterLayer *> ( mLayer );
QgsDateTimeRange projectRange;
QgsDateTimeRange projectRange;

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

if ( rasterLayer && rasterLayer->temporalProperties() )
{
if ( !projectRange.begin().isValid() || !projectRange.end().isValid() )
return;
if ( !projectRange.begin().isValid() || !projectRange.end().isValid() )
return;

rasterLayer->temporalProperties()->setTemporalRange( projectRange );
rasterLayer->temporalProperties()->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Project );
mLayer->temporalProperties()->setTemporalRange( projectRange );
mLayer->temporalProperties()->setTemporalSource( QgsMapLayerTemporalProperties::TemporalSource::Project );
}

rasterLayer->temporalProperties()->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >( mFetchModeComboBox->currentData().toInt() ) );
mLayer->temporalProperties()->setIntervalHandlingMethod( static_cast< QgsRasterDataProviderTemporalCapabilities::IntervalHandlingMethod >( mFetchModeComboBox->currentData().toInt() ) );

if ( mReferenceCheckBox->isChecked() )
{
QgsDateTimeRange referenceRange = QgsDateTimeRange( mStartReferenceDateTimeEdit->dateTime(),
mEndReferenceDateTimeEdit->dateTime() );
rasterLayer->temporalProperties()->setReferenceTemporalRange( referenceRange );
}
}
}
if ( mReferenceCheckBox->isChecked() )
{
QgsDateTimeRange referenceRange = QgsDateTimeRange( mStartReferenceDateTimeEdit->dateTime(),
mEndReferenceDateTimeEdit->dateTime() );
mLayer->temporalProperties()->setReferenceTemporalRange( referenceRange );
}
}
@@ -48,8 +48,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>743</width>
<height>658</height>
<width>729</width>
<height>660</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout">
@@ -74,6 +74,9 @@ background: white;QgsCollapsibleGroupBoxBasic::title, QgsCollapsibleGroupBox::ti
<property name="title">
<string>Temporal</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<property name="collapsed" stdset="0">
<bool>false</bool>
</property>

0 comments on commit f37da16

Please sign in to comment.
You can’t perform that action at this time.