QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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  connect( mModeRedrawLayer, &QRadioButton::toggled, mLabelRedrawLayer, &QWidget::setEnabled );
43 
44  mStartTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );
45  mEndTemporalDateTimeEdit->setDisplayFormat( QStringLiteral( "yyyy-MM-dd HH:mm:ss" ) );
46 
47  if ( !mLayer->dataProvider() || !mLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
48  {
49  mModeAutomaticRadio->setEnabled( false );
50  mModeAutomaticRadio->setChecked( false );
51  mModeFixedRangeRadio->setChecked( true );
52  }
53 
54  syncToLayer();
55 }
56 
58 {
59  mLayer->temporalProperties()->setIsActive( mTemporalGroupBox->isChecked() );
60 
61  QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
62 
63  QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
64  mEndTemporalDateTimeEdit->dateTime() );
65 
66  if ( mModeAutomaticRadio->isChecked() )
67  temporalProperties->setMode( Qgis::RasterTemporalMode::TemporalRangeFromDataProvider );
68  else if ( mModeFixedRangeRadio->isChecked() )
69  temporalProperties->setMode( Qgis::RasterTemporalMode::FixedTemporalRange );
70  else if ( mModeRedrawLayer->isChecked() )
71  temporalProperties->setMode( Qgis::RasterTemporalMode::RedrawLayerOnly );
72  temporalProperties->setFixedTemporalRange( normalRange );
73 
74  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
75  {
76  widget->apply();
77  }
78 }
79 
81 {
82  const QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< const QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
83  switch ( temporalProperties->mode() )
84  {
85  case Qgis::RasterTemporalMode::TemporalRangeFromDataProvider:
86  mModeAutomaticRadio->setChecked( true );
87  break;
88  case Qgis::RasterTemporalMode::FixedTemporalRange:
89  mModeFixedRangeRadio->setChecked( true );
90  break;
91  case Qgis::RasterTemporalMode::RedrawLayerOnly:
92  mModeRedrawLayer->setChecked( true );
93  break;
94  }
95 
96  mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
97  mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );
98 
99  mTemporalGroupBox->setChecked( temporalProperties->isActive() );
100 
101  mLabelRedrawLayer->setEnabled( mModeRedrawLayer->isChecked() );
102 
103  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
104  {
105  widget->syncToLayer( mLayer );
106  }
107 }
108 
110 {
111  mExtraWidgets << widget;
112  mExtraWidgetLayout->insertWidget( mExtraWidgetLayout->count() - 1, widget );
113 }
114 
115 void QgsRasterLayerTemporalPropertiesWidget::temporalGroupBoxChecked( bool checked )
116 {
117  for ( QgsMapLayerConfigWidget *widget : std::as_const( mExtraWidgets ) )
118  {
119  widget->emit dynamicTemporalControlToggled( checked );
120  }
121 }
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.
Qgis::RasterTemporalMode mode() const
Returns the temporal properties mode.
void setMode(Qgis::RasterTemporalMode mode)
Sets 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.