Skip to content
Permalink
Browse files
Remove duplicated code for localized numbers
Followup #43681
  • Loading branch information
elpaso authored and nyalldawson committed Jun 21, 2021
1 parent 479173d commit 4ff006421191788e0c94598c8f9626591a4a6043
Showing with 9 additions and 36 deletions.
  1. +9 −36 src/core/expression/qgsexpression.cpp
@@ -23,6 +23,7 @@
#include "qgsgeometry.h"
#include "qgsproject.h"
#include "qgsexpressioncontextutils.h"
#include "qgsexpressionutils.h"
#include "qgsexpression_p.h"

#include <QRegularExpression>
@@ -1085,43 +1086,15 @@ QString QgsExpression::formatPreviewString( const QVariant &value, const bool ht
listStr += QLatin1Char( ']' );
return listStr;
}
else if ( value.type() == QVariant::Int || value.type() == QVariant::UInt || value.type() == QVariant::LongLong || value.type() == QVariant::ULongLong )
else if ( value.type() == QVariant::Int ||
value.type() == QVariant::UInt ||
value.type() == QVariant::LongLong ||
value.type() == QVariant::ULongLong ||
value.type() == QVariant::Double ||
// Qt madness with QMetaType::Float :/
value.type() == static_cast<QVariant::Type>( QMetaType::Float ) )
{
bool ok;
QString res;

if ( value.type() == QVariant::ULongLong )
{
res = QLocale().toString( value.toULongLong( &ok ) );
}
else
{
res = QLocale().toString( value.toLongLong( &ok ) );
}

if ( ok )
{
return res;
}
else
{
return value.toString();
}
}
// Qt madness with QMetaType::Float :/
else if ( value.type() == QVariant::Double || value.type() == static_cast<QVariant::Type>( QMetaType::Float ) )
{
bool ok;
const QString res { QLocale().toString( value.toDouble( &ok ), 'f', 6 ) };

if ( ok )
{
return res;
}
else
{
return value.toString();
}
return QgsExpressionUtils::toLocalizedString( value );
}
else
{

0 comments on commit 4ff0064

Please sign in to comment.