QGIS API Documentation 3.39.0-Master (67e056379ed)
Loading...
Searching...
No Matches
qgsaggregatecalculator.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsaggregatecalculator.h
3 ------------------------
4 begin : May 2016
5 copyright : (C) 2016 by Nyall Dawson
6 email : nyall dot dawson at gmail dot com
7 ***************************************************************************/
8
9/***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18#ifndef QGSAGGREGATECALCULATOR_H
19#define QGSAGGREGATECALCULATOR_H
20
21#include "qgis_core.h"
23#include "qgsfeaturerequest.h"
24#include <QVariant>
25#include "qgsfeatureid.h"
26
27
29class QgsExpression;
30class QgsVectorLayer;
32
41class CORE_EXPORT QgsAggregateCalculator
42{
43 public:
44
50 {
52 QString function;
54 QString name;
56 QSet<QMetaType::Type> supportedTypes;
57 };
58
84
90
96 QString lastError() const { return mLastError; }
97
101 const QgsVectorLayer *layer() const;
102
107 void setParameters( const AggregateParameters &parameters );
108
114 void setFilter( const QString &filterExpression ) { mFilterExpression = filterExpression; }
115
122 void setFidsFilter( const QgsFeatureIds &fids );
123
128 QString filter() const { return mFilterExpression; }
129
135 void setDelimiter( const QString &delimiter ) { mDelimiter = delimiter; }
136
141 QString delimiter() const { return mDelimiter; }
142
154 QVariant calculate( Qgis::Aggregate aggregate, const QString &fieldOrExpression,
155 QgsExpressionContext *context = nullptr, bool *ok = nullptr, QgsFeedback *feedback = nullptr ) const;
156
163 static Qgis::Aggregate stringToAggregate( const QString &string, bool *ok = nullptr );
164
169 static QString displayName( Qgis::Aggregate aggregate );
170
176 static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
177
178 private:
179
181 const QgsVectorLayer *mLayer = nullptr;
182
184 QString mFilterExpression;
185
188
190 QString mDelimiter;
191
193 QgsFeatureIds mFidsFilter;
194
195 //trigger variable
196 bool mFidsSet = false;
197
198 mutable QString mLastError;
199
200 static Qgis::Statistic numericStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
201 static Qgis::StringStatistic stringStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
202 static Qgis::DateTimeStatistic dateTimeStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
203
204 static QVariant calculateNumericAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
205 QgsExpressionContext *context, Qgis::Statistic stat );
206
207 static QVariant calculateStringAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
209
210 static QVariant calculateDateTimeAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
212 static QVariant calculateGeometryAggregate( QgsFeatureIterator &fit, QgsExpression *expression, QgsExpressionContext *context );
213
214 static QVariant calculateArrayAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
215 QgsExpressionContext *context );
216
217 static QVariant calculate( Qgis::Aggregate aggregate, QgsFeatureIterator &fit, QMetaType::Type resultType, int userType,
218 int attr, QgsExpression *expression,
219 const QString &delimiter,
220 QgsExpressionContext *context, bool *ok = nullptr, QString *error = nullptr );
221 static QVariant concatenateStrings( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
222 QgsExpressionContext *context, const QString &delimiter, bool unique = false );
223
224 QVariant defaultValue( Qgis::Aggregate aggregate ) const;
225};
226
227#endif //QGSAGGREGATECALCULATOR_H
Statistic
Available generic statistics.
Definition qgis.h:5001
StringStatistic
Available string statistics.
Definition qgis.h:5063
Aggregate
Available aggregates to calculate.
Definition qgis.h:4969
DateTimeStatistic
Available date/time statistics.
Definition qgis.h:5038
Utility class for calculating aggregates for a field (or expression) over the features from a vector ...
void setFilter(const QString &filterExpression)
Sets a filter to limit the features used during the aggregate calculation.
void setDelimiter(const QString &delimiter)
Sets the delimiter to use for joining values with the StringConcatenate aggregate.
QString lastError() const
Returns the last error encountered during the aggregate calculation.
QString filter() const
Returns the filter which limits the features used during the aggregate calculation.
QString delimiter() const
Returns the delimiter used for joining values with the StringConcatenate aggregate.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Class for parsing and evaluation of expressions (formerly called "search strings").
Wrapper for iterator of features from vector data provider or vector layer.
Represents a list of OrderByClauses, with the most important first and the least important last.
Base class for feedback objects to be used for cancellation of something running in a worker thread.
Definition qgsfeedback.h:44
Represents a vector layer which manages a vector based data sets.
QSet< QgsFeatureId > QgsFeatureIds
Structured information about the available aggregates.
QString name
A translated, human readable name.
QString function
The expression function.
QSet< QMetaType::Type > supportedTypes
This aggregate function can only be used with these datatypes.
A bundle of parameters controlling aggregate calculation.
QString filter
Optional filter for calculating aggregate over a subset of features, or an empty string to use all fe...
QString delimiter
Delimiter to use for joining values with the StringConcatenate aggregate.
QgsFeatureRequest::OrderBy orderBy
Optional order by clauses.