QGIS API Documentation 3.41.0-Master (af5edcb665c)
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
42class CORE_EXPORT QgsAggregateCalculator
43{
44 public:
45
51 {
53 QString function;
55 QString name;
57 QSet<QMetaType::Type> supportedTypes;
58 };
59
85
91
97 QString lastError() const { return mLastError; }
98
102 const QgsVectorLayer *layer() const;
103
108 void setParameters( const AggregateParameters &parameters );
109
115 void setFilter( const QString &filterExpression ) { mFilterExpression = filterExpression; }
116
123 void setFidsFilter( const QgsFeatureIds &fids );
124
129 QString filter() const { return mFilterExpression; }
130
136 void setDelimiter( const QString &delimiter ) { mDelimiter = delimiter; }
137
142 QString delimiter() const { return mDelimiter; }
143
155 QVariant calculate( Qgis::Aggregate aggregate, const QString &fieldOrExpression,
156 QgsExpressionContext *context = nullptr, bool *ok = nullptr, QgsFeedback *feedback = nullptr ) const;
157
164 static Qgis::Aggregate stringToAggregate( const QString &string, bool *ok = nullptr );
165
170 static QString displayName( Qgis::Aggregate aggregate );
171
177 static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
178
179 private:
180
182 const QgsVectorLayer *mLayer = nullptr;
183
185 QString mFilterExpression;
186
189
191 QString mDelimiter;
192
194 QgsFeatureIds mFidsFilter;
195
196 //trigger variable
197 bool mFidsSet = false;
198
199 mutable QString mLastError;
200
201 static Qgis::Statistic numericStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
202 static Qgis::StringStatistic stringStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
203 static Qgis::DateTimeStatistic dateTimeStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
204
205 static QVariant calculateNumericAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
206 QgsExpressionContext *context, Qgis::Statistic stat );
207
208 static QVariant calculateStringAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
210
211 static QVariant calculateDateTimeAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
213 static QVariant calculateGeometryAggregate( QgsFeatureIterator &fit, QgsExpression *expression, QgsExpressionContext *context );
214
215 static QVariant calculateArrayAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
216 QgsExpressionContext *context );
217
218 static QVariant calculate( Qgis::Aggregate aggregate, QgsFeatureIterator &fit, QMetaType::Type resultType, int userType,
219 int attr, QgsExpression *expression,
220 const QString &delimiter,
221 QgsExpressionContext *context, bool *ok = nullptr, QString *error = nullptr );
222 static QVariant concatenateStrings( QgsFeatureIterator &fit, int attr, QgsExpression *expression,
223 QgsExpressionContext *context, const QString &delimiter, bool unique = false );
224
225 QVariant defaultValue( Qgis::Aggregate aggregate ) const;
226};
227
228#endif //QGSAGGREGATECALCULATOR_H
Statistic
Available generic statistics.
Definition qgis.h:5509
StringStatistic
Available string statistics.
Definition qgis.h:5571
Aggregate
Available aggregates to calculate.
Definition qgis.h:5477
DateTimeStatistic
Available date/time statistics.
Definition qgis.h:5546
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.