QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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"
25 
27  : QWidget( parent )
28  , mLayer( layer )
29 {
30  Q_ASSERT( mLayer );
31  setupUi( this );
32 
33  connect( mModeFixedRangeRadio, &QRadioButton::toggled, mFixedTimeRangeFrame, &QWidget::setEnabled );
34 
35  mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
36  mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
37 
38  if ( !mLayer->dataProvider() || !mLayer->dataProvider()->temporalCapabilities()->hasTemporalCapabilities() )
39  {
40  mModeAutomaticRadio->setEnabled( false );
41  mModeAutomaticRadio->setChecked( false );
42  mModeFixedRangeRadio->setChecked( true );
43  }
44 
45  syncToLayer();
46 }
47 
49 {
50  mLayer->temporalProperties()->setIsActive( mTemporalGroupBox->isChecked() );
51 
52  QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
53 
54  QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(),
55  mEndTemporalDateTimeEdit->dateTime() );
56 
57  if ( mModeAutomaticRadio->isChecked() )
59  else if ( mModeFixedRangeRadio->isChecked() )
61  temporalProperties->setFixedTemporalRange( normalRange );
62 }
63 
65 {
66  const QgsRasterLayerTemporalProperties *temporalProperties = qobject_cast< const QgsRasterLayerTemporalProperties * >( mLayer->temporalProperties() );
67  switch ( temporalProperties->mode() )
68  {
70  mModeAutomaticRadio->setChecked( true );
71  break;
73  mModeFixedRangeRadio->setChecked( true );
74  break;
75  }
76 
77  mStartTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().begin() );
78  mEndTemporalDateTimeEdit->setDateTime( temporalProperties->fixedTemporalRange().end() );
79 
80  mTemporalGroupBox->setChecked( temporalProperties->isActive() );
81 }
qgsrasterlayer.h
qgsgui.h
qgsrasterlayertemporalpropertieswidget.h
QgsRasterLayerTemporalProperties::ModeTemporalRangeFromDataProvider
@ ModeTemporalRangeFromDataProvider
Mode when raster layer delegates temporal range handling to the dataprovider.
Definition: qgsrasterlayertemporalproperties.h:57
qgsrasterdataprovidertemporalcapabilities.h
QgsRasterLayerTemporalProperties
Implementation of map layer temporal properties for raster layers.
Definition: qgsrasterlayertemporalproperties.h:36
QgsRasterLayerTemporalProperties::ModeFixedTemporalRange
@ ModeFixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
Definition: qgsrasterlayertemporalproperties.h:56
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:90
QgsRasterDataProvider::temporalCapabilities
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider's temporal capabilities.
Definition: qgsrasterdataprovider.cpp:427
QgsRasterLayer::temporalProperties
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
Definition: qgsrasterlayer.cpp:1006
QgsRasterLayer::dataProvider
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
Definition: qgsrasterlayer.cpp:234
QgsRasterLayerTemporalProperties::mode
TemporalMode mode() const
Returns the temporal properties mode.
Definition: qgsrasterlayertemporalproperties.cpp:61
QgsRasterLayer
Represents a raster layer.
Definition: qgsrasterlayer.h:71
QgsTemporalProperty::setIsActive
void setIsActive(bool active)
Sets whether the temporal property is active.
Definition: qgstemporalproperty.cpp:27
qgsprojecttimesettings.h
QgsRasterLayerTemporalProperties::setMode
void setMode(TemporalMode mode)
Sets the temporal properties mode.
Definition: qgsrasterlayertemporalproperties.cpp:66
QgsRasterLayerTemporalPropertiesWidget::saveTemporalProperties
void saveTemporalProperties()
Save widget temporal properties inputs.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:48
QgsRasterLayerTemporalProperties::fixedTemporalRange
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
Definition: qgsrasterlayertemporalproperties.cpp:95
QgsRasterLayerTemporalPropertiesWidget::syncToLayer
void syncToLayer()
Updates the widget state to match the current layer state.
Definition: qgsrasterlayertemporalpropertieswidget.cpp:64
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:26
qgsproject.h