QGIS API Documentation 3.41.0-Master (57ec4277f5e)
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#include "moc_qgsvectorlayertemporalpropertieswidget.cpp"
20#include "qgsgui.h"
21#include "qgsunittypes.h"
22#include "qgsvectorlayer.h"
24#include "qgsstringutils.h"
26
28 : QWidget( parent )
29 , mLayer( layer )
30{
31 Q_ASSERT( mLayer );
32 setupUi( this );
33
34 mModeComboBox->addItem( tr( "Fixed Time Range" ), static_cast<int>( Qgis::VectorTemporalMode::FixedTemporalRange ) );
35 mModeComboBox->addItem( tr( "Single Field with Date/Time" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeInstantFromField ) );
36 mModeComboBox->addItem( tr( "Separate Fields for Start and End Date/Time" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromFields ) );
37 mModeComboBox->addItem( tr( "Separate Fields for Start and Event Duration" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndDurationFromFields ) );
38 mModeComboBox->addItem( tr( "Start and End Date/Time from Expressions" ), static_cast<int>( Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromExpressions ) );
39 mModeComboBox->addItem( tr( "Redraw Layer Only" ), static_cast<int>( Qgis::VectorTemporalMode::RedrawLayerOnly ) );
40
41 connect( mModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), mStackedWidget, &QStackedWidget::setCurrentIndex );
42 connect( mModeComboBox, qOverload<int>( &QComboBox::currentIndexChanged ), this, [=] {
43 switch ( static_cast<Qgis::VectorTemporalMode>( mModeComboBox->currentData().toInt() ) )
44 {
45 case Qgis::VectorTemporalMode::FixedTemporalRange:
46 case Qgis::VectorTemporalMode::FeatureDateTimeInstantFromField:
47 case Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromFields:
48 case Qgis::VectorTemporalMode::FeatureDateTimeStartAndDurationFromFields:
49 case Qgis::VectorTemporalMode::FeatureDateTimeStartAndEndFromExpressions:
50 mLimitsComboBox->show();
51 mLimitsLabel->show();
52 break;
53 case Qgis::VectorTemporalMode::RedrawLayerOnly:
54 mLimitsComboBox->hide();
55 mLimitsLabel->hide();
56 break;
57 }
58 } );
59
60 mLimitsComboBox->addItem( tr( "Include Start, Exclude End (default)" ), static_cast<int>( Qgis::VectorTemporalLimitMode::IncludeBeginExcludeEnd ) );
61 mLimitsComboBox->addItem( tr( "Include Start, Include End" ), static_cast<int>( Qgis::VectorTemporalLimitMode::IncludeBeginIncludeEnd ) );
62
63 mStartTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
64 mEndTemporalDateTimeEdit->setDisplayFormat( "yyyy-MM-dd HH:mm:ss" );
65
66 mSingleFieldComboBox->setLayer( layer );
67 mStartFieldComboBox->setLayer( layer );
68 mEndFieldComboBox->setLayer( layer );
69 mDurationStartFieldComboBox->setLayer( layer );
70 mDurationFieldComboBox->setLayer( layer );
71 mSingleFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
72 mStartFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
73 mStartFieldComboBox->setAllowEmptyFieldName( true );
74 mEndFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
75 mEndFieldComboBox->setAllowEmptyFieldName( true );
76 mDurationStartFieldComboBox->setFilters( QgsFieldProxyModel::DateTime | QgsFieldProxyModel::Date );
77 mDurationFieldComboBox->setFilters( QgsFieldProxyModel::Numeric );
78
79 mFixedDurationSpinBox->setMinimum( 0 );
80 mFixedDurationSpinBox->setClearValue( 0 );
81
82 for ( const Qgis::TemporalUnit u :
83 {
94 } )
95 {
98 mDurationUnitsComboBox->addItem( title, static_cast<int>( u ) );
99 mFixedDurationUnitsComboBox->addItem( title, static_cast<int>( u ) );
100 }
101
102 mFixedDurationUnitsComboBox->setEnabled( !mAccumulateCheckBox->isChecked() );
103 mFixedDurationSpinBox->setEnabled( !mAccumulateCheckBox->isChecked() );
104 connect( mAccumulateCheckBox, &QCheckBox::toggled, this, [=]( bool checked ) {
105 mFixedDurationUnitsComboBox->setEnabled( !checked );
106 mFixedDurationSpinBox->setEnabled( !checked );
107 } );
108
109 mStartExpressionWidget->setAllowEmptyFieldName( true );
110 mEndExpressionWidget->setAllowEmptyFieldName( true );
111 mStartExpressionWidget->setLayer( layer );
112 mEndExpressionWidget->setLayer( layer );
113 mStartExpressionWidget->registerExpressionContextGenerator( this );
114 mEndExpressionWidget->registerExpressionContextGenerator( this );
115
116 syncToLayer();
117}
118
120{
121 QgsVectorLayerTemporalProperties *properties = qobject_cast<QgsVectorLayerTemporalProperties *>( mLayer->temporalProperties() );
122
123 properties->setIsActive( mTemporalGroupBox->isChecked() );
124 properties->setMode( static_cast<Qgis::VectorTemporalMode>( mModeComboBox->currentData().toInt() ) );
125 properties->setLimitMode( static_cast<Qgis::VectorTemporalLimitMode>( mLimitsComboBox->currentData().toInt() ) );
126
127 const QgsDateTimeRange normalRange = QgsDateTimeRange( mStartTemporalDateTimeEdit->dateTime(), mEndTemporalDateTimeEdit->dateTime() );
128
129 properties->setFixedTemporalRange( normalRange );
130
131 switch ( properties->mode() )
132 {
137 properties->setStartField( mSingleFieldComboBox->currentField() );
138 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mFixedDurationUnitsComboBox->currentData().toInt() ) );
139 break;
140
142 properties->setStartField( mStartFieldComboBox->currentField() );
143 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mFixedDurationUnitsComboBox->currentData().toInt() ) );
144 break;
145
147 properties->setStartField( mDurationStartFieldComboBox->currentField() );
148 properties->setDurationUnits( static_cast<Qgis::TemporalUnit>( mDurationUnitsComboBox->currentData().toInt() ) );
149 break;
150 }
151
152 properties->setEndField( mEndFieldComboBox->currentField() );
153 properties->setDurationField( mDurationFieldComboBox->currentField() );
154 properties->setFixedDuration( mFixedDurationSpinBox->value() );
155 properties->setAccumulateFeatures( mAccumulateCheckBox->isChecked() );
156 properties->setStartExpression( mStartExpressionWidget->currentField() );
157 properties->setEndExpression( mEndExpressionWidget->currentField() );
158}
159
166
168{
169 const QgsVectorLayerTemporalProperties *properties = qobject_cast<QgsVectorLayerTemporalProperties *>( mLayer->temporalProperties() );
170 mTemporalGroupBox->setChecked( properties->isActive() );
171
172 mModeComboBox->setCurrentIndex( mModeComboBox->findData( static_cast<int>( properties->mode() ) ) );
173 mStackedWidget->setCurrentIndex( static_cast<int>( properties->mode() ) );
174
175 mLimitsComboBox->setCurrentIndex( mLimitsComboBox->findData( static_cast<int>( properties->limitMode() ) ) );
176
177 mStartTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().begin() );
178 mEndTemporalDateTimeEdit->setDateTime( properties->fixedTemporalRange().end() );
179
180 mFixedDurationSpinBox->setValue( properties->fixedDuration() );
181
182 mSingleFieldComboBox->setField( properties->startField() );
183 mStartFieldComboBox->setField( properties->startField() );
184 mDurationStartFieldComboBox->setField( properties->startField() );
185 mEndFieldComboBox->setField( properties->endField() );
186 mDurationFieldComboBox->setField( properties->durationField() );
187 mDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( static_cast<int>( properties->durationUnits() ) ) );
188 mFixedDurationUnitsComboBox->setCurrentIndex( mDurationUnitsComboBox->findData( static_cast<int>( properties->durationUnits() ) ) );
189
190 mAccumulateCheckBox->setChecked( properties->accumulateFeatures() );
191
192 mStartExpressionWidget->setField( properties->startExpression() );
193 mEndExpressionWidget->setField( properties->endExpression() );
194}
VectorTemporalMode
Vector layer temporal feature modes.
Definition qgis.h:2475
@ FeatureDateTimeStartAndDurationFromFields
Mode when features have a field for start time and a field for event duration.
@ RedrawLayerOnly
Redraw the layer when temporal range changes, but don't apply any filtering. Useful when symbology or...
@ FeatureDateTimeStartAndEndFromExpressions
Mode when features use expressions for start and end times.
@ FeatureDateTimeInstantFromField
Mode when features have a datetime instant taken from a single field.
@ FixedTemporalRange
Mode when temporal properties have fixed start and end datetimes.
@ FeatureDateTimeStartAndEndFromFields
Mode when features have separate fields for start and end times.
@ TitleCase
Simple title case conversion - does not fully grammatically parse the text and uses simple rules only...
TemporalUnit
Temporal units.
Definition qgis.h:4886
@ Milliseconds
Milliseconds.
@ Centuries
Centuries.
VectorTemporalLimitMode
Mode for the handling of the limits of the filtering timeframe for vector features.
Definition qgis.h:2491
@ IncludeBeginExcludeEnd
Default mode: include the Begin limit, but exclude the End limit.
@ IncludeBeginIncludeEnd
Mode to include both limits of the filtering timeframe.
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:270
static QgsGui::HigFlags higFlags()
Returns the platform's HIG flags.
Definition qgsgui.cpp:234
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:444
T end() const
Returns the upper bound of the range.
Definition qgsrange.h:451
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 data sets.
QgsMapLayerTemporalProperties * temporalProperties() override
Returns the layer's temporal properties.
QgsTemporalRange< QDateTime > QgsDateTimeRange
QgsRange which stores a range of date times.
Definition qgsrange.h:742