Skip to content
Permalink
Browse files

Correctly update temporal properties widgets after loading styles

  • Loading branch information
nyalldawson committed May 19, 2020
1 parent 79f8fd9 commit 4744696d5ab8b4eb0ee7305a2002a9a564a2c1d4
@@ -36,6 +36,11 @@ Save widget temporal properties inputs.
virtual QgsExpressionContext createExpressionContext() const;


void syncToLayer();
%Docstring
Updates the widget state to match the current layer state.
%End

};
/************************************************************************
* This file has been generated automatically from *
@@ -32,6 +32,11 @@ Constructor for QgsRasterLayerTemporalPropertiesWidget.
void saveTemporalProperties();
%Docstring
Save widget temporal properties inputs.
%End

void syncToLayer();
%Docstring
Updates the widget state to match the current layer state.
%End

};
@@ -39,21 +39,11 @@ QgsVectorLayerTemporalPropertiesWidget::QgsVectorLayerTemporalPropertiesWidget(
mModeComboBox->addItem( tr( "Start and End Date/Time from Expressions" ), QgsVectorLayerTemporalProperties::ModeFeatureDateTimeStartAndEndFromExpressions );
mModeComboBox->addItem( tr( "Redraw Layer Only" ), QgsVectorLayerTemporalProperties::ModeRedrawLayerOnly );

const QgsVectorLayerTemporalProperties *properties = qobject_cast< QgsVectorLayerTemporalProperties * >( layer->temporalProperties() );
mTemporalGroupBox->setChecked( properties->isActive() );

mModeComboBox->setCurrentIndex( mModeComboBox->findData( properties->mode() ) );

connect( mModeComboBox, qgis::overload<int>::of( &QComboBox::currentIndexChanged ), mStackedWidget, &QStackedWidget::setCurrentIndex );

mStackedWidget->setCurrentIndex( static_cast< int >( properties->mode() ) );

mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );

mStartTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().begin() );
mEndTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().end() );

mSingleFieldComboBox->setLayer( layer );
mStartFieldComboBox->setLayer( layer );
mEndFieldComboBox->setLayer( layer );
@@ -69,7 +59,6 @@ QgsVectorLayerTemporalPropertiesWidget::QgsVectorLayerTemporalPropertiesWidget(

mFixedDurationSpinBox->setMinimum( 0 );
mFixedDurationSpinBox->setClearValue( 0 );
mFixedDurationSpinBox->setValue( properties->fixedDuration() );

for ( QgsUnitTypes::TemporalUnit u :
{
@@ -91,21 +80,6 @@ QgsVectorLayerTemporalPropertiesWidget::QgsVectorLayerTemporalPropertiesWidget(
mFixedDurationUnitsComboBox->addItem( title, u );
}

if ( !properties->startField().isEmpty() )
{
mSingleFieldComboBox->setField( properties->startField() );
mStartFieldComboBox->setField( properties->startField() );
mDurationStartFieldComboBox->setField( properties->startField() );
}
if ( !properties->endField().isEmpty() )
{
mEndFieldComboBox->setField( properties->endField() );
}
mDurationFieldComboBox->setField( properties->durationField() );
mDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( properties->durationUnits() ) );
mFixedDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( properties->durationUnits() ) );

mAccumulateCheckBox->setChecked( properties->accumulateFeatures() );
mFixedDurationUnitsComboBox->setEnabled( !mAccumulateCheckBox->isChecked() );
mFixedDurationSpinBox->setEnabled( !mAccumulateCheckBox->isChecked() );
connect( mAccumulateCheckBox, &QCheckBox::toggled, this, [ = ]( bool checked )
@@ -121,8 +95,7 @@ QgsVectorLayerTemporalPropertiesWidget::QgsVectorLayerTemporalPropertiesWidget(
mStartExpressionWidget->registerExpressionContextGenerator( this );
mEndExpressionWidget->registerExpressionContextGenerator( this );

mStartExpressionWidget->setField( properties->startExpression() );
mEndExpressionWidget->setField( properties->endExpression() );
syncToLayer();
}

void QgsVectorLayerTemporalPropertiesWidget::saveTemporalProperties()
@@ -172,3 +145,36 @@ QgsExpressionContext QgsVectorLayerTemporalPropertiesWidget::createExpressionCon
context.appendScopes( QgsExpressionContextUtils::globalProjectLayerScopes( mLayer ) );
return context;
}

void QgsVectorLayerTemporalPropertiesWidget::syncToLayer()
{
const QgsVectorLayerTemporalProperties *properties = qobject_cast< QgsVectorLayerTemporalProperties * >( mLayer->temporalProperties() );
mTemporalGroupBox->setChecked( properties->isActive() );

mModeComboBox->setCurrentIndex( mModeComboBox->findData( properties->mode() ) );
mStackedWidget->setCurrentIndex( static_cast< int >( properties->mode() ) );

mStartTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().begin() );
mEndTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().end() );

mFixedDurationSpinBox->setValue( properties->fixedDuration() );

if ( !properties->startField().isEmpty() )
{
mSingleFieldComboBox->setField( properties->startField() );
mStartFieldComboBox->setField( properties->startField() );
mDurationStartFieldComboBox->setField( properties->startField() );
}
if ( !properties->endField().isEmpty() )
{
mEndFieldComboBox->setField( properties->endField() );
}
mDurationFieldComboBox->setField( properties->durationField() );
mDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( properties->durationUnits() ) );
mFixedDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( properties->durationUnits() ) );

mAccumulateCheckBox->setChecked( properties->accumulateFeatures() );

mStartExpressionWidget->setField( properties->startExpression() );
mEndExpressionWidget->setField( properties->endExpression() );
}
@@ -48,6 +48,11 @@ class GUI_EXPORT QgsVectorLayerTemporalPropertiesWidget : public QWidget, public

QgsExpressionContext createExpressionContext() const override;

/**
* Updates the widget state to match the current layer state.
*/
void syncToLayer();

