Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix default value expression on double field
  • Loading branch information
github-actions[bot] committed Aug 10, 2020
1 parent b3147bc commit a5cfda4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/core/qgsfield.cpp
Expand Up @@ -252,6 +252,13 @@ QString QgsField::displayString( const QVariant &v ) const
// Special treatment for numeric types if group separator is set or decimalPoint is not a dot
if ( d->type == QVariant::Double )
{
// if value doesn't contain a double (a default value expression for instance),
// apply no transformation
bool ok;
v.toDouble( &ok );
if ( !ok )
return v.toString();

// Locales with decimal point != '.' or that require group separator: use QLocale
if ( QLocale().decimalPoint() != '.' ||
!( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator ) )
Expand Down
3 changes: 3 additions & 0 deletions tests/src/core/testqgsfield.cpp
Expand Up @@ -370,6 +370,9 @@ void TestQgsField::displayString()
QCOMPARE( QLocale().numberOptions() & QLocale::NumberOption::OmitGroupSeparator, QLocale::NumberOption::DefaultNumberOptions );
QCOMPARE( doubleFieldNoPrec.displayString( 599999898999.0 ), QString( "599,999,898,999" ) );

// no conversion when this is default value expression
QCOMPARE( doubleFieldNoPrec.displayString( ( "(1+2)" ) ), QString( "(1+2)" ) );

//test NULL double
QVariant nullDouble = QVariant( QVariant::Double );
QCOMPARE( doubleField.displayString( nullDouble ), QString( "TEST NULL" ) );
Expand Down

0 comments on commit a5cfda4

Please sign in to comment.