Skip to content
Permalink
Browse files

[needs-docs] Update min and max functions

In case of a null value, these functions will not always return null
  • Loading branch information
DelazJ authored and m-kuhn committed Dec 27, 2017
1 parent e552b9b commit 97caa005d9747920042459e050d8503fab535afe
Showing with 28 additions and 16 deletions.
  1. +28 −16 src/core/expression/qgsexpressionfunction.cpp
@@ -415,38 +415,50 @@ static QVariant fcnExpScale( const QVariantList &values, const QgsExpressionCont

static QVariant fcnMax( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
//initially set max as first value
double maxVal = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );

//check against all other values
for ( int i = 1; i < values.length(); ++i )
QVariant result;
double maxVal = std::numeric_limits<double>::quiet_NaN();
for ( const QVariant &val : values )
{
double testVal = QgsExpressionUtils::getDoubleValue( values[i], parent );
if ( testVal > maxVal )
double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
if ( std::isnan( maxVal ) )
{
maxVal = testVal;
}
else if ( !std::isnan( testVal ) )
{
maxVal = std::max( maxVal, testVal );
}
}

return QVariant( maxVal );
if ( !std::isnan( maxVal ) )
{
result = QVariant( maxVal );
}
return result;
}

static QVariant fcnMin( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
{
//initially set min as first value
double minVal = QgsExpressionUtils::getDoubleValue( values.at( 0 ), parent );

//check against all other values
for ( int i = 1; i < values.length(); ++i )
QVariant result;
double minVal = std::numeric_limits<double>::quiet_NaN();
for ( const QVariant &val : values )
{
double testVal = QgsExpressionUtils::getDoubleValue( values[i], parent );
if ( testVal < minVal )
double testVal = val.isNull() ? std::numeric_limits<double>::quiet_NaN() : QgsExpressionUtils::getDoubleValue( val, parent );
if ( std::isnan( minVal ) )
{
minVal = testVal;
}
else if ( !std::isnan( testVal ) )
{
minVal = std::min( minVal, testVal );
}
}

return QVariant( minVal );
if ( !std::isnan( minVal ) )
{
result = QVariant( minVal );
}
return result;
}

static QVariant fcnAggregate( const QVariantList &values, const QgsExpressionContext *context, QgsExpression *parent, const QgsExpressionNodeFunction * )

0 comments on commit 97caa00

Please sign in to comment.
You can’t perform that action at this time.