19 #include <QStringList> 22 #include <QVariantList> 32 : mStatistics( stats )
51 Q_FOREACH (
const QVariant &variant, values )
60 if ( value.type() == QVariant::DateTime )
62 testDateTime( value.toDateTime() );
64 else if ( value.type() == QVariant::Date )
66 QDate date = value.toDate();
67 testDateTime( date.isValid() ? QDateTime( date, QTime( 0, 0, 0 ) )
70 else if ( value.type() == QVariant::Time )
73 QTime time = value.toTime();
74 testDateTime( time.isValid() ? QDateTime( QDate::fromJulianDay( 0 ), time )
91 void QgsDateTimeStatisticalSummary::testDateTime(
const QDateTime &dateTime )
95 if ( !dateTime.isValid() )
102 if ( mStatistics &
Min || mStatistics &
Range )
104 if ( mMin.isValid() && dateTime.isValid() )
106 mMin = std::min( mMin, dateTime );
108 else if ( !mMin.isValid() && dateTime.isValid() )
113 if ( mStatistics &
Max || mStatistics & Range )
115 if ( mMax.isValid() && dateTime.isValid() )
117 mMax = std::max( mMax, dateTime );
119 else if ( !mMax.isValid() && dateTime.isValid() )
133 return mValues.count();
135 return mCountMissing;
137 return mIsTimes ? QVariant( mMin.time() ) : QVariant( mMin );
139 return mIsTimes ? QVariant( mMax.time() ) : QVariant( mMax );
141 return mIsTimes ? QVariant::fromValue( mMax.time() - mMin.time() ) : QVariant::fromValue( mMax - mMin );
153 return QObject::tr(
"Count" );
155 return QObject::tr(
"Count (distinct)" );
157 return QObject::tr(
"Count (missing)" );
159 return QObject::tr(
"Minimum (earliest)" );
161 return QObject::tr(
"Maximum (latest)" );
163 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...
QVariant statistic(QgsDateTimeStatisticalSummary::Statistic stat) const
Returns the value of a specified statistic.
QgsDateTimeStatisticalSummary(QgsDateTimeStatisticalSummary::Statistics stats=All)
Constructor for QgsDateTimeStatisticalSummary.
Number of distinct datetime values.