19 #include <QStringList> 22 #include <QVariantList> 32 : mStatistics( stats )
51 const auto constValues = values;
52 for (
const QVariant &variant : constValues )
61 if ( value.type() == QVariant::DateTime )
63 testDateTime( value.toDateTime() );
65 else if ( value.type() == QVariant::Date )
67 QDate date = value.toDate();
68 testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
71 else if ( value.type() == QVariant::Time )
74 QTime time = value.toTime();
75 testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
92 void QgsDateTimeStatisticalSummary::testDateTime(
const QDateTime &dateTime )
96 if ( !dateTime.isValid() )
103 if ( mStatistics &
Min || mStatistics &
Range )
105 if ( mMin.isValid() && dateTime.isValid() )
107 mMin = std::min( mMin, dateTime );
109 else if ( !mMin.isValid() && dateTime.isValid() )
114 if ( mStatistics &
Max || mStatistics & Range )
116 if ( mMax.isValid() && dateTime.isValid() )
118 mMax = std::max( mMax, dateTime );
120 else if ( !mMax.isValid() && dateTime.isValid() )
134 return mValues.count();
136 return mCountMissing;
138 return mIsTimes ? QVariant( mMin.time() ) : QVariant( mMin );
140 return mIsTimes ? QVariant( mMax.time() ) : QVariant( mMax );
142 return mIsTimes ? QVariant::fromValue( mMax.time() - mMin.time() ) : QVariant::fromValue( mMax - mMin );
154 return QObject::tr(
"Count" );
156 return QObject::tr(
"Count (distinct)" );
158 return QObject::tr(
"Count (missing)" );
160 return QObject::tr(
"Minimum (earliest)" );
162 return QObject::tr(
"Maximum (latest)" );
164 return QObject::tr(
"Range (interval)" );
static QString displayName(QgsDateTimeStatisticalSummary::Statistic statistic)
Returns the friendly display name for a statistic.
Number of missing (null) values.
Maximum (latest) datetime value.
void addValue(const QVariant &value)
Adds a single datetime to the statistics calculation.
Interval between earliest and latest datetime value.
void reset()
Resets the calculated values.
void calculate(const QVariantList &values)
Calculates summary statistics for a list of variants.
Statistic
Enumeration of flags that specify statistics to be calculated.
Minimum (earliest) datetime value.
void finalize()
Must be called after adding all datetimes with addValue() and before retrieving any calculated dateti...
QgsDateTimeStatisticalSummary(QgsDateTimeStatisticalSummary::Statistics stats=All)
Constructor for QgsDateTimeStatisticalSummary.
QVariant statistic(QgsDateTimeStatisticalSummary::Statistic stat) const
Returns the value of a specified statistic.
Number of distinct datetime values.