41 mFilterExpression = parameters.
filter;
65 context = context ? context : &defaultContext;
67 std::unique_ptr<QgsExpression> expression;
77 if ( expression->hasParserError() || !expression->prepare( context ) )
79 mLastError = !expression->parserErrorString().isEmpty() ? expression->parserErrorString() : expression->evalErrorString();
88 lst = expression->referencedColumns();
90 request.
setFlags( ( expression && expression->needsGeometry() ) ?
98 if ( !mOrderBy.empty() )
101 if ( !mFilterExpression.isEmpty() )
109 QVariant::Type resultType = QVariant::Double;
116 resultType = QVariant::UserType;
121 bool foundFeatures =
false;
123 if ( !foundFeatures )
127 return defaultValue( aggregate );
130 resultType = std::get<0>( returnType );
131 userType = std::get<1>( returnType );
132 if ( resultType == QVariant::Invalid )
176 resultType = v.type();
177 userType = v.userType();
185 return calculate( aggregate, fit, resultType, userType, attrNum, expression.get(), mDelimiter, context, ok, &mLastError );
190 const QString normalized =
string.trimmed().toLower();
195 if ( normalized == QLatin1String(
"count" ) )
197 else if ( normalized == QLatin1String(
"count_distinct" ) )
199 else if ( normalized == QLatin1String(
"count_missing" ) )
201 else if ( normalized == QLatin1String(
"min" ) )
203 else if ( normalized == QLatin1String(
"max" ) )
205 else if ( normalized == QLatin1String(
"sum" ) )
207 else if ( normalized == QLatin1String(
"mean" ) )
209 else if ( normalized == QLatin1String(
"median" ) )
211 else if ( normalized == QLatin1String(
"stdev" ) )
213 else if ( normalized == QLatin1String(
"stdevsample" ) )
215 else if ( normalized == QLatin1String(
"range" ) )
217 else if ( normalized == QLatin1String(
"minority" ) )
219 else if ( normalized == QLatin1String(
"majority" ) )
221 else if ( normalized == QLatin1String(
"q1" ) )
223 else if ( normalized == QLatin1String(
"q3" ) )
225 else if ( normalized == QLatin1String(
"iqr" ) )
227 else if ( normalized == QLatin1String(
"min_length" ) )
229 else if ( normalized == QLatin1String(
"max_length" ) )
231 else if ( normalized == QLatin1String(
"concatenate" ) )
233 else if ( normalized == QLatin1String(
"concatenate_unique" ) )
235 else if ( normalized == QLatin1String(
"collect" ) )
237 else if ( normalized == QLatin1String(
"array_agg" ) )
251 return QObject::tr(
"count" );
253 return QObject::tr(
"count distinct" );
255 return QObject::tr(
"count missing" );
257 return QObject::tr(
"minimum" );
259 return QObject::tr(
"maximum" );
261 return QObject::tr(
"sum" );
263 return QObject::tr(
"mean" );
265 return QObject::tr(
"median" );
267 return QObject::tr(
"standard deviation" );
269 return QObject::tr(
"standard deviation (sample)" );
271 return QObject::tr(
"range" );
273 return QObject::tr(
"minority" );
275 return QObject::tr(
"majority" );
277 return QObject::tr(
"first quartile" );
279 return QObject::tr(
"third quartile" );
281 return QObject::tr(
"inter quartile range" );
283 return QObject::tr(
"minimum length" );
285 return QObject::tr(
"maximum length" );
287 return QObject::tr(
"concatenate" );
289 return QObject::tr(
"collection" );
291 return QObject::tr(
"array aggregate" );
293 return QObject::tr(
"concatenate (unique)" );
304 QStringLiteral(
"count" ),
305 QCoreApplication::tr(
"Count" ),
306 QSet<QVariant::Type>()
307 << QVariant::DateTime
311 << QVariant::LongLong
312 << QVariant::ULongLong
317 QStringLiteral(
"count_distinct" ),
318 QCoreApplication::tr(
"Count Distinct" ),
319 QSet<QVariant::Type>()
320 << QVariant::DateTime
324 << QVariant::LongLong
325 << QVariant::ULongLong
330 QStringLiteral(
"count_missing" ),
331 QCoreApplication::tr(
"Count Missing" ),
332 QSet<QVariant::Type>()
333 << QVariant::DateTime
337 << QVariant::LongLong
342 QStringLiteral(
"min" ),
343 QCoreApplication::tr(
"Min" ),
344 QSet<QVariant::Type>()
345 << QVariant::DateTime
349 << QVariant::LongLong
350 << QVariant::ULongLong
356 QStringLiteral(
"max" ),
357 QCoreApplication::tr(
"Max" ),
358 QSet<QVariant::Type>()
359 << QVariant::DateTime
363 << QVariant::LongLong
364 << QVariant::ULongLong
370 QStringLiteral(
"sum" ),
371 QCoreApplication::tr(
"Sum" ),
372 QSet<QVariant::Type>()
375 << QVariant::LongLong
376 << QVariant::ULongLong
381 QStringLiteral(
"mean" ),
382 QCoreApplication::tr(
"Mean" ),
383 QSet<QVariant::Type>()
386 << QVariant::LongLong
387 << QVariant::ULongLong
392 QStringLiteral(
"median" ),
393 QCoreApplication::tr(
"Median" ),
394 QSet<QVariant::Type>()
401 QStringLiteral(
"stdev" ),
402 QCoreApplication::tr(
"Stdev" ),
403 QSet<QVariant::Type>()
406 << QVariant::LongLong
407 << QVariant::ULongLong
412 QStringLiteral(
"stdevsample" ),
413 QCoreApplication::tr(
"Stdev Sample" ),
414 QSet<QVariant::Type>()
417 << QVariant::LongLong
418 << QVariant::ULongLong
423 QStringLiteral(
"range" ),
424 QCoreApplication::tr(
"Range" ),
425 QSet<QVariant::Type>()
427 << QVariant::DateTime
430 << QVariant::LongLong
431 << QVariant::ULongLong
436 QStringLiteral(
"minority" ),
437 QCoreApplication::tr(
"Minority" ),
438 QSet<QVariant::Type>()
441 << QVariant::LongLong
442 << QVariant::ULongLong
448 QStringLiteral(
"majority" ),
449 QCoreApplication::tr(
"Majority" ),
450 QSet<QVariant::Type>()
453 << QVariant::LongLong
454 << QVariant::ULongLong
460 QStringLiteral(
"q1" ),
461 QCoreApplication::tr(
"Q1" ),
462 QSet<QVariant::Type>()
465 << QVariant::LongLong
466 << QVariant::ULongLong
471 QStringLiteral(
"q3" ),
472 QCoreApplication::tr(
"Q3" ),
473 QSet<QVariant::Type>()
476 << QVariant::LongLong
477 << QVariant::ULongLong
482 QStringLiteral(
"iqr" ),
483 QCoreApplication::tr(
"InterQuartileRange" ),
484 QSet<QVariant::Type>()
487 << QVariant::LongLong
488 << QVariant::ULongLong
493 QStringLiteral(
"min_length" ),
494 QCoreApplication::tr(
"Min Length" ),
495 QSet<QVariant::Type>()
500 QStringLiteral(
"max_length" ),
501 QCoreApplication::tr(
"Max Length" ),
502 QSet<QVariant::Type>()
507 QStringLiteral(
"concatenate" ),
508 QCoreApplication::tr(
"Concatenate" ),
509 QSet<QVariant::Type>()
514 QStringLiteral(
"collect" ),
515 QCoreApplication::tr(
"Collect" ),
516 QSet<QVariant::Type>()
520 QStringLiteral(
"array_agg" ),
521 QCoreApplication::tr(
"Array Aggregate" ),
522 QSet<QVariant::Type>()
538 return calculateArrayAggregate( fit, attr, expression, context );
541 switch ( resultType )
545 case QVariant::LongLong:
546 case QVariant::ULongLong:
547 case QVariant::Double:
554 *error = expression ? QObject::tr(
"Cannot calculate %1 on numeric values" ).arg(
displayName( aggregate ) )
555 : QObject::tr(
"Cannot calculate %1 on numeric fields" ).arg(
displayName( aggregate ) );
561 return calculateNumericAggregate( fit, attr, expression, context, stat );
565 case QVariant::DateTime:
572 *error = ( expression ? QObject::tr(
"Cannot calculate %1 on %2 values" ).arg(
displayName( aggregate ) ) :
573 QObject::tr(
"Cannot calculate %1 on %2 fields" ).arg(
displayName( aggregate ) ) ).arg( resultType == QVariant::Date ? QObject::tr(
"date" ) : QObject::tr(
"datetime" ) );
579 return calculateDateTimeAggregate( fit, attr, expression, context, stat );
582 case QVariant::UserType:
588 return calculateGeometryAggregate( fit, expression, context );
604 return concatenateStrings( fit, attr, expression, context,
delimiter );
611 return concatenateStrings( fit, attr, expression, context,
delimiter,
true );
619 if ( resultType == QVariant::Invalid )
620 typeString = QObject::tr(
"null" );
621 else if ( resultType == QVariant::UserType )
624 typeString = resultType == QVariant::String ? QObject::tr(
"string" ) : QVariant::typeToName( resultType );
627 *error = expression ? QObject::tr(
"Cannot calculate %1 on %3 values" ).arg(
displayName( aggregate ), typeString )
628 : QObject::tr(
"Cannot calculate %1 on %3 fields" ).arg(
displayName( aggregate ), typeString );
634 return calculateStringAggregate( fit, attr, expression, context, stat );
802 Q_ASSERT( expression || attr >= 0 );
813 const QVariant v = expression->
evaluate( context );
822 const double val = s.statistic( stat );
823 return std::isnan( val ) ? QVariant() : val;
829 Q_ASSERT( expression || attr >= 0 );
840 const QVariant v = expression->
evaluate( context );
849 return s.statistic( stat );
854 Q_ASSERT( expression );
857 QVector< QgsGeometry > geometries;
862 const QVariant v = expression->
evaluate( context );
875 Q_ASSERT( expression || attr >= 0 );
886 const QVariant v = expression->
evaluate( context );
887 result = v.toString();
894 if ( !unique || !results.contains( result ) )
917 return QVariantList();
944 Q_ASSERT( expression || attr >= 0 );
955 const QVariant v = expression->
evaluate( context );
964 return s.statistic( stat );
970 Q_ASSERT( expression || attr >= 0 );
982 const QVariant v = expression->
evaluate( context );