18 #include <QStringList> 
   21 #include <QVariantList> 
   31   : mStatistics( stats )
 
   43   mMinLength = std::numeric_limits<int>::max();
 
   47   mMinority = QString();
 
   48   mMajority = QString();
 
   55   const auto constValues = values;
 
   56   for ( 
const QString &
string : constValues )
 
   70   if ( value.type() == QVariant::String )
 
   72     testString( value.toString() );
 
   79   mMeanLength = mSumLengths / 
static_cast< double >( mCount );
 
   83     QList<int> valueCounts = mValues.values();
 
   87       mMinority = mValues.key( *std::min_element( valueCounts.begin(), valueCounts.end() ) );
 
   91       mMajority = mValues.key( *std::max_element( valueCounts.begin(), valueCounts.end() ) );
 
  100   const auto constValues = values;
 
  101   for ( 
const QVariant &variant : constValues )
 
  103     if ( variant.type() == QVariant::String )
 
  105       testString( variant.toString() );
 
  112 void QgsStringStatisticalSummary::testString( 
const QString &
string )
 
  116   if ( 
string.isEmpty() )
 
  123   if ( mStatistics & 
Min )
 
  125     if ( !mMin.isEmpty() && !
string.isEmpty() )
 
  127       mMin = std::min( mMin, 
string );
 
  129     else if ( mMin.isEmpty() && !
string.isEmpty() )
 
  134   if ( mStatistics & 
Max )
 
  136     if ( !mMax.isEmpty() && !
string.isEmpty() )
 
  138       mMax = std::max( mMax, 
string );
 
  140     else if ( mMax.isEmpty() && !
string.isEmpty() )
 
  146     mSumLengths += 
string.length();
 
  147   mMinLength = std::min( mMinLength, 
static_cast<int>( 
string.length() ) );
 
  148   mMaxLength = std::max( mMaxLength, 
static_cast<int>( 
string.length() ) );
 
  158       return mValues.count();
 
  160       return mCountMissing;
 
  186       return QObject::tr( 
"Count" );
 
  188       return QObject::tr( 
"Count (distinct)" );
 
  190       return QObject::tr( 
"Count (missing)" );
 
  192       return QObject::tr( 
"Minimum" );
 
  194       return QObject::tr( 
"Maximum" );
 
  196       return QObject::tr( 
"Minimum length" );
 
  198       return QObject::tr( 
"Maximum length" );
 
  200       return QObject::tr( 
"Mean length" );
 
  202       return QObject::tr( 
"Minority" );
 
  204       return QObject::tr( 
"Majority" );
 
static QString displayName(QgsStringStatisticalSummary::Statistic statistic)
Returns the friendly display name for a statistic.
void finalize()
Must be called after adding all strings with addString() and before retrieving any calculated string ...
void addString(const QString &string)
Adds a single string to the statistics calculation.
QVariant statistic(QgsStringStatisticalSummary::Statistic stat) const
Returns the value of a specified statistic.
void addValue(const QVariant &value)
Adds a single variant to the statistics calculation.
QgsStringStatisticalSummary(QgsStringStatisticalSummary::Statistics stats=QgsStringStatisticalSummary::All)
Constructor for QgsStringStatistics.
Statistic
Enumeration of flags that specify statistics to be calculated.
@ Majority
Majority of strings.
@ MeanLength
Mean length of strings.
@ Max
Maximum string value.
@ Minority
Minority of strings.
@ MaximumLength
Maximum length of string.
@ MinimumLength
Minimum length of string.
@ CountDistinct
Number of distinct string values.
@ CountMissing
Number of missing (null) values.
@ Min
Minimum string value.
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.
void reset()
Resets the calculated values.