QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
Public Types | Public Member Functions | Static Public Member Functions | List of all members
QgsStringStatisticalSummary Class Reference

Calculator for summary statistics and aggregates for a list of strings. More...

#include <qgsstringstatisticalsummary.h>

Public Types

enum  Statistic {
  Count = 1, CountDistinct = 2, CountMissing = 4, Min = 8,
  Max = 16, MinimumLength = 32, MaximumLength = 64, MeanLength = 128,
  Minority = 256, Majority = 512, All = Count | CountDistinct | CountMissing | Min | Max | MinimumLength | MaximumLength | MeanLength | Minority | Majority
}
 Enumeration of flags that specify statistics to be calculated. More...
 

Public Member Functions

 QgsStringStatisticalSummary (QgsStringStatisticalSummary::Statistics stats=QgsStringStatisticalSummary::All)
 Constructor for QgsStringStatistics. More...
 
void addString (const QString &string)
 Adds a single string to the statistics calculation. More...
 
void addValue (const QVariant &value)
 Adds a single variant to the statistics calculation. More...
 
void calculate (const QStringList &values)
 Calculates summary statistics for an entire list of strings at once. More...
 
void calculateFromVariants (const QVariantList &values)
 Calculates summary statistics for an entire list of variants at once. More...
 
int count () const
 Returns the calculated count of values. More...
 
int countDistinct () const
 Returns the number of distinct string values. More...
 
int countMissing () const
 Returns the number of missing (null) string values. More...
 
QSet< QString > distinctValues () const
 Returns the set of distinct string values. More...
 
void finalize ()
 Must be called after adding all strings with addString() and before retrieving any calculated string statistics. More...
 
QString majority () const
 Returns the most common string. More...
 
QString max () const
 Returns the maximum (non-null) string value. More...
 
int maxLength () const
 Returns the maximum length of strings. More...
 
double meanLength () const
 Returns the mean length of strings. More...
 
QString min () const
 Returns the minimum (non-null) string value. More...
 
int minLength () const
 Returns the minimum length of strings. More...
 
QString minority () const
 Returns the least common string. More...
 
void reset ()
 Resets the calculated values. More...
 
void setStatistics (QgsStringStatisticalSummary::Statistics stats)
 Sets flags which specify which statistics will be calculated. More...
 
QVariant statistic (QgsStringStatisticalSummary::Statistic stat) const
 Returns the value of a specified statistic. More...
 
Statistics statistics () const
 Returns flags which specify which statistics will be calculated. More...
 

Static Public Member Functions

static QString displayName (QgsStringStatisticalSummary::Statistic statistic)
 Returns the friendly display name for a statistic. More...
 

Detailed Description

Calculator for summary statistics and aggregates for a list of strings.

Statistics are calculated by calling calculate() and passing a list of strings. The individual statistics can then be retrieved using the associated methods. Note that not all statistics are calculated by default. Statistics which require slower computations are only calculated by specifying the statistic in the constructor or via setStatistics().

Since
QGIS 2.16

Definition at line 44 of file qgsstringstatisticalsummary.h.

Member Enumeration Documentation

◆ Statistic

Enumeration of flags that specify statistics to be calculated.

Enumerator
Count 

Count.

CountDistinct 

Number of distinct string values.

CountMissing 

Number of missing (null) values.

Min 

Minimum string value.

Max 

Maximum string value.

MinimumLength 

Minimum length of string.

MaximumLength 

Maximum length of string.

MeanLength 

Mean length of strings.

Minority 

Minority of strings.

Majority 

Majority of strings.

All 

All statistics.

Definition at line 49 of file qgsstringstatisticalsummary.h.

Constructor & Destructor Documentation

◆ QgsStringStatisticalSummary()

QgsStringStatisticalSummary::QgsStringStatisticalSummary ( QgsStringStatisticalSummary::Statistics  stats = QgsStringStatisticalSummary::All)

Constructor for QgsStringStatistics.

Parameters
statsflags for statistics to calculate

Definition at line 30 of file qgsstringstatisticalsummary.cpp.

Member Function Documentation

◆ addString()

void QgsStringStatisticalSummary::addString ( const QString &  string)

Adds a single string to the statistics calculation.

Calling this method allows strings to be added to the calculation one at a time. For large quantities of strings this may be more efficient then first adding all the strings to a list and calling calculate().

Parameters
stringstring to add
Note
call reset() before adding the first string using this method to clear the results from any previous calculations
finalize() must be called after adding the final string and before retrieving calculated statistics.
See also
calculate()
addValue()
finalize()

Definition at line 63 of file qgsstringstatisticalsummary.cpp.

◆ addValue()

void QgsStringStatisticalSummary::addValue ( const QVariant &  value)

Adds a single variant to the statistics calculation.

Calling this method allows variants to be added to the calculation one at a time. For large quantities of variants this may be more efficient then first adding all the variants to a list and calling calculateFromVariants().

Parameters
valuevariant to add
Note
call reset() before adding the first string using this method to clear the results from any previous calculations
finalize() must be called after adding the final value and before retrieving calculated statistics.
See also
calculateFromVariants()
finalize()

Definition at line 68 of file qgsstringstatisticalsummary.cpp.

◆ calculate()

void QgsStringStatisticalSummary::calculate ( const QStringList &  values)

Calculates summary statistics for an entire list of strings at once.

Parameters
valueslist of strings
See also
calculateFromVariants()
addString()

Definition at line 51 of file qgsstringstatisticalsummary.cpp.

◆ calculateFromVariants()

void QgsStringStatisticalSummary::calculateFromVariants ( const QVariantList &  values)

Calculates summary statistics for an entire list of variants at once.

Any non-string variants will be ignored.

Parameters
valueslist of variants
See also
calculate()
addValue()

Definition at line 96 of file qgsstringstatisticalsummary.cpp.

◆ count()

int QgsStringStatisticalSummary::count ( ) const
inline

Returns the calculated count of values.

Definition at line 156 of file qgsstringstatisticalsummary.h.

◆ countDistinct()

int QgsStringStatisticalSummary::countDistinct ( ) const
inline

Returns the number of distinct string values.

See also
distinctValues()

Definition at line 162 of file qgsstringstatisticalsummary.h.

◆ countMissing()

int QgsStringStatisticalSummary::countMissing ( ) const
inline

Returns the number of missing (null) string values.

Definition at line 173 of file qgsstringstatisticalsummary.h.

◆ displayName()

QString QgsStringStatisticalSummary::displayName ( QgsStringStatisticalSummary::Statistic  statistic)
static

Returns the friendly display name for a statistic.

Parameters
statisticstatistic to return name for

Definition at line 181 of file qgsstringstatisticalsummary.cpp.

◆ distinctValues()

QSet< QString > QgsStringStatisticalSummary::distinctValues ( ) const
inline

Returns the set of distinct string values.

See also
countDistinct()

Definition at line 168 of file qgsstringstatisticalsummary.h.

◆ finalize()

void QgsStringStatisticalSummary::finalize ( )

Must be called after adding all strings with addString() and before retrieving any calculated string statistics.

See also
addString()

Definition at line 77 of file qgsstringstatisticalsummary.cpp.

◆ majority()

QString QgsStringStatisticalSummary::majority ( ) const
inline

Returns the most common string.

The majority is the value with most occurrences in the list This is only calculated if Statistic::Majority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order.

See also
minority
Since
QGIS 3.14

Definition at line 219 of file qgsstringstatisticalsummary.h.

◆ max()

QString QgsStringStatisticalSummary::max ( ) const
inline

Returns the maximum (non-null) string value.

Definition at line 183 of file qgsstringstatisticalsummary.h.

◆ maxLength()

int QgsStringStatisticalSummary::maxLength ( ) const
inline

Returns the maximum length of strings.

Definition at line 193 of file qgsstringstatisticalsummary.h.

◆ meanLength()

double QgsStringStatisticalSummary::meanLength ( ) const
inline

Returns the mean length of strings.

Since
QGIS 3.0

Definition at line 199 of file qgsstringstatisticalsummary.h.

◆ min()

QString QgsStringStatisticalSummary::min ( ) const
inline

Returns the minimum (non-null) string value.

Definition at line 178 of file qgsstringstatisticalsummary.h.

◆ minLength()

int QgsStringStatisticalSummary::minLength ( ) const
inline

Returns the minimum length of strings.

Definition at line 188 of file qgsstringstatisticalsummary.h.

◆ minority()

QString QgsStringStatisticalSummary::minority ( ) const
inline

Returns the least common string.

The minority is the value with least occurrences in the list This is only calculated if Statistic::Minority has been specified in the constructor or via setStatistics. If multiple values match, return the first value relative to the initial values order.

See also
majority
Since
QGIS 3.14

Definition at line 209 of file qgsstringstatisticalsummary.h.

◆ reset()

void QgsStringStatisticalSummary::reset ( )

Resets the calculated values.

Definition at line 36 of file qgsstringstatisticalsummary.cpp.

◆ setStatistics()

void QgsStringStatisticalSummary::setStatistics ( QgsStringStatisticalSummary::Statistics  stats)
inline

Sets flags which specify which statistics will be calculated.

Some statistics are always calculated (e.g., count).

Parameters
statsflags for statistics to calculate
See also
statistics

Definition at line 84 of file qgsstringstatisticalsummary.h.

◆ statistic()

QVariant QgsStringStatisticalSummary::statistic ( QgsStringStatisticalSummary::Statistic  stat) const

Returns the value of a specified statistic.

Parameters
statstatistic to return
Returns
calculated value of statistic

Definition at line 151 of file qgsstringstatisticalsummary.cpp.

◆ statistics()

Statistics QgsStringStatisticalSummary::statistics ( ) const
inline

Returns flags which specify which statistics will be calculated.

Some statistics are always calculated (e.g., count).

See also
setStatistics

Definition at line 76 of file qgsstringstatisticalsummary.h.


The documentation for this class was generated from the following files: