QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsdatetimestatisticalsummary.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsdatetimestatisticalsummary.h
3 -------------------------------
4 Date : May 2016
5 Copyright : (C) 2016 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 QGSDATETIMESTATISTICALSUMMARY_H
17#define QGSDATETIMESTATISTICALSUMMARY_H
18
19#include "qgis_core.h"
20#include "qgis_sip.h"
21#include "qgsinterval.h"
22#include <QSet>
23#include <QDateTime>
24#include <QVariantList>
25
26/***************************************************************************
27 * This class is considered CRITICAL and any change MUST be accompanied with
28 * full unit tests in test_qgsdatetimestatisticalsummary.py.
29 * See details in QEP #17
30 ****************************************************************************/
31
46{
47 public:
48
51 {
52 Count = 1,
53 CountDistinct = 2,
54 CountMissing = 4,
55 Min = 8,
56 Max = 16,
57 Range = 32,
58 All = Count | CountDistinct | CountMissing | Min | Max | Range,
59 };
60 Q_DECLARE_FLAGS( Statistics, Statistic )
61
62
66 QgsDateTimeStatisticalSummary( QgsDateTimeStatisticalSummary::Statistics stats = All );
67
73 Statistics statistics() const { return mStatistics; }
74
81 void setStatistics( Statistics stats ) { mStatistics = stats; }
82
86 void reset();
87
94 void calculate( const QVariantList &values );
95
109 void addValue( const QVariant &value );
110
116 void finalize();
117
123 QVariant statistic( QgsDateTimeStatisticalSummary::Statistic stat ) const;
124
128 int count() const { return mCount; }
129
133 int countDistinct() const { return mValues.count(); }
134
138 QSet< QDateTime > distinctValues() const { return mValues; }
139
143 int countMissing() const { return mCountMissing; }
144
148 QDateTime min() const { return mMin; }
149
153 QDateTime max() const { return mMax; }
154
158 QgsInterval range() const { return mMax - mMin; }
159
164 static QString displayName( QgsDateTimeStatisticalSummary::Statistic statistic );
165
166 private:
167
168 Statistics mStatistics;
169
170 int mCount;
171 QSet< QDateTime > mValues;
172 int mCountMissing;
173 QDateTime mMin;
174 QDateTime mMax;
175 bool mIsTimes;
176
177 void testDateTime( const QDateTime &dateTime, bool isNull );
178};
179
180Q_DECLARE_OPERATORS_FOR_FLAGS( QgsDateTimeStatisticalSummary::Statistics )
181
182#endif // QGSDATETIMESTATISTICALSUMMARY_H
Calculator for summary statistics and aggregates for a list of datetimes.
QgsInterval range() const
Returns the range (interval between earliest and latest non-null datetime values).
QDateTime min() const
Returns the minimum (earliest) non-null datetime value.
Statistic
Enumeration of flags that specify statistics to be calculated.
int count() const
Returns the calculated count of values.
Statistics statistics() const
Returns flags which specify which statistics will be calculated.
void setStatistics(Statistics stats)
Sets flags which specify which statistics will be calculated.
int countMissing() const
Returns the number of missing (null) datetime values.
int countDistinct() const
Returns the number of distinct datetime values.
QSet< QDateTime > distinctValues() const
Returns the set of distinct datetime values.
QDateTime max() const
Returns the maximum (latest) non-null datetime value.
A representation of the interval between two datetime values.
Definition: qgsinterval.h:42
Q_DECLARE_OPERATORS_FOR_FLAGS(QgsField::ConfigurationFlags) CORE_EXPORT QDataStream &operator<<(QDataStream &out
Writes the field to stream out. QGIS version compatibility is not guaranteed.