QGIS API Documentation 3.32.0-Lima (311a8cb8a6)
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#include "qgis.h"
24
25/***************************************************************************
26 * This class is considered CRITICAL and any change MUST be accompanied with
27 * full unit tests in test_qgsstringstatisticalsummary.py.
28 * See details in QEP #17
29 ****************************************************************************/
30
45{
46 public:
47
50 {
51 Count = 1,
52 CountDistinct = 2,
53 CountMissing = 4,
54 Min = 8,
55 Max = 16,
56 MinimumLength = 32,
57 MaximumLength = 64,
58 MeanLength = 128,
59 Minority = 256,
60 Majority = 512,
61 All = Count | CountDistinct | CountMissing | Min | Max | MinimumLength | MaximumLength | MeanLength | Minority | Majority,
62 };
63 Q_DECLARE_FLAGS( Statistics, Statistic )
64
65
69 QgsStringStatisticalSummary( QgsStringStatisticalSummary::Statistics stats = QgsStringStatisticalSummary::All );
70
76 Statistics statistics() const { return mStatistics; }
77
84 void setStatistics( QgsStringStatisticalSummary::Statistics stats ) { mStatistics = stats; }
85
89 void reset();
90
97 void calculate( const QStringList &values );
98
106 void calculateFromVariants( const QVariantList &values );
107
122 void addString( const QString &string );
123
137 void addValue( const QVariant &value );
138
144 void finalize();
145
151 QVariant statistic( QgsStringStatisticalSummary::Statistic stat ) const;
152
156 int count() const { return mCount; }
157
162 int countDistinct() const { return mValues.count(); }
163
168 QSet< QString > distinctValues() const;
169
173 int countMissing() const { return mCountMissing; }
174
178 QString min() const { return mMin; }
179
183 QString max() const { return mMax; }
184
188 int minLength() const { return mMinLength; }
189
193 int maxLength() const { return mMaxLength; }
194
199 double meanLength() const { return mMeanLength; }
200
209 QString minority() const { return mMinority; }
210
219 QString majority() const { return mMajority; }
220
225 static QString displayName( QgsStringStatisticalSummary::Statistic statistic );
226
227 private:
228
229 Statistics mStatistics;
230
231 int mCount;
232 QMap< QString, int > mValues;
233 int mCountMissing;
234 QString mMin;
235 QString mMax;
236 int mMinLength;
237 int mMaxLength;
238 long mSumLengths;
239 double mMeanLength;
240 QString mMinority;
241 QString mMajority;
242
243 void testString( const QString &string );
244};
245
246Q_DECLARE_OPERATORS_FOR_FLAGS( QgsStringStatisticalSummary::Statistics )
247
248#endif // QGSSTRINGSTATISTICALSUMMARY_H
Calculator for summary statistics and aggregates for a list of strings.
Statistics statistics() const
Returns flags which specify which statistics will be calculated.
QString max() const
Returns the maximum (non-null) string value.
QString min() const
Returns the minimum (non-null) string value.
int countMissing() const
Returns the number of missing (null) string values.
int count() const
Returns the calculated count of values.
int countDistinct() const
Returns the number of distinct string values.
int minLength() const
Returns the minimum length of strings.
int maxLength() const
Returns the maximum length of strings.
Statistic
Enumeration of flags that specify statistics to be calculated.
QString majority() const
Returns the most common string.
QString minority() const
Returns the least common string.
double meanLength() const
Returns the mean length of strings.
void setStatistics(QgsStringStatisticalSummary::Statistics stats)
Sets flags which specify which statistics will be calculated.
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.