@@ -4364,29 +4364,27 @@ static QVariant fcnPi( const QVariantList &values, const QgsExpressionContext *,
4364
4364
4365
4365
static QVariant fcnFormatNumber ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
4366
4366
{
4367
- double value = QgsExpressionUtils::getDoubleValue ( values.at ( 0 ), parent );
4368
- int places = QgsExpressionUtils::getNativeIntValue ( values.at ( 1 ), parent );
4367
+ const double value = QgsExpressionUtils::getDoubleValue ( values.at ( 0 ), parent );
4368
+ const int places = QgsExpressionUtils::getNativeIntValue ( values.at ( 1 ), parent );
4369
+ const QString language = QgsExpressionUtils::getStringValue ( values.at ( 2 ), parent );
4369
4370
if ( places < 0 )
4370
4371
{
4371
4372
parent->setEvalErrorString ( QObject::tr ( " Number of places must be positive" ) );
4372
4373
return QVariant ();
4373
4374
}
4374
- QLocale locale = QLocale ();
4375
+
4376
+ QLocale locale = !language.isEmpty () ? QLocale ( language ) : QLocale ();
4375
4377
locale.setNumberOptions ( locale.numberOptions () &= ~QLocale::NumberOption::OmitGroupSeparator );
4376
4378
return locale.toString ( value, ' f' , places );
4377
4379
}
4378
4380
4379
4381
static QVariant fcnFormatDate ( const QVariantList &values, const QgsExpressionContext *, QgsExpression *parent, const QgsExpressionNodeFunction * )
4380
4382
{
4381
- QDateTime datetime = QgsExpressionUtils::getDateTimeValue ( values.at ( 0 ), parent );
4382
- QString format = QgsExpressionUtils::getStringValue ( values.at ( 1 ), parent );
4383
- QString language = QgsExpressionUtils::getStringValue ( values.at ( 2 ), parent );
4383
+ const QDateTime datetime = QgsExpressionUtils::getDateTimeValue ( values.at ( 0 ), parent );
4384
+ const QString format = QgsExpressionUtils::getStringValue ( values.at ( 1 ), parent );
4385
+ const QString language = QgsExpressionUtils::getStringValue ( values.at ( 2 ), parent );
4384
4386
4385
- QLocale locale = QLocale ();
4386
- if ( !language.isEmpty () )
4387
- {
4388
- locale = QLocale ( language );
4389
- }
4387
+ QLocale locale = !language.isEmpty () ? QLocale ( language ) : QLocale ();
4390
4388
return locale.toString ( datetime, format );
4391
4389
}
4392
4390
@@ -5879,7 +5877,7 @@ const QList<QgsExpressionFunction *> &QgsExpression::Functions()
5879
5877
<< new QgsStaticExpressionFunction ( QStringLiteral ( " rpad" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " width" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " fill" ) ), fcnRPad, QStringLiteral ( " String" ) )
5880
5878
<< new QgsStaticExpressionFunction ( QStringLiteral ( " lpad" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " string" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " width" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " fill" ) ), fcnLPad, QStringLiteral ( " String" ) )
5881
5879
<< new QgsStaticExpressionFunction ( QStringLiteral ( " format" ), -1 , fcnFormatString, QStringLiteral ( " String" ) )
5882
- << new QgsStaticExpressionFunction ( QStringLiteral ( " format_number" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " number" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " places" ) ), fcnFormatNumber, QStringLiteral ( " String" ) )
5880
+ << new QgsStaticExpressionFunction ( QStringLiteral ( " format_number" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " number" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " places" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " language " ), true , QVariant () ) , fcnFormatNumber, QStringLiteral ( " String" ) )
5883
5881
<< new QgsStaticExpressionFunction ( QStringLiteral ( " format_date" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " datetime" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " format" ) ) << QgsExpressionFunction::Parameter ( QStringLiteral ( " language" ), true , QVariant () ), fcnFormatDate, QStringList () << QStringLiteral ( " String" ) << QStringLiteral ( " Date and Time" ) )
5884
5882
<< new QgsStaticExpressionFunction ( QStringLiteral ( " color_grayscale_average" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " color" ) ), fcnColorGrayscaleAverage, QStringLiteral ( " Color" ) )
5885
5883
<< new QgsStaticExpressionFunction ( QStringLiteral ( " color_mix_rgb" ), QgsExpressionFunction::ParameterList () << QgsExpressionFunction::Parameter ( QStringLiteral ( " color1" ) )
0 commit comments