QGIS API Documentation 3.41.0-Master (af5edcb665c)
|
Utility class for calculating aggregates for a field (or expression) over the features from a vector layer. More...
#include <qgsaggregatecalculator.h>
Classes | |
struct | AggregateInfo |
Structured information about the available aggregates. More... | |
struct | AggregateParameters |
A bundle of parameters controlling aggregate calculation. More... | |
Public Member Functions | |
QgsAggregateCalculator (const QgsVectorLayer *layer) | |
Constructor for QgsAggregateCalculator. | |
QVariant | calculate (Qgis::Aggregate aggregate, const QString &fieldOrExpression, QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeedback *feedback=nullptr) const |
Calculates the value of an aggregate. | |
QString | delimiter () const |
Returns the delimiter used for joining values with the StringConcatenate aggregate. | |
QString | filter () const |
Returns the filter which limits the features used during the aggregate calculation. | |
QString | lastError () const |
Returns the last error encountered during the aggregate calculation. | |
const QgsVectorLayer * | layer () const |
Returns the associated vector layer. | |
void | setDelimiter (const QString &delimiter) |
Sets the delimiter to use for joining values with the StringConcatenate aggregate. | |
void | setFidsFilter (const QgsFeatureIds &fids) |
Sets a filter to limit the features used during the aggregate calculation. | |
void | setFilter (const QString &filterExpression) |
Sets a filter to limit the features used during the aggregate calculation. | |
void | setParameters (const AggregateParameters ¶meters) |
Sets all aggregate parameters from a parameter bundle. | |
Static Public Member Functions | |
static QList< QgsAggregateCalculator::AggregateInfo > | aggregates () |
Structured information for available aggregates. | |
static QString | displayName (Qgis::Aggregate aggregate) |
Returns the friendly display name for a aggregate. | |
static Qgis::Aggregate | stringToAggregate (const QString &string, bool *ok=nullptr) |
Converts a string to a aggregate type. | |
Utility class for calculating aggregates for a field (or expression) over the features from a vector layer.
Definition at line 42 of file qgsaggregatecalculator.h.
QgsAggregateCalculator::QgsAggregateCalculator | ( | const QgsVectorLayer * | layer | ) |
Constructor for QgsAggregateCalculator.
layer | vector layer to calculate aggregate from |
Definition at line 30 of file qgsaggregatecalculator.cpp.
|
static |
Structured information for available aggregates.
Definition at line 312 of file qgsaggregatecalculator.cpp.
QVariant QgsAggregateCalculator::calculate | ( | Qgis::Aggregate | aggregate, |
const QString & | fieldOrExpression, | ||
QgsExpressionContext * | context = nullptr , |
||
bool * | ok = nullptr , |
||
QgsFeedback * | feedback = nullptr |
||
) | const |
Calculates the value of an aggregate.
aggregate | aggregate to calculate |
fieldOrExpression | source field or expression to use as basis for aggregated values. If an expression is used, then the context parameter must be set. |
context | expression context for evaluating expressions |
ok | if specified, will be set to true if aggregate calculation was successful. If ok is false then lastError() can be used to retrieve a descriptive error message. |
feedback | optional feedback argument for early cancellation (since QGIS 3.22). If set, this will take precedence over any feedback object set on the expression context. |
Definition at line 54 of file qgsaggregatecalculator.cpp.
|
inline |
Returns the delimiter used for joining values with the StringConcatenate aggregate.
Definition at line 142 of file qgsaggregatecalculator.h.
|
static |
Returns the friendly display name for a aggregate.
Definition at line 260 of file qgsaggregatecalculator.cpp.
|
inline |
Returns the filter which limits the features used during the aggregate calculation.
Definition at line 129 of file qgsaggregatecalculator.h.
|
inline |
Returns the last error encountered during the aggregate calculation.
Definition at line 97 of file qgsaggregatecalculator.h.
const QgsVectorLayer * QgsAggregateCalculator::layer | ( | ) | const |
Returns the associated vector layer.
Definition at line 36 of file qgsaggregatecalculator.cpp.
|
inline |
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
delimiter | string delimiter |
Definition at line 136 of file qgsaggregatecalculator.h.
void QgsAggregateCalculator::setFidsFilter | ( | const QgsFeatureIds & | fids | ) |
Sets a filter to limit the features used during the aggregate calculation.
If an expression filter is set, it will override this filter.
fids | feature ids for feature filtering, and empty list will return no features. |
Definition at line 48 of file qgsaggregatecalculator.cpp.
|
inline |
Sets a filter to limit the features used during the aggregate calculation.
filterExpression | expression for filtering features, or empty string to remove filter |
Definition at line 115 of file qgsaggregatecalculator.h.
void QgsAggregateCalculator::setParameters | ( | const AggregateParameters & | parameters | ) |
Sets all aggregate parameters from a parameter bundle.
parameters | aggregate parameters |
Definition at line 41 of file qgsaggregatecalculator.cpp.
|
static |
Converts a string to a aggregate type.
string | string to convert |
ok | if specified, will be set to true if conversion was successful |
Definition at line 202 of file qgsaggregatecalculator.cpp.