QGIS API Documentation  3.20.0-Odense (decaadbb31)
qgsrasterlayertemporalpropertieswidget.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgsrasterlayertemporalpropertieswidget.cpp
3  ------------------------------
4  begin : January 2020
5  copyright : (C) 2020 by Samweli Mwakisambwe
6  email : samweli at kartoza dot com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  * *
11  * This program is free software; you can redistribute it and/or modify *
12  * it under the terms of the GNU General Public License as published by *
13  * the Free Software Foundation; either version 2 of the License, or *
14  * (at your option) any later version. *
15  * *
16  ***************************************************************************/
17 
19 #include "qgsgui.h"
20 #include "qgsproject.h"
21 #include "qgsprojecttimesettings.h"
23 #include "qgsrasterlayer.h"
26 
28  : QWidget( parent )
29  , mLayer( layer )
30 {
31  Q_ASSERT( mLayer );
32  setupUi( this );
33 
34  mExtraWidgetLayout = new QVBoxLayout();
35  mExtraWidgetLayout->setContentsMargins( 0, 0, 0, 0 );
36  mExtraWidgetLayout->addStretch();
37  mExtraWidgetContainer->setLayout( mExtraWidgetLayout );
38 
39  connect( mModeFixedRangeRadio, &QRadioButton::toggled, mFixedTimeRangeFrame, &QWidget::setEnabled );
40 
41  connect( mTemporalGroupBox, &QGroupBox::toggled, this, &QgsRasterLayerTemporalPropertiesWidget::temporalGroupBoxChecked );
42 
43  mStartTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );
44  mEndTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );
45 
46  if ( !mLayer->dataProvider() || !mLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
47  {
48  mModeAutomaticRadio->setEnabled( false );
49  mModeAutomaticRadio->setChecked( false );
50  mModeFixedRangeRadio->setChecked( true );
51  }
52 
53  syncToLayer();
54 }
55 
57 {
58  mLayer->temporalProperties()->setIsActive( mTemporalGroupBox->isChecked() );
59 
60  QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
61 
62  QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
63  mEndTemporalDateTimeEdit->dateTime() );
64 
65  if ( mModeAutomaticRadio->isChecked() )
67  else if ( mModeFixedRangeRadio->isChecked() )
69  temporalProperties->setFixedTemporalRange( normalRange );
70 
71  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
72  {
73  widget->apply();
74  }
75 }
76 
78 {
79  const QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< const QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
80  switch ( temporalProperties->mode() )
81  {
83  mModeAutomaticRadio->setChecked( true );
84  break;
86  mModeFixedRangeRadio->setChecked( true );
87  break;
88  }
89 
90  mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
91  mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );
92 
93  mTemporalGroupBox->setChecked( temporalProperties->isActive() );
94 
95  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
96  {
97  widget->syncToLayer( mLayer );
98  }
99 }
100 
102 {
103  mExtraWidgets << widget;
104  mExtraWidgetLayout->insertWidget( mExtraWidgetLayout->count() - 1, widget );
105 }
106 
107 void QgsRasterLayerTemporalPropertiesWidget::temporalGroupBoxChecked( bool checked )
108 {
109  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
110  {
111  widget->emit dynamicTemporalControlToggled( checked );
112  }
113 }
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
A panel widget that can be shown in the map style dock.
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
void syncToLayer()
Updates the widget state to match the current layer state.
void saveTemporalProperties()
Save widget temporal properties inputs.
QgsRasterLayerTemporalPropertiesWidget(QWidget *parent=nullptr, QgsRasterLayer *layer=nullptr)
Constructor for QgsRasterLayerTemporalPropertiesWidget.
void addWidget(QgsMapLayerConfigWidget *widget SIP_TRANSFER)
Adds a child widget to the properties widget.
Implementation of map layer temporal properties for raster layers.
void setMode(TemporalMode mode)
Sets the temporal properties mode.
@ ModeFixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
@ ModeTemporalRangeFromDataProvider
Mode when raster layer delegates temporal range handling to the dataprovider.
TemporalMode mode() const
Returns the temporal properties mode.
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
Represents a raster layer.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.