QGIS API Documentation 3.37.0-Master (fdefdf9c27f)
Classes | Public Member Functions | Static Public Member Functions | List of all members
QgsAggregateCalculator Class Reference

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. More...
 
QVariant calculate (Qgis::Aggregate aggregate, const QString &fieldOrExpression, QgsExpressionContext *context=nullptr, bool *ok=nullptr, QgsFeedback *feedback=nullptr) const
 Calculates the value of an aggregate. More...
 
QString delimiter () const
 Returns the delimiter used for joining values with the StringConcatenate aggregate. More...
 
QString filter () const
 Returns the filter which limits the features used during the aggregate calculation. More...
 
QString lastError () const
 Returns the last error encountered during the aggregate calculation. More...
 
const QgsVectorLayerlayer () const
 Returns the associated vector layer. More...
 
void setDelimiter (const QString &delimiter)
 Sets the delimiter to use for joining values with the StringConcatenate aggregate. More...
 
void setFidsFilter (const QgsFeatureIds &fids)
 Sets a filter to limit the features used during the aggregate calculation. More...
 
void setFilter (const QString &filterExpression)
 Sets a filter to limit the features used during the aggregate calculation. More...
 
void setParameters (const AggregateParameters &parameters)
 Sets all aggregate parameters from a parameter bundle. More...
 

Static Public Member Functions

static QList< QgsAggregateCalculator::AggregateInfoaggregates ()
 Structured information for available aggregates. More...
 
static QString displayName (Qgis::Aggregate aggregate)
 Returns the friendly display name for a aggregate. More...
 
static Qgis::Aggregate stringToAggregate (const QString &string, bool *ok=nullptr)
 Converts a string to a aggregate type. More...
 

Detailed Description

Utility class for calculating aggregates for a field (or expression) over the features from a vector layer.

It is recommended that QgsVectorLayer::aggregate() is used rather then directly using this class, as the QgsVectorLayer method can handle delegating aggregate calculation to a data provider for remote calculation.

Definition at line 41 of file qgsaggregatecalculator.h.

Constructor & Destructor Documentation

◆ QgsAggregateCalculator()

QgsAggregateCalculator::QgsAggregateCalculator ( const QgsVectorLayer layer)

Constructor for QgsAggregateCalculator.

Parameters
layervector layer to calculate aggregate from

Definition at line 30 of file qgsaggregatecalculator.cpp.

Member Function Documentation

◆ aggregates()

QList< QgsAggregateCalculator::AggregateInfo > QgsAggregateCalculator::aggregates ( )
static

Structured information for available aggregates.

Since
QGIS 3.2

Definition at line 312 of file qgsaggregatecalculator.cpp.

◆ calculate()

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.

Parameters
aggregateaggregate to calculate
fieldOrExpressionsource field or expression to use as basis for aggregated values. If an expression is used, then the context parameter must be set.
contextexpression context for evaluating expressions
okif 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.
feedbackoptional feedback argument for early cancellation (since QGIS 3.22). If set, this will take precedence over any feedback object set on the expression context.
Returns
calculated aggregate value

Definition at line 54 of file qgsaggregatecalculator.cpp.

◆ delimiter()

QString QgsAggregateCalculator::delimiter ( ) const
inline

Returns the delimiter used for joining values with the StringConcatenate aggregate.

See also
setDelimiter()

Definition at line 141 of file qgsaggregatecalculator.h.

◆ displayName()

QString QgsAggregateCalculator::displayName ( Qgis::Aggregate  aggregate)
static

Returns the friendly display name for a aggregate.

Since
QGIS 3.22

Definition at line 260 of file qgsaggregatecalculator.cpp.

◆ filter()

QString QgsAggregateCalculator::filter ( ) const
inline

Returns the filter which limits the features used during the aggregate calculation.

See also
setFilter()

Definition at line 128 of file qgsaggregatecalculator.h.

◆ lastError()

QString QgsAggregateCalculator::lastError ( ) const
inline

Returns the last error encountered during the aggregate calculation.

Since
QGIS 3.22

Definition at line 96 of file qgsaggregatecalculator.h.

◆ layer()

const QgsVectorLayer * QgsAggregateCalculator::layer ( ) const

Returns the associated vector layer.

Definition at line 36 of file qgsaggregatecalculator.cpp.

◆ setDelimiter()

void QgsAggregateCalculator::setDelimiter ( const QString &  delimiter)
inline

Sets the delimiter to use for joining values with the StringConcatenate aggregate.

Parameters
delimiterstring delimiter
See also
delimiter()

Definition at line 135 of file qgsaggregatecalculator.h.

◆ setFidsFilter()

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.

Parameters
fidsfeature ids for feature filtering, and empty list will return no features.
See also
filter()

Definition at line 48 of file qgsaggregatecalculator.cpp.

◆ setFilter()

void QgsAggregateCalculator::setFilter ( const QString &  filterExpression)
inline

Sets a filter to limit the features used during the aggregate calculation.

Parameters
filterExpressionexpression for filtering features, or empty string to remove filter
See also
filter()

Definition at line 114 of file qgsaggregatecalculator.h.

◆ setParameters()

void QgsAggregateCalculator::setParameters ( const AggregateParameters parameters)

Sets all aggregate parameters from a parameter bundle.

Parameters
parametersaggregate parameters

Definition at line 41 of file qgsaggregatecalculator.cpp.

◆ stringToAggregate()

Qgis::Aggregate QgsAggregateCalculator::stringToAggregate ( const QString &  string,
bool *  ok = nullptr 
)
static

Converts a string to a aggregate type.

Parameters
stringstring to convert
okif specified, will be set to true if conversion was successful
Returns
aggregate type

Definition at line 202 of file qgsaggregatecalculator.cpp.


The documentation for this class was generated from the following files: