18 #include <QStringList> 21 #include <QVariantList> 31 : mStatistics( stats )
43 mMinLength = std::numeric_limits<int>::max();
53 const auto constValues = values;
54 for (
const QString &
string : constValues )
68 if ( value.type() == QVariant::String )
70 testString( value.toString() );
77 mMeanLength = mSumLengths /
static_cast< double >( mCount );
84 const auto constValues = values;
85 for (
const QVariant &variant : constValues )
87 if ( variant.type() == QVariant::String )
89 testString( variant.toString() );
94 void QgsStringStatisticalSummary::testString(
const QString &
string )
98 if (
string.isEmpty() )
105 if ( mStatistics &
Min )
107 if ( !mMin.isEmpty() && !
string.isEmpty() )
109 mMin = std::min( mMin,
string );
111 else if ( mMin.isEmpty() && !
string.isEmpty() )
116 if ( mStatistics &
Max )
118 if ( !mMax.isEmpty() && !
string.isEmpty() )
120 mMax = std::max( mMax,
string );
122 else if ( mMax.isEmpty() && !
string.isEmpty() )
128 mSumLengths +=
string.length();
129 mMinLength = std::min( mMinLength,
string.length() );
130 mMaxLength = std::max( mMaxLength,
string.length() );
140 return mValues.count();
142 return mCountMissing;
164 return QObject::tr(
"Count" );
166 return QObject::tr(
"Count (distinct)" );
168 return QObject::tr(
"Count (missing)" );
170 return QObject::tr(
"Minimum" );
172 return QObject::tr(
"Maximum" );
174 return QObject::tr(
"Minimum length" );
176 return QObject::tr(
"Maximum length" );
178 return QObject::tr(
"Mean length" );
Statistic
Enumeration of flags that specify statistics to be calculated.
Number of distinct string values.
static QString displayName(QgsStringStatisticalSummary::Statistic statistic)
Returns the friendly display name for a statistic.
Number of missing (null) values.
QgsStringStatisticalSummary(QgsStringStatisticalSummary::Statistics stats=QgsStringStatisticalSummary::All)
Constructor for QgsStringStatistics.
void addValue(const QVariant &value)
Adds a single variant to the statistics calculation.
Maximum length of string.
void addString(const QString &string)
Adds a single string to the statistics calculation.
void calculateFromVariants(const QVariantList &values)
Calculates summary statistics for an entire list of variants at once.
QVariant statistic(QgsStringStatisticalSummary::Statistic stat) const
Returns the value of a specified statistic.
Minimum length of string.
void finalize()
Must be called after adding all strings with addString() and before retrieving any calculated string ...
void calculate(const QStringList &values)
Calculates summary statistics for an entire list of strings at once.
void reset()
Resets the calculated values.