18 #include <QStringList> 21 #include <QVariantList> 31 : mStatistics( stats )
53 Q_FOREACH (
const QString &
string, values )
67 if ( value.type() == QVariant::String )
69 testString( value.toString() );
76 mMeanLength = mSumLengths /
static_cast< double >( mCount );
83 Q_FOREACH (
const QVariant &variant, values )
85 if ( variant.type() == QVariant::String )
87 testString( variant.toString() );
92 void QgsStringStatisticalSummary::testString(
const QString &
string )
96 if (
string.isEmpty() )
103 if ( mStatistics &
Min )
105 if ( !mMin.isEmpty() && !
string.isEmpty() )
107 mMin = std::min( mMin,
string );
109 else if ( mMin.isEmpty() && !
string.isEmpty() )
114 if ( mStatistics &
Max )
116 if ( !mMax.isEmpty() && !
string.isEmpty() )
118 mMax = std::max( mMax,
string );
120 else if ( mMax.isEmpty() && !
string.isEmpty() )
126 mSumLengths +=
string.length();
127 mMinLength = std::min( mMinLength,
string.length() );
128 mMaxLength = std::max( mMaxLength,
string.length() );
138 return mValues.count();
140 return mCountMissing;
162 return QObject::tr(
"Count" );
164 return QObject::tr(
"Count (distinct)" );
166 return QObject::tr(
"Count (missing)" );
168 return QObject::tr(
"Minimum" );
170 return QObject::tr(
"Maximum" );
172 return QObject::tr(
"Minimum length" );
174 return QObject::tr(
"Maximum length" );
176 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.