39 mFilterExpression = parameters.
filter;
44 const QString& fieldOrExpression,
57 defaultContext.
reset( createContext() );
58 context = defaultContext.
data();
70 if ( expression->hasParserError() || !expression->prepare( context ) )
78 lst.
append( fieldOrExpression );
80 lst = expression->referencedColumns();
83 .
setFlags(( expression.
data() && expression->needsGeometry() ) ?
87 if ( !mFilterExpression.
isEmpty() )
93 QVariant::Type resultType = QVariant::Double;
106 return defaultValue( aggregate );
111 QVariant v = expression->evaluate( context );
112 resultType = v.
type();
120 return calculate( aggregate, fit, resultType, attrNum, expression.
data(), mDelimiter, context, ok );
130 if ( normalized ==
"count" )
132 else if ( normalized ==
"count_distinct" )
134 else if ( normalized ==
"count_missing" )
136 else if ( normalized ==
"min" )
138 else if ( normalized ==
"max" )
140 else if ( normalized ==
"sum" )
142 else if ( normalized ==
"mean" )
144 else if ( normalized ==
"median" )
146 else if ( normalized ==
"stdev" )
148 else if ( normalized ==
"stdevsample" )
150 else if ( normalized ==
"range" )
152 else if ( normalized ==
"minority" )
154 else if ( normalized ==
"majority" )
156 else if ( normalized ==
"q1" )
158 else if ( normalized ==
"q3" )
160 else if ( normalized ==
"iqr" )
162 else if ( normalized ==
"min_length" )
164 else if ( normalized ==
"max_length" )
166 else if ( normalized ==
"concatenate" )
181 switch ( resultType )
185 case QVariant::LongLong:
186 case QVariant::ULongLong:
187 case QVariant::Double:
196 return calculateNumericAggregate( fit, attr, expression, context, stat );
200 case QVariant::DateTime:
209 return calculateDateTimeAggregate( fit, attr, expression, context, stat );
220 return concatenateStrings( fit, attr, expression, context, delimiter );
230 return calculateStringAggregate( fit, attr, expression, context, stat );
385 Q_ASSERT( expression || attr >= 0 );
406 return qIsNaN( val ) ?
QVariant() : val;
412 Q_ASSERT( expression || attr >= 0 );
438 Q_ASSERT( expression || attr >= 0 );
500 Q_ASSERT( expression || attr >= 0 );
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
Third quartile (numeric fields only)
Inter quartile range (IQR) (numeric fields only)
Median of values (numeric fields only)
Q_DECL_DEPRECATED QVariant evaluate(const QgsFeature *f)
Evaluate the feature and return the result.
QVariant statistic(Statistic stat) const
Returns the value of a specified statistic.
Statistic
Enumeration of flags that specify statistics to be calculated.
void setFeature(const QgsFeature &feature)
Convenience function for setting a feature for the context.
First quartile (numeric fields only)
Number of missing (null) values.
QgsFeatureIterator getFeatures(const QgsFeatureRequest &request=QgsFeatureRequest())
Query the provider for features specified in request.
Number of missing (null) values.
Maximum (latest) datetime value.
void addValue(const QVariant &value)
Adds a single datetime to the statistics calculation.
Variety (count of distinct) values.
void finalize()
Must be called after adding all values with addValues() and before retrieving any calculated statisti...
Statistic
Enumeration of flags that specify statistics to be calculated.
QgsFeatureRequest & setSubsetOfAttributes(const QgsAttributeList &attrs)
Set a subset of attributes that will be fetched.
Interval between earliest and latest datetime value.
QgsAggregateCalculator(QgsVectorLayer *layer)
Constructor for QgsAggregateCalculator.
void addVariant(const QVariant &value)
Adds a single value to the statistics calculation.
Calculator for summary statistics and aggregates for a list of datetimes.
Sample standard deviation of values.
The feature class encapsulates a single feature including its id, geometry and a list of field/values...
Standard deviation of values (numeric fields only)
Number of distinct string values.
double statistic(Statistic stat) const
Returns the value of a specified statistic.
QString delimiter
Delimiter to use for joining values with the StringConcatenate aggregate.
void setParameters(const AggregateParameters ¶meters)
Sets all aggregate parameters from a parameter bundle.
const QgsField & at(int i) const
Get field at particular index (must be in range 0..N-1)
QgsFields fields() const
Returns the list of fields of this layer.
QgsFeatureRequest & setExpressionContext(const QgsExpressionContext &context)
Sets the expression context used to evaluate filter expressions.
QgsFeatureRequest & setFilterExpression(const QString &expression)
Set the filter expression.
Number of missing (null) values.
void append(const T &value)
static QgsExpressionContextScope * globalScope()
Creates a new scope which contains variables and functions relating to the global QGIS context...
static Aggregate stringToAggregate(const QString &string, bool *ok=nullptr)
Converts a string to a aggregate type.
Number of missing (null) values.
Minimum length of string (string fields only)
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Inter quartile range (IQR)
QgsVectorLayer * layer() const
Returns the associated vector layer.
void addValue(const QVariant &value)
Adds a single variant to the statistics calculation.
This class wraps a request for features to a vector layer (or directly its vector data provider)...
QgsFeatureRequest & setFlags(const QgsFeatureRequest::Flags &flags)
Set flags that affect how features will be fetched.
Statistic
Enumeration of flags that specify statistics to be calculated.
Minimum (earliest) datetime value.
QVariant calculate(Aggregate aggregate, const QString &fieldOrExpression, QgsExpressionContext *context=nullptr, bool *ok=nullptr) const
Calculates the value of an aggregate.
Majority of values (numeric fields only)
void setFields(const QgsFields &fields)
Convenience function for setting a fields for the context.
Maximum length of string.
void finalize()
Must be called after adding all datetimes with addValue() and before retrieving any calculated dateti...
Number of distinct values.
QString delimiter() const
Returns the delimiter used for joining values with the StringConcatenate aggregate.
Maximum length of string (string fields only)
QString filter
Optional filter for calculating aggregate over a subset of features, or an empty string to use all fe...
Mean of values (numeric fields only)
void appendScope(QgsExpressionContextScope *scope)
Appends a scope to the end of the context.
Calculator for summary statistics and aggregates for a list of strings.
QgsFeatureRequest & setLimit(long limit)
Set the maximum number of features to request.
Minimum length of string.
Standard deviation of values.
static QgsExpressionContextScope * projectScope()
Creates a new scope which contains variables and functions relating to the current QGIS project...
void finalize()
Must be called after adding all strings with addString() and before retrieving any calculated string ...
static QgsExpressionContextScope * layerScope(const QgsMapLayer *layer)
Creates a new scope which contains variables and functions relating to a QgsMapLayer.
bool nextFeature(QgsFeature &f)
Minority of values (numeric fields only)
Geometry is not required. It may still be returned if e.g. required for a filter condition.
QVariant statistic(Statistic stat) const
Returns the value of a specified statistic.
Calculator for summary statistics for a list of doubles.
Represents a vector layer which manages a vector based data sets.
QVariant::Type type() const
Gets variant type of the field as it will be retrieved from data source.
QVariant attribute(const QString &name) const
Lookup attribute value from attribute name.
Range of values (max - min) (numeric and datetime fields only)
int fieldNameIndex(const QString &fieldName) const
Returns the index of a field name or -1 if the field does not exist.
Sample standard deviation of values (numeric fields only)
Range of values (max - min)
Aggregate
Available aggregates to calculate.
A bundle of parameters controlling aggregate calculation.
Number of distinct datetime values.