Skip to content
Permalink
Browse files
Responsive cancelation of aggregate expression functions
  • Loading branch information
nyalldawson committed Jun 18, 2021
1 parent d5708c2 commit 11e88f7e922224fa0e95360defc5afa345774e50
@@ -132,7 +132,7 @@ Returns the delimiter used for joining values with the StringConcatenate aggrega
%End

QVariant calculate( Aggregate aggregate, const QString &fieldOrExpression,
QgsExpressionContext *context = 0, bool *ok = 0 ) const;
QgsExpressionContext *context = 0, bool *ok = 0, QgsFeedback *feedback = 0 ) const;
%Docstring
Calculates the value of an aggregate.

@@ -141,6 +141,7 @@ Calculates the value of an aggregate.
If an expression is used, then the context parameter must be set.
:param context: expression context for evaluating expressions
:param ok: if specified, will be set to ``True`` if aggregate calculation was successful
:param feedback: optional feedback argument for early cancellation (since QGIS 3.22)

:return: calculated aggregate value
%End
@@ -2458,7 +2458,8 @@ and maximum values are required.
const QgsAggregateCalculator::AggregateParameters &parameters = QgsAggregateCalculator::AggregateParameters(),
QgsExpressionContext *context = 0,
bool *ok = 0,
QgsFeatureIds *fids = 0 ) const;
QgsFeatureIds *fids = 0,
QgsFeedback *feedback = 0 ) const;
%Docstring
Calculates an aggregated value from the layer's features.
Currently any filtering expression provided will override filters in the FeatureRequest.
@@ -2469,6 +2470,7 @@ Currently any filtering expression provided will override filters in the Feature
:param context: expression context for expressions and filters
:param ok: if specified, will be set to ``True`` if aggregate calculation was successful
:param fids: list of fids to filter, otherwise will use all fids
:param feedback: optional feedback argument for early cancellation (since QGIS 3.22)

:return: calculated aggregate value

@@ -685,13 +685,13 @@ static QVariant fcnAggregate( const QVariantList &values, const QgsExpressionCon
QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subScope->setVariable( QStringLiteral( "parent" ), context->feature() );
subContext.appendScope( subScope );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context ? context->feedback() : nullptr );

context->setCachedValue( cacheKey, result );
}
else
{
result = vl->aggregate( aggregate, subExpression, parameters, nullptr, &ok );
result = vl->aggregate( aggregate, subExpression, parameters, nullptr, &ok, nullptr, context ? context->feedback() : nullptr );
}
if ( !ok )
{
@@ -807,7 +807,7 @@ static QVariant fcnAggregateRelation( const QVariantList &values, const QgsExpre


QgsExpressionContext subContext( *context );
result = childLayer->aggregate( aggregate, subExpression, parameters, &subContext, &ok );
result = childLayer->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback() );

if ( !ok )
{
@@ -931,7 +931,7 @@ static QVariant fcnAggregateGeneric( QgsAggregateCalculator::Aggregate aggregate
QgsExpressionContextScope *subScope = new QgsExpressionContextScope();
subScope->setVariable( QStringLiteral( "parent" ), context->feature() );
subContext.appendScope( subScope );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok );
result = vl->aggregate( aggregate, subExpression, parameters, &subContext, &ok, nullptr, context->feedback() );

if ( !ok )
{
@@ -49,7 +49,7 @@ void QgsAggregateCalculator::setFidsFilter( const QgsFeatureIds &fids )
}

QVariant QgsAggregateCalculator::calculate( QgsAggregateCalculator::Aggregate aggregate,
const QString &fieldOrExpression, QgsExpressionContext *context, bool *ok ) const
const QString &fieldOrExpression, QgsExpressionContext *context, bool *ok, QgsFeedback *feedback ) const
{
if ( ok )
*ok = false;
@@ -98,6 +98,9 @@ QVariant QgsAggregateCalculator::calculate( QgsAggregateCalculator::Aggregate ag
request.setFilterExpression( mFilterExpression );
if ( context )
request.setExpressionContext( *context );

request.setFeedback( feedback ? feedback : ( context ? context->feedback() : nullptr ) );

//determine result type
QVariant::Type resultType = QVariant::Double;
if ( attrNum == -1 )
@@ -171,10 +171,11 @@ class CORE_EXPORT QgsAggregateCalculator
* If an expression is used, then the context parameter must be set.
* \param context expression context for evaluating expressions
* \param ok if specified, will be set to TRUE if aggregate calculation was successful
* \param feedback optional feedback argument for early cancellation (since QGIS 3.22)
* \returns calculated aggregate value
*/
QVariant calculate( Aggregate aggregate, const QString &fieldOrExpression,
QgsExpressionContext *context = nullptr, bool *ok = nullptr ) const;
QgsExpressionContext *context = nullptr, bool *ok = nullptr, QgsFeedback *feedback = nullptr ) const;

/**
* Converts a string to a aggregate type.
@@ -4428,7 +4428,7 @@ void QgsVectorLayer::minimumOrMaximumValue( int index, QVariant *minimum, QVaria

QVariant QgsVectorLayer::aggregate( QgsAggregateCalculator::Aggregate aggregate, const QString &fieldOrExpression,
const QgsAggregateCalculator::AggregateParameters &parameters, QgsExpressionContext *context,
bool *ok, QgsFeatureIds *fids ) const
bool *ok, QgsFeatureIds *fids, QgsFeedback *feedback ) const
{
if ( ok )
*ok = false;
@@ -4464,7 +4464,7 @@ QVariant QgsVectorLayer::aggregate( QgsAggregateCalculator::Aggregate aggregate,
if ( fids )
c.setFidsFilter( *fids );
c.setParameters( parameters );
return c.calculate( aggregate, fieldOrExpression, context, ok );
return c.calculate( aggregate, fieldOrExpression, context, ok, feedback );
}

void QgsVectorLayer::setFeatureBlendMode( QPainter::CompositionMode featureBlendMode )
@@ -2272,6 +2272,7 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
* \param context expression context for expressions and filters
* \param ok if specified, will be set to TRUE if aggregate calculation was successful
* \param fids list of fids to filter, otherwise will use all fids
* \param feedback optional feedback argument for early cancellation (since QGIS 3.22)
* \returns calculated aggregate value
* \since QGIS 2.16
*/
@@ -2280,7 +2281,8 @@ class CORE_EXPORT QgsVectorLayer : public QgsMapLayer, public QgsExpressionConte
const QgsAggregateCalculator::AggregateParameters &parameters = QgsAggregateCalculator::AggregateParameters(),
QgsExpressionContext *context = nullptr,
bool *ok = nullptr,
QgsFeatureIds *fids = nullptr ) const;
QgsFeatureIds *fids = nullptr,
QgsFeedback *feedback = nullptr ) const;

//! Sets the blending mode used for rendering each feature
void setFeatureBlendMode( QPainter::CompositionMode blendMode );

0 comments on commit 11e88f7

Please sign in to comment.