QGIS API Documentation  3.17.0-Master (a035f434f4)
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 }
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
bool isActive() const
Returns true if the temporal property is active.
Represents a raster layer.
QgsRasterDataProviderTemporalCapabilities * temporalCapabilities() override
Returns the provider&#39;s temporal capabilities.
void setMode(TemporalMode mode)
Sets the temporal properties mode.
QgsRasterLayerTemporalPropertiesWidget(QWidget *parent=nullptr, QgsRasterLayer *layer=nullptr)
Constructor for QgsRasterLayerTemporalPropertiesWidget.
QgsRasterDataProvider * dataProvider() override
Returns the source data provider.
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
Mode when temporal properties have fixed start and end datetimes.
Mode when raster layer delegates temporal range handling to the dataprovider.
TemporalMode mode() const
Returns the temporal properties mode.
void saveTemporalProperties()
Save widget temporal properties inputs.
Implementation of map layer temporal properties for raster layers.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer&#39;s temporal properties.
void syncToLayer()
Updates the widget state to match the current layer state.
void setIsActive(bool active)
Sets whether the temporal property is active.
bool hasTemporalCapabilities() const
Returns true if the provider has temporal capabilities available.