QGIS API Documentation 3.99.0-Master (26c88405ac0)
Loading...
Searching...
No Matches
qgsvectorlayertemporalpropertieswidget.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsvectorlayertemporalpropertieswidget.cpp
3 ------------------------------
4 begin : May 2020
5 copyright : (C) 2020 by Nyall Dawson
6 email : nyall dot dawson at gmail 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
21#include "qgsgui.h"
22#include "qgsstringutils.h"
23#include "qgsunittypes.h"
24#include "qgsvectorlayer.h"
26
27#include "moc_qgsvectorlayertemporalpropertieswidget.cpp"
28
30 : QWidget( parent )
31 , mLayer( layer )
32{
33 Q_ASSERT( mLayer );
34 setupUi( this );
35
36 mModeComboBox->addItem( tr( "Fixed Time Range" ), static_cast<int>( Qgis::VectorTemporalMode::FixedTemporalRange ) );
37 mModeComboBox->addItem( tr( "Single Field with Date/Time" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeInstantFromField ) );
38 mModeComboBox->addItem( tr( "Separate Fields for Start and End Date/Time" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromFields ) );
39 mModeComboBox->addItem( tr( "Separate Fields for Start and Event Duration" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndDurationFromFields ) );
40 mModeComboBox->addItem( tr( "Start and End Date/Time from Expressions" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromExpressions ) );
41 mModeComboBox->addItem( tr( "Redraw Layer Only" ), static_cast<int>( Qgis::VectorTemporalMode::RedrawLayerOnly ) );
42
43 connect( mModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), mStackedWidget, &QStackedWidget::setCurrentIndex );
44 connect( mModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [this] {
45 switch ( static_cast<Qgis::VectorTemporalMode>( mModeComboBox->currentData().toInt() ) )
46 {
52 mLimitsComboBox->show();
53 mLimitsLabel->show();
54 break;
56 mLimitsComboBox->hide();
57 mLimitsLabel->hide();
58 break;
59 }
60 } );
61
62 mLimitsComboBox->addItem( tr( "Include Start, Exclude End (default)" ), static_cast<int>( Qgis::VectorTemporalLimitMode::IncludeBeginExcludeEnd ) );
63 mLimitsComboBox->addItem( tr( "Include Start, Include End" ), static_cast<int>( Qgis::VectorTemporalLimitMode::IncludeBeginIncludeEnd ) );
64
65 mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
66 mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
67
68 mSingleFieldComboBox->setLayer( layer );
69 mStartFieldComboBox->setLayer( layer );
70 mEndFieldComboBox->setLayer( layer );
71 mDurationStartFieldComboBox->setLayer( layer );
72 mDurationFieldComboBox->setLayer( layer );
73 mSingleFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
74 mStartFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
75 mStartFieldComboBox->setAllowEmptyFieldName( true );
76 mEndFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
77 mEndFieldComboBox->setAllowEmptyFieldName( true );
78 mDurationStartFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
79 mDurationFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
80
81 mFixedDurationSpinBox->setMinimum( 0 );
82 mFixedDurationSpinBox->setClearValue( 0 );
83
84 for ( const Qgis::TemporalUnit u :
85 {
96 } )
97 {
100 mDurationUnitsComboBox->addItem( title, static_cast<int>( u ) );
101 mFixedDurationUnitsComboBox->addItem( title, static_cast<int>( u ) );
102 }
103
104 mFixedDurationUnitsComboBox->setEnabled( !mAccumulateCheckBox->isChecked() );
105 mFixedDurationSpinBox->setEnabled( !mAccumulateCheckBox->isChecked() );
106 connect( mAccumulateCheckBox, &QCheckBox::toggled, this, [this]( bool checked ) {
107 mFixedDurationUnitsComboBox->setEnabled( !checked );
108 mFixedDurationSpinBox->setEnabled( !checked );
109 } );
110
111 mStartExpressionWidget->setAllowEmptyFieldName( true );
112 mEndExpressionWidget->setAllowEmptyFieldName( true );
113 mStartExpressionWidget->setLayer( layer );
114 mEndExpressionWidget->setLayer( layer );
115 mStartExpressionWidget->registerExpressionContextGenerator( this );
116 mEndExpressionWidget->registerExpressionContextGenerator( this );
117
118 syncToLayer();
119}
120
122{
123 QgsVectorLayerTemporalProperties *properties = qobject_cast<QgsVectorLayerTemporalProperties *>( mLayer->temporalProperties() );
124
125 properties->setIsActive( mTemporalGroupBox->isChecked() );
126 properties->setMode( static_cast<Qgis::VectorTemporalMode>( mModeComboBox->currentData().toInt() ) );
127 Qgis::VectorTemporalLimitMode limitMode = static_cast<Qgis::VectorTemporalLimitMode>( mLimitsComboBox->currentData().toInt() );
128 properties->setLimitMode( limitMode );
129
130 const QgsDateTimeRange normalRange = QgsDateTimeRange(
131 mStartTemporalDateTimeEdit->dateTime(), mEndTemporalDateTimeEdit->dateTime(),
133 );
134
135 properties->setFixedTemporalRange( normalRange );
136
137 switch ( properties->mode() )
138 {
143 properties->setStartField( mSingleFieldComboBox->currentField() );
144 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mFixedDurationUnitsComboBox->currentData().toInt() ) );
145 break;
146
148 properties->setStartField( mStartFieldComboBox->currentField() );
149 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mFixedDurationUnitsComboBox->currentData().toInt() ) );
150 break;
151
153 properties->setStartField( mDurationStartFieldComboBox->currentField() );
154 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mDurationUnitsComboBox->currentData().toInt() ) );
155 break;
156 }
157
158 properties->setEndField( mEndFieldComboBox->currentField() );
159 properties->setDurationField( mDurationFieldComboBox->currentField() );
160 properties->setFixedDuration( mFixedDurationSpinBox->value() );
161 properties->setAccumulateFeatures( mAccumulateCheckBox->isChecked() );
162 properties->setStartExpression( mStartExpressionWidget->currentField() );
163 properties->setEndExpression( mEndExpressionWidget->currentField() );
164}
165
172
174{
175 const QgsVectorLayerTemporalProperties *properties = qobject_cast<QgsVectorLayerTemporalProperties *>( mLayer->temporalProperties() );
176 mTemporalGroupBox->setChecked( properties->isActive() );
177
178 mModeComboBox->setCurrentIndex( mModeComboBox->findData( static_cast<int>( properties->mode() ) ) );
179 mStackedWidget->setCurrentIndex( static_cast<int>( properties->mode() ) );
180
181 mLimitsComboBox->setCurrentIndex( mLimitsComboBox->findData( static_cast<int>( properties->limitMode() ) ) );
182
183 mStartTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().begin() );
184 mEndTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().end() );
185
186 mFixedDurationSpinBox->setValue( properties->fixedDuration() );
187
188 mSingleFieldComboBox->setField( properties->startField() );
189 mStartFieldComboBox->setField( properties->startField() );
190 mDurationStartFieldComboBox->setField( properties->startField() );
191 mEndFieldComboBox->setField( properties->endField() );
192 mDurationFieldComboBox->setField( properties->durationField() );
193 mDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( static_cast<int>( properties->durationUnits() ) ) );
194 mFixedDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( static_cast<int>( properties->durationUnits() ) ) );
195
196 mAccumulateCheckBox->setChecked( properties->accumulateFeatures() );
197
198 mStartExpressionWidget->setField( properties->startExpression() );
199 mEndExpressionWidget->setField( properties->endExpression() );
200}
VectorTemporalMode
Vector layer temporal feature modes.
Definition qgis.h:2580
@ FeatureDateTimeStartAndDurationFromFields
Mode when features have a field for start time and a field for event duration.
Definition qgis.h:2584
@ RedrawLayerOnly
Redraw the layer when temporal range changes, but don't apply any filtering. Useful when symbology or...
Definition qgis.h:2586
@ FeatureDateTimeStartAndEndFromExpressions
Mode when features use expressions for start and end times.
Definition qgis.h:2585
@ FeatureDateTimeInstantFromField
Mode when features have a datetime instant taken from a single field.
Definition qgis.h:2582
@ FixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
Definition qgis.h:2581
@ FeatureDateTimeStartAndEndFromFields
Mode when features have separate fields for start and end times.
Definition qgis.h:2583
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
Definition qgis.h:3395
TemporalUnit
Temporal units.
Definition qgis.h:5159
@ Milliseconds
Milliseconds.
Definition qgis.h:5160
@ Hours
Hours.
Definition qgis.h:5163
@ Centuries
Centuries.
Definition qgis.h:5169
@ Seconds
Seconds.
Definition qgis.h:5161
@ Weeks
Weeks.
Definition qgis.h:5165
@ Years
Years.
Definition qgis.h:5167
@ Decades
Decades.
Definition qgis.h:5168
@ Months
Months.
Definition qgis.h:5166
@ Minutes
Minutes.
Definition qgis.h:5162
VectorTemporalLimitMode
Mode for the handling of the limits of the filtering timeframe for vector features.
Definition qgis.h:2596
@ IncludeBeginExcludeEnd
Default mode: include the Begin limit, but exclude the End limit.
Definition qgis.h:2597
@ IncludeBeginIncludeEnd
Mode to include both limits of the filtering timeframe.
Definition qgis.h:2598
static QList< QgsExpressionContextScope * > globalProjectLayerScopes(const QgsMapLayer *layer)
Creates a list of three scopes: global, layer's project and layer.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
void appendScopes(const QList< QgsExpressionContextScope * > &scopes)
Appends a list of scopes to the end of the context.
@ DateTime
Datetime fields.
@ Date
Date or datetime fields.
@ Numeric
All numeric fields.
@ HigDialogTitleIsTitleCase
Dialog titles should be title case.
Definition qgsgui.h:281
static QgsGui::HigFlags higFlags()
Returns the platform's HIG flags.
Definition qgsgui.cpp:250
static QString capitalize(const QString &string, Qgis::Capitalization capitalization)
Converts a string by applying capitalization rules to the string.
bool isActive() const
Returns true if the temporal property is active.
void setIsActive(bool active)
Sets whether the temporal property is active.
T begin() const
Returns the beginning of the range.
Definition qgsrange.h:446
T end() const
Returns the upper bound of the range.
Definition qgsrange.h:453
static Q_INVOKABLE QString toString(Qgis::DistanceUnit unit)
Returns a translated string representing a distance unit.
void syncToLayer()
Updates the widget state to match the current layer state.
QgsVectorLayerTemporalPropertiesWidget(QWidget *parent=nullptr, QgsVectorLayer *layer=nullptr)
Constructor for QgsVectorLayerTemporalPropertiesWidget.
QgsExpressionContext createExpressionContext() const override
This method needs to be reimplemented in all classes which implement this interface and return an exp...
void saveTemporalProperties()
Save widget temporal properties inputs.
Implementation of map layer temporal properties for vector layers.
QString endExpression() const
Returns the expression for the end time for the feature's time spans.
void setDurationField(const QString &field)
Sets the name of the duration field, which contains the duration of the event.
void setMode(Qgis::VectorTemporalMode mode)
Sets the temporal properties mode.
void setStartExpression(const QString &expression)
Sets the expression to use for the start time for the feature's time spans.
Qgis::VectorTemporalLimitMode limitMode() const
Returns the temporal limit mode (to include or exclude begin/end limits).
void setLimitMode(Qgis::VectorTemporalLimitMode mode)
Sets the temporal limit mode (to include or exclude begin/end limits).
const QgsDateTimeRange & fixedTemporalRange() const
Returns the fixed temporal range for the layer.
double fixedDuration() const
Returns the fixed duration length, which contains the duration of the event.
bool accumulateFeatures() const
Returns true if features will be accumulated over time (i.e.
void setFixedTemporalRange(const QgsDateTimeRange &range)
Sets a temporal range to apply to the whole layer.
void setEndExpression(const QString &endExpression)
Sets the expression to use for the end time for the feature's time spans.
QString durationField() const
Returns the name of the duration field, which contains the duration of the event.
void setDurationUnits(Qgis::TemporalUnit units)
Sets the units of the event's duration.
QString endField() const
Returns the name of the end datetime field, which contains the end time for the feature's time spans.
Qgis::TemporalUnit durationUnits() const
Returns the units of the event's duration.
void setAccumulateFeatures(bool accumulate)
Sets whether features will be accumulated over time (i.e.
void setFixedDuration(double duration)
Sets the fixed event duration, which contains the duration of the event.
void setEndField(const QString &field)
Sets the name of the end datetime field, which contains the end time for the feature's time spans.
Qgis::VectorTemporalMode mode() const
Returns the temporal properties mode.
QString startField() const
Returns the name of the start datetime field, which contains the start time for the feature's time sp...
void setStartField(const QString &field)
Sets the name of the start datetime field, which contains the start time for the feature's time spans...
QString startExpression() const
Returns the expression for the start time for the feature's time spans.
Represents a vector layer which manages a vector based dataset.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:761