QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
qgstemporalutils.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgstemporalutils.h
3  ------------------
4  Date : March 2020
5  Copyright : (C) 2020 by Nyall Dawson
6  Email : nyall dot dawson at gmail dot com
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #ifndef QGSTEMPORALUTILS_H
17 #define QGSTEMPORALUTILS_H
18 
19 #include "qgis_core.h"
20 #include "qgsrange.h"
21 #include "qgsinterval.h"
22 
23 class QgsProject;
24 class QgsMapSettings;
25 class QgsFeedback;
26 class QgsMapDecoration;
27 
28 #ifndef SIP_RUN
29 
40 class CORE_EXPORT QgsTimeDuration
41 {
42  public:
43 
45  int years = 0;
47  int months = 0;
49  int weeks = 0;
51  int days = 0;
53  int hours = 0;
55  int minutes = 0;
57  double seconds = 0;
58 
62  bool isNull() const
63  {
64  return !years && !months && !days &&
65  !hours && !minutes && !seconds;
66  }
67 
68  // TODO c++20 - replace with = default
69  bool operator==( const QgsTimeDuration &other ) const
70  {
71  return years == other.years && months == other.months && weeks == other.weeks &&
72  days == other.days && hours == other.hours &&
73  minutes == other.minutes && seconds == other.seconds;
74  }
75 
76  bool operator!=( const QgsTimeDuration &other ) const
77  {
78  return !( *this == other );
79  }
80 
84  QgsInterval toInterval() const;
85 
89  QString toString() const;
90 
97  long long toSeconds() const;
98 
102  QDateTime addToDateTime( const QDateTime &dateTime );
103 
107  static QgsTimeDuration fromString( const QString &string, bool &ok );
108 
109 };
110 #endif
111 
112 
121 class CORE_EXPORT QgsTemporalUtils
122 {
123  public:
124 
131  static QgsDateTimeRange calculateTemporalRangeForProject( QgsProject *project );
132 
144  static QList< QgsDateTimeRange > usedTemporalRangesForProject( QgsProject *project );
145 
148  {
150  QgsDateTimeRange animationRange;
151 
154 
157 
166 
168  QList<QgsMapDecoration *> decorations;
169 
175  double frameRate = 30;
176 
177  };
178 
196  static bool exportAnimation( const QgsMapSettings &mapSettings, const AnimationExportSettings &settings, QString &error SIP_OUT, QgsFeedback *feedback = nullptr );
197 
219  static QDateTime calculateFrameTime( const QDateTime &start, const long long frame, const QgsInterval &interval );
220 
232  static QList< QDateTime > calculateDateTimesUsingDuration( const QDateTime &start, const QDateTime &end, const QString &duration, bool &ok SIP_OUT, bool &maxValuesExceeded SIP_OUT, int maxValues = -1 );
233 
234 #ifndef SIP_RUN
235 
247  static QList< QDateTime > calculateDateTimesUsingDuration( const QDateTime &start, const QDateTime &end, const QgsTimeDuration &duration, bool &maxValuesExceeded SIP_OUT, int maxValues = -1 );
248 #endif
249 
259  static QList< QDateTime > calculateDateTimesFromISO8601( const QString &string, bool &ok SIP_OUT, bool &maxValuesExceeded SIP_OUT, int maxValues = -1 );
260 
261 };
262 
263 
264 #endif // QGSTEMPORALUTILS_H
QgsTemporalUtils::AnimationExportSettings
Contains settings relating to exporting animations.
Definition: qgstemporalutils.h:147
QgsTimeDuration::operator==
bool operator==(const QgsTimeDuration &other) const
Definition: qgstemporalutils.h:69
qgsinterval.h
SIP_OUT
#define SIP_OUT
Definition: qgis_sip.h:58
QgsTimeDuration::hours
int hours
Hours.
Definition: qgstemporalutils.h:53
QgsTemporalUtils::AnimationExportSettings::animationRange
QgsDateTimeRange animationRange
Dictates the overall temporal range of the animation.
Definition: qgstemporalutils.h:150
qgsrange.h
QgsTimeDuration::seconds
double seconds
Seconds.
Definition: qgstemporalutils.h:57
QgsProject
Encapsulates a QGIS project, including sets of map layers and their styles, layouts,...
Definition: qgsproject.h:103
QgsTimeDuration::years
int years
Years.
Definition: qgstemporalutils.h:45
QgsTemporalUtils::AnimationExportSettings::outputDirectory
QString outputDirectory
Destination directory for created image files.
Definition: qgstemporalutils.h:156
QgsFeedback
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition: qgsfeedback.h:44
QgsTemporalUtils::AnimationExportSettings::fileNameTemplate
QString fileNameTemplate
The filename template for exporting the frames.
Definition: qgstemporalutils.h:165
QgsTemporalUtils
Contains utility methods for working with temporal layers and projects.
Definition: qgstemporalutils.h:121
QgsTimeDuration::minutes
int minutes
Minutes.
Definition: qgstemporalutils.h:55
QgsTimeDuration::months
int months
Months.
Definition: qgstemporalutils.h:47
QgsTimeDuration::isNull
bool isNull() const
Returns true if the duration is null, i.e.
Definition: qgstemporalutils.h:62
QgsTemporalUtils::AnimationExportSettings::frameDuration
QgsInterval frameDuration
Duration of individual export frames.
Definition: qgstemporalutils.h:153
QgsTimeDuration::weeks
int weeks
Weeks.
Definition: qgstemporalutils.h:49
QgsTimeDuration
Contains utility methods for working with temporal layers and projects.
Definition: qgstemporalutils.h:40
QgsInterval
A representation of the interval between two datetime values.
Definition: qgsinterval.h:41
QgsMapDecoration
Interface for map decorations.
Definition: qgsmapdecoration.h:34
QgsMapSettings
The QgsMapSettings class contains configuration for rendering of the map. The rendering itself is don...
Definition: qgsmapsettings.h:88
QgsTemporalUtils::AnimationExportSettings::decorations
QList< QgsMapDecoration * > decorations
List of decorations to draw onto exported frames.
Definition: qgstemporalutils.h:168
QgsTimeDuration::operator!=
bool operator!=(const QgsTimeDuration &other) const
Definition: qgstemporalutils.h:76
QgsTimeDuration::days
int days
Days.
Definition: qgstemporalutils.h:51