QGIS API Documentation 4.0.0-Norrköping (1ddcee3d0e4)
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 "qgis.h"
20#include "qgis_core.h"
21
22#include <QSet>
23#include <QVariantList>
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
42
44{
45 public:
51
57 Qgis::StringStatistics statistics() const { return mStatistics; }
58
65 void setStatistics( Qgis::StringStatistics stats ) { mStatistics = stats; }
66
70 void reset();
71
78 void calculate( const QStringList &values );
79
87 void calculateFromVariants( const QVariantList &values );
88
103 void addString( const QString &string );
104
118 void addValue( const QVariant &value );
119
125 void finalize();
126
132 QVariant statistic( Qgis::StringStatistic stat ) const;
133
137 int count() const { return mCount; }
138
143 int countDistinct() const { return mValues.count(); }
144
149 QSet< QString > distinctValues() const;
150
154 int countMissing() const { return mCountMissing; }
155
159 QString min() const { return mMin; }
160
164 QString max() const { return mMax; }
165
169 int minLength() const { return mMinLength; }
170
174 int maxLength() const { return mMaxLength; }
175
179 double meanLength() const { return mMeanLength; }
180
189 QString minority() const { return mMinority; }
190
199 QString majority() const { return mMajority; }
200
205 static QString displayName( Qgis::StringStatistic statistic );
206
207 private:
208 Qgis::StringStatistics mStatistics;
209
210 int mCount;
211 QMap< QString, int > mValues;
212 int mCountMissing;
213 QString mMin;
214 QString mMax;
215 int mMinLength;
216 int mMaxLength;
217 long mSumLengths;
218 double mMeanLength;
219 QString mMinority;
220 QString mMajority;
221
222 void testString( const QString &string );
223};
224
225#endif // QGSSTRINGSTATISTICALSUMMARY_H
QFlags< StringStatistic > StringStatistics
Statistics to be calculated for string values.
Definition qgis.h:6288
StringStatistic
Available string statistics.
Definition qgis.h:6268
@ All
All statistics.
Definition qgis.h:6279
void setStatistics(Qgis::StringStatistics stats)
Sets flags which specify which statistics will be calculated.
QString max() const
Returns the maximum (non-null) string value.
QgsStringStatisticalSummary(Qgis::StringStatistics stats=Qgis::StringStatistic::All)
Constructor for QgsStringStatistics.
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.