QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 }
qgsrasterlayer.h
QgsRasterLayerTemporalProperties::setMode
void setMode(Qgis::RasterTemporalMode mode)
Sets the temporal properties mode.
Definition: qgsrasterlayertemporalproperties.cpp:94
qgsgui.h
qgsrasterlayertemporalpropertieswidget.h
qgsrasterdataprovidertemporalcapabilities.h
QgsRasterLayerTemporalProperties
Implementation of map layer temporal properties for raster layers.
Definition: qgsrasterlayertemporalproperties.h:35
QgsMapLayerConfigWidget
A panel widget that can be shown in the map style dock.
Definition: qgsmaplayerconfigwidget.h:115
QgsTemporalProperty::isActive
bool isActive() const
Returns true if the temporal property is active.
Definition: qgstemporalproperty.cpp:36
QgsRasterLayerTemporalProperties::setFixedTemporalRange
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
Definition: qgsrasterlayertemporalproperties.cpp:118
QgsRasterLayer::temporalProperties
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
Definition: qgsrasterlayer.cpp:1082
QgsRasterLayerTemporalPropertiesWidget::addWidget
void addWidget(QgsMapLayerConfigWidget *widget SIP_TRANSFER)
Adds a child widget to the properties widget.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:109
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:76
QgsTemporalProperty::setIsActive
void setIsActive(bool active)
Sets whether the temporal property is active.
Definition: qgstemporalproperty.cpp:27
qgsprojecttimesettings.h
QgsRasterLayerTemporalProperties::mode
Qgis::RasterTemporalMode mode() const
Returns the temporal properties mode.
Definition: qgsrasterlayertemporalproperties.cpp:89
qgsmaplayerconfigwidget.h
QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties
void saveTemporalProperties()
Save widget temporal properties inputs.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:57
QgsRasterLayerTemporalProperties::fixedTemporalRange
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
Definition: qgsrasterlayertemporalproperties.cpp:123
QgsRasterLayerTemporalPropertiesWidget::syncToLayer
void syncToLayer()
Updates the widget state to match the current layer state.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:80
qgsrasterlayertemporalproperties.h
QgsDataProviderTemporalCapabilities::hasTemporalCapabilities
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.
Definition: qgsdataprovidertemporalcapabilities.h:74
QgsRasterLayerTemporalPropertiesWidget::QgsRasterLayerTemporalPropertiesWidget
QgsRasterLayerTemporalPropertiesWidget(QWidget *parent=nullptr, QgsRasterLayer *layer=nullptr)
Constructor for QgsRasterLayerTemporalPropertiesWidget.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:27
QgsRasterDataProvider::temporalCapabilities
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsrasterdataprovider.cpp:412
qgsproject.h
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:257