private:

/**
@@ -938,18 +938,11 @@ void QgsRasterLayerProperties::sync()
QVariant wmsBackgroundLayer = mRasterLayer->customProperty( QStringLiteral( "WMSBackgroundLayer" ), false );
mBackgroundLayerCheckBox->setChecked( wmsBackgroundLayer.toBool() );

/*
* Legend Tab
*/
mLegendConfigEmbeddedWidget->setLayer( mRasterLayer );

} // QgsRasterLayerProperties::sync()
mTemporalWidget->syncToLayer();
}

/*
*
* PUBLIC AND PRIVATE SLOTS
*
*/
void QgsRasterLayerProperties::apply()
{

@@ -31,37 +31,18 @@ QgsRasterLayerTemporalPropertiesWidget::QgsRasterLayerTemporalPropertiesWidget(
setupUi( this );

connect( mModeFixedRangeRadio, &QRadioButton::toggled, mFixedTimeRangeFrame, &QWidget::setEnabled );
init();
}

void QgsRasterLayerTemporalPropertiesWidget::init()
{
mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );

mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );

const QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< const QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
switch ( temporalProperties->mode() )
{
case QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider:
mModeAutomaticRadio->setChecked( true );
break;
case QgsRasterLayerTemporalProperties::ModeFixedTemporalRange:
mModeFixedRangeRadio->setChecked( true );
break;
}

mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );

if ( !mLayer->dataProvider() || !mLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
{
mModeAutomaticRadio->setEnabled( false );
mModeAutomaticRadio->setChecked( false );
mModeFixedRangeRadio->setChecked( true );
}

mTemporalGroupBox->setChecked( temporalProperties->isActive() );
syncToLayer();
}

void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
@@ -79,3 +60,22 @@ void QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties()
temporalProperties->setMode( QgsRasterLayerTemporalProperties::ModeFixedTemporalRange );
temporalProperties->setFixedTemporalRange( normalRange );
}

void QgsRasterLayerTemporalPropertiesWidget::syncToLayer()
{
const QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< const QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
switch ( temporalProperties->mode() )
{
case QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider:
mModeAutomaticRadio->setChecked( true );
break;
case QgsRasterLayerTemporalProperties::ModeFixedTemporalRange:
mModeFixedRangeRadio->setChecked( true );
break;
}

mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );

mTemporalGroupBox->setChecked( temporalProperties->isActive() );
}
@@ -46,12 +46,12 @@ class GUI_EXPORT QgsRasterLayerTemporalPropertiesWidget : public QWidget, privat
*/
void saveTemporalProperties();

private:

/**
* Initialize the widget with default state.
* Updates the widget state to match the current layer state.
*/
void init();
void syncToLayer();

private:

/**
* The corresponding map layer with temporal attributes
@@ -597,6 +597,8 @@ void QgsVectorLayerProperties::syncToLayer()

mMetadataWidget->setMetadata( &mLayer->metadata() );

mTemporalWidget->syncToLayer();

} // syncToLayer()

void QgsVectorLayerProperties::apply()

0 comments on commit 4744696

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