22#include <QVariantList> 
   32  : mStatistics( stats )
 
 
   44  mMinLength = std::numeric_limits<int>::max();
 
   48  mMinority = QString();
 
   49  mMajority = QString();
 
 
   56  const auto constValues = values;
 
   57  for ( 
const QString &
string : constValues )
 
 
   73    testString( value.toString() );
 
 
   80  mMeanLength = mSumLengths / 
static_cast< double >( mCount );
 
   84    QList<int> valueCounts = mValues.values();
 
   88      mMinority = mValues.key( *std::min_element( valueCounts.begin(), valueCounts.end() ) );
 
   92      mMajority = mValues.key( *std::max_element( valueCounts.begin(), valueCounts.end() ) );
 
 
  101  const auto constValues = values;
 
  102  for ( 
const QVariant &variant : constValues )
 
  106      testString( variant.toString() );
 
 
  113void QgsStringStatisticalSummary::testString( 
const QString &
string )
 
  117  if ( 
string.isEmpty() )
 
  126    if ( !mMin.isEmpty() && !
string.isEmpty() )
 
  128      mMin = std::min( mMin, 
string );
 
  130    else if ( mMin.isEmpty() && !
string.isEmpty() )
 
  137    if ( !mMax.isEmpty() && !
string.isEmpty() )
 
  139      mMax = std::max( mMax, 
string );
 
  141    else if ( mMax.isEmpty() && !
string.isEmpty() )
 
  147    mSumLengths += 
string.length();
 
  148  mMinLength = std::min( mMinLength, 
static_cast<int>( 
string.length() ) );
 
  149  mMaxLength = std::max( mMaxLength, 
static_cast<int>( 
string.length() ) );
 
  159      return mValues.count();
 
  161      return mCountMissing;
 
 
  185  res.reserve( mValues.size() );
 
  186  for ( 
auto it = mValues.begin(); it != mValues.end(); ++it )
 
  188    res.insert( it.key() );
 
 
  198      return QObject::tr( 
"Count" );
 
  200      return QObject::tr( 
"Count (distinct)" );
 
  202      return QObject::tr( 
"Count (missing)" );
 
  204      return QObject::tr( 
"Minimum" );
 
  206      return QObject::tr( 
"Maximum" );
 
  208      return QObject::tr( 
"Minimum length" );
 
  210      return QObject::tr( 
"Maximum length" );
 
  212      return QObject::tr( 
"Mean length" );
 
  214      return QObject::tr( 
"Minority" );
 
  216      return QObject::tr( 
"Majority" );
 
 
QFlags< StringStatistic > StringStatistics
Statistics to be calculated for string values.
 
StringStatistic
Available string statistics.
 
@ Max
Maximum string value.
 
@ Min
Minimum string value.
 
@ MaximumLength
Maximum length of string.
 
@ MeanLength
Mean length of strings.
 
@ Minority
Minority of strings.
 
@ CountMissing
Number of missing (null) values.
 
@ Majority
Majority of strings.
 
@ CountDistinct
Number of distinct string values.
 
@ MinimumLength
Minimum length of string.
 
QgsStringStatisticalSummary(Qgis::StringStatistics stats=Qgis::StringStatistic::All)
Constructor for QgsStringStatistics.
 
static QString displayName(Qgis::StringStatistic 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.
 
QSet< QString > distinctValues() const
Returns the set of distinct string values.
 
void addValue(const QVariant &value)
Adds a single variant to the statistics calculation.
 
QVariant statistic(Qgis::StringStatistic stat) const
Returns the value of a specified statistic.
 
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.
 
static bool isNull(const QVariant &variant, bool silenceNullWarnings=false)
Returns true if the specified variant should be considered a NULL value.