QGIS API Documentation  2.18.21-Las Palmas (9fba24a)
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 /***************************************************************************
23  * This class is considered CRITICAL and any change MUST be accompanied with
24  * full unit tests in test_qgsstringstatisticalsummary.py.
25  * See details in QEP #17
26  ****************************************************************************/
27 
40 class CORE_EXPORT QgsStringStatisticalSummary
41 {
42  public:
43 
45  enum Statistic
46  {
47  Count = 1,
48  CountDistinct = 2,
49  CountMissing = 4,
50  Min = 8,
51  Max = 16,
52  MinimumLength = 32,
53  MaximumLength = 64,
54  All = Count | CountDistinct | CountMissing | Min | Max,
55  };
56  Q_DECLARE_FLAGS( Statistics, Statistic )
57 
58 
61  QgsStringStatisticalSummary( const QgsStringStatisticalSummary::Statistics& stats = All );
62 
67  Statistics statistics() const { return mStatistics; }
68 
74  void setStatistics( const Statistics& stats ) { mStatistics = stats; }
75 
78  void reset();
79 
85  void calculate( const QStringList& values );
86 
93  void calculateFromVariants( const QVariantList& values );
94 
108  void addString( const QString& string );
109 
122  void addValue( const QVariant& value );
123 
128  void finalize();
129 
134  QVariant statistic( Statistic stat ) const;
135 
138  int count() const { return mCount; }
139 
143  int countDistinct() const { return mValues.count(); }
144 
148  QSet< QString > distinctValues() const { return mValues; }
149 
152  int countMissing() const { return mCountMissing; }
153 
156  QString min() const { return mMin; }
157 
160  QString max() const { return mMax; }
161 
164  int minLength() const { return mMinLength; }
165 
168  int maxLength() const { return mMaxLength; }
169 
173  static QString displayName( Statistic statistic );
174 
175  private:
176 
177  Statistics mStatistics;
178 
179  int mCount;
180  QSet< QString > mValues;
181  int mCountMissing;
182  QString mMin;
183  QString mMax;
184  int mMinLength;
185  int mMaxLength;
186 
187  void testString( const QString& string );
188 };
189 
190 Q_DECLARE_OPERATORS_FOR_FLAGS( QgsStringStatisticalSummary::Statistics )
191 
192 #endif // QGSSTRINGSTATISTICALSUMMARY_H
int maxLength() const
Returns the maximum length of strings.
Statistics statistics() const
Returns flags which specify which statistics will be calculated.
Statistic
Enumeration of flags that specify statistics to be calculated.
int countMissing() const
Returns the number of missing (null) string values.
QString min() const
Returns the minimum (non-null) string value.
int count() const
Returns the calculated count of values.
int minLength() const
Returns the minimum length of strings.
QSet< QString > distinctValues() const
Returns the set of distinct string values.
int countDistinct() const
Returns the number of distinct string values.
Calculator for summary statistics and aggregates for a list of strings.
QString max() const
Returns the maximum (non-null) string value.
void setStatistics(const Statistics &stats)
Sets flags which specify which statistics will be calculated.