QgsStringStatisticalSummary class

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().

Public types

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

Public static functions

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

Constructors, destructors, conversion operators

QgsStringStatisticalSummary(QgsStringStatisticalSummary::Statistics stats = QgsStringStatisticalSummary::All)
Constructor for QgsStringStatistics.

Public functions

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

Enum documentation

enum QgsStringStatisticalSummary::Statistic

Enumeration of flags that specify statistics to be calculated.

Enumerators
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.

All

Function documentation

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

Returns the friendly display name for a statistic.

Parameters
statistic statistic to return name for

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

Constructor for QgsStringStatistics.

Parameters
stats flags for statistics to calculate

void QgsStringStatisticalSummary::addString(const QString& string)

Adds a single string to the statistics calculation.

Parameters
string string to add

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().

void QgsStringStatisticalSummary::addValue(const QVariant& value)

Adds a single variant to the statistics calculation.

Parameters
value variant to add

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().

void QgsStringStatisticalSummary::calculate(const QStringList& values)

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

Parameters
values list of strings

void QgsStringStatisticalSummary::calculateFromVariants(const QVariantList& values)

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

Parameters
values list of variants

Any non-string variants will be ignored.

int QgsStringStatisticalSummary::countDistinct() const

Returns the number of distinct string values.

QSet<QString> QgsStringStatisticalSummary::distinctValues() const

Returns the set of distinct string values.

void QgsStringStatisticalSummary::finalize()

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

double QgsStringStatisticalSummary::meanLength() const

Returns the mean length of strings.

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

Sets flags which specify which statistics will be calculated.

Parameters
stats flags for statistics to calculate

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

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

Returns the value of a specified statistic.

Parameters
stat statistic to return
Returns calculated value of statistic

Statistics QgsStringStatisticalSummary::statistics() const

Returns flags which specify which statistics will be calculated.

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