QGIS API Documentation  3.4.15-Madeira (e83d02e274)
qgsstringstatisticalsummary.h
Go to the documentation of this file.
1 /***************************************************************************
2  qgsstringstatisticalsummary.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 QGSSTRINGSTATISTICALSUMMARY_H
17 #define QGSSTRINGSTATISTICALSUMMARY_H
18 
19 #include <QSet>
20 #include <QVariantList>
21 
22 #include "qgis_core.h"
23 
24 /***************************************************************************
25  * This class is considered CRITICAL and any change MUST be accompanied with
26  * full unit tests in test_qgsstringstatisticalsummary.py.
27  * See details in QEP #17
28  ****************************************************************************/
29 
43 class CORE_EXPORT QgsStringStatisticalSummary
44 {
45  public:
46 
48  enum Statistic
49  {
50  Count = 1,
51  CountDistinct = 2,
52  CountMissing = 4,
53  Min = 8,
54  Max = 16,
55  MinimumLength = 32,
56  MaximumLength = 64,
57  MeanLength = 128,
58  All = Count | CountDistinct | CountMissing | Min | Max | MinimumLength | MaximumLength | MeanLength,
59  };
60  Q_DECLARE_FLAGS( Statistics, Statistic )
61 
62 
67 
73  Statistics statistics() const { return mStatistics; }
74 
81  void setStatistics( QgsStringStatisticalSummary::Statistics stats ) { mStatistics = stats; }
82 
86  void reset();
87 
94  void calculate( const QStringList &values );
95 
103  void calculateFromVariants( const QVariantList &values );
104 
119  void addString( const QString &string );
120 
134  void addValue( const QVariant &value );
135 
141  void finalize();
142 
148  QVariant statistic( QgsStringStatisticalSummary::Statistic stat ) const;
149 
153  int count() const { return mCount; }
154 
159  int countDistinct() const { return mValues.count(); }
160 
165  QSet< QString > distinctValues() const { return mValues; }
166 
170  int countMissing() const { return mCountMissing; }
171 
175  QString min() const { return mMin; }
176 
180  QString max() const { return mMax; }
181 
185  int minLength() const { return mMinLength; }
186 
190  int maxLength() const { return mMaxLength; }
191 
196  double meanLength() const { return mMeanLength; }
197 
202  static QString displayName( QgsStringStatisticalSummary::Statistic statistic );
203 
204  private:
205 
206  Statistics mStatistics;
207 
208  int mCount;
209  QSet< QString > mValues;
210  int mCountMissing;
211  QString mMin;
212  QString mMax;
213  int mMinLength;
214  int mMaxLength;
215  long mSumLengths;
216  double mMeanLength;
217 
218  void testString( const QString &string );
219 };
220 
221 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsStringStatisticalSummary::Statistics )
222 
223 #endif // QGSSTRINGSTATISTICALSUMMARY_H
int countDistinct() const
Returns the number of distinct string values.
Statistic
Enumeration of flags that specify statistics to be calculated.
void setStatistics(QgsStringStatisticalSummary::Statistics stats)
Sets flags which specify which statistics will be calculated.
QString max() const
Returns the maximum (non-null) string value.
int count() const
Returns the calculated count of values.
double meanLength() const
Returns the mean length of strings.
QString min() const
Returns the minimum (non-null) string value.
int countMissing() const
Returns the number of missing (null) string values.
QSet< QString > distinctValues() const
Returns the set of distinct string values.
Calculator for summary statistics and aggregates for a list of strings.
int maxLength() const
Returns the maximum length of strings.
int minLength() const
Returns the minimum length of strings.