QGIS API Documentation 3.41.0-Master (fda2aa46e9a)
Loading...
Searching...
No Matches
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
44{
45 public:
46
52
58 Qgis::StringStatistics statistics() const { return mStatistics; }
59
66 void setStatistics( Qgis::StringStatistics stats ) { mStatistics = stats; }
67
71 void reset();
72
79 void calculate( const QStringList &values );
80
88 void calculateFromVariants( const QVariantList &values );
89
104 void addString( const QString &string );
105
119 void addValue( const QVariant &value );
120
126 void finalize();
127
133 QVariant statistic( Qgis::StringStatistic stat ) const;
134
138 int count() const { return mCount; }
139
144 int countDistinct() const { return mValues.count(); }
145
150 QSet< QString > distinctValues() const;
151
155 int countMissing() const { return mCountMissing; }
156
160 QString min() const { return mMin; }
161
165 QString max() const { return mMax; }
166
170 int minLength() const { return mMinLength; }
171
175 int maxLength() const { return mMaxLength; }
176
180 double meanLength() const { return mMeanLength; }
181
190 QString minority() const { return mMinority; }
191
200 QString majority() const { return mMajority; }
201
206 static QString displayName( Qgis::StringStatistic statistic );
207
208 private:
209
210 Qgis::StringStatistics mStatistics;
211
212 int mCount;
213 QMap< QString, int > mValues;
214 int mCountMissing;
215 QString mMin;
216 QString mMax;
217 int mMinLength;
218 int mMaxLength;
219 long mSumLengths;
220 double mMeanLength;
221 QString mMinority;
222 QString mMajority;
223
224 void testString( const QString &string );
225};
226
227#endif // QGSSTRINGSTATISTICALSUMMARY_H
QFlags< StringStatistic > StringStatistics
Statistics to be calculated for string values.
Definition qgis.h:5514
StringStatistic
Available string statistics.
Definition qgis.h:5494
@ All
All statistics.
Calculator for summary statistics and aggregates for a list of strings.
void setStatistics(Qgis::StringStatistics stats)
Sets 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.
QString majority() const
Returns the most common string.
Qgis::StringStatistics statistics() const
Returns flags which specify which statistics will be calculated.
QString minority() const
Returns the least common string.
double meanLength() const
Returns the mean length of strings.