QGIS API Documentation 4.1.0-Master (60fea48833c)
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"
22#include "qgsfeatureid.h"
23#include "qgsfeaturerequest.h"
25
26#include <QVariant>
27
29class QgsExpression;
30class QgsVectorLayer;
32
42class CORE_EXPORT QgsAggregateCalculator
43{
44 public:
50 {
52 QString function;
54 QString name;
56 QSet<QMetaType::Type> supportedTypes;
57 };
58
83
89
95 QString lastError() const { return mLastError; }
96
100 const QgsVectorLayer *layer() const;
101
106 void setParameters( const AggregateParameters &parameters );
107
113 void setFilter( const QString &filterExpression ) { mFilterExpression = filterExpression; }
114
121 void setFidsFilter( const QgsFeatureIds &fids );
122
127 QString filter() const { return mFilterExpression; }
128
134 void setDelimiter( const QString &delimiter ) { mDelimiter = delimiter; }
135
140 QString delimiter() const { return mDelimiter; }
141
153 QVariant calculate( Qgis::Aggregate aggregate, const QString &fieldOrExpression, QgsExpressionContext *context = nullptr, bool *ok = nullptr, QgsFeedback *feedback = nullptr ) const;
154
161 static Qgis::Aggregate stringToAggregate( const QString &string, bool *ok = nullptr );
162
167 static QString displayName( Qgis::Aggregate aggregate );
168
174 static QList< QgsAggregateCalculator::AggregateInfo > aggregates();
175
176 private:
178 const QgsVectorLayer *mLayer = nullptr;
179
181 QString mFilterExpression;
182
185
187 QString mDelimiter;
188
190 QgsFeatureIds mFidsFilter;
191
192 //trigger variable
193 bool mFidsSet = false;
194
195 mutable QString mLastError;
196
197 static Qgis::Statistic numericStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
198 static Qgis::StringStatistic stringStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
199 static Qgis::DateTimeStatistic dateTimeStatFromAggregate( Qgis::Aggregate aggregate, bool *ok = nullptr );
200
201 static QVariant calculateNumericAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression, QgsExpressionContext *context, Qgis::Statistic stat );
202
203 static QVariant calculateStringAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression, QgsExpressionContext *context, Qgis::StringStatistic stat );
204
205 static QVariant calculateDateTimeAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression, QgsExpressionContext *context, Qgis::DateTimeStatistic stat );
206 static QVariant calculateGeometryAggregate( QgsFeatureIterator &fit, QgsExpression *expression, QgsExpressionContext *context );
207
208 static QVariant calculateArrayAggregate( QgsFeatureIterator &fit, int attr, QgsExpression *expression, QgsExpressionContext *context );
209
210 static QVariant calculate(
211 Qgis::Aggregate aggregate,
213 QMetaType::Type resultType,
214 int attr,
215 QgsExpression *expression,
216 const QString &delimiter,
217 QgsExpressionContext *context,
218 bool *ok = nullptr,
219 QString *error = nullptr
220 );
221 static QVariant concatenateStrings( QgsFeatureIterator &fit, int attr, QgsExpression *expression, QgsExpressionContext *context, const QString &delimiter, bool unique = false );
222
223 QVariant defaultValue( Qgis::Aggregate aggregate ) const;
224};
225
226#endif //QGSAGGREGATECALCULATOR_H
Statistic
Available generic statistics.
Definition qgis.h:6206
StringStatistic
Available string statistics.
Definition qgis.h:6268
Aggregate
Available aggregates to calculate.
Definition qgis.h:6174
DateTimeStatistic
Available date/time statistics.
Definition qgis.h:6243
void setFilter(const QString &filterExpression)
Sets a filter to limit the features used 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.
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.
QgsAggregateCalculator(const QgsVectorLayer *layer)
Constructor for QgsAggregateCalculator.
Expression contexts are used to encapsulate the parameters around which a QgsExpression should be eva...
Handles 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 dataset.
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.