mirror of
https://github.com/qgis/QGIS.git
synced 2025-03-01 00:46:20 -05:00
Fields: be permissive when parsing formatted numbers
This commit is contained in:
parent
ba4fb65072
commit
0b35147a92
@ -285,8 +285,8 @@ bool QgsField::convertCompatible( QVariant &v ) const
|
||||
if ( !tmp.convert( d->type ) )
|
||||
{
|
||||
// This might be a string with thousand separator: use locale to convert
|
||||
bool ok;
|
||||
double d = QLocale().toDouble( v.toString(), &ok );
|
||||
bool ok = false;
|
||||
double d = qgsPermissiveToDouble( v.toString(), ok );
|
||||
if ( ok )
|
||||
{
|
||||
v = QVariant( d );
|
||||
@ -295,7 +295,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
|
||||
// For not 'dot' locales, we also want to accept '.'
|
||||
if ( QLocale().decimalPoint() != '.' )
|
||||
{
|
||||
d = QLocale( QLocale::English ).toDouble( v.toString(), &ok );
|
||||
d = QLocale( QLocale::C ).toDouble( v.toString(), &ok );
|
||||
if ( ok )
|
||||
{
|
||||
v = QVariant( d );
|
||||
@ -313,7 +313,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
|
||||
{
|
||||
// This might be a string with thousand separator: use locale to convert
|
||||
bool ok;
|
||||
int i = QLocale().toInt( v.toString(), &ok );
|
||||
int i = qgsPermissiveToInt( v.toString(), ok );
|
||||
if ( ok )
|
||||
{
|
||||
v = QVariant( i );
|
||||
@ -330,7 +330,7 @@ bool QgsField::convertCompatible( QVariant &v ) const
|
||||
{
|
||||
// This might be a string with thousand separator: use locale to convert
|
||||
bool ok;
|
||||
qlonglong l = QLocale().toLongLong( v.toString(), &ok );
|
||||
qlonglong l = qgsPermissiveToLongLong( v.toString(), ok );
|
||||
if ( ok )
|
||||
{
|
||||
v = QVariant( l );
|
||||
|
@ -607,6 +607,14 @@ void TestQgsField::convertCompatible()
|
||||
QCOMPARE( stringDouble.type(), QVariant::Double );
|
||||
QCOMPARE( stringDouble, QVariant( 1223456.012345 ) );
|
||||
|
||||
// Test that wrongly formatted decimal separator are also accepted
|
||||
QLocale::setDefault( QLocale::German );
|
||||
QCOMPARE( QLocale().groupSeparator(), '.' );
|
||||
QCOMPARE( QLocale().decimalPoint(), ',' );
|
||||
stringDouble = QVariant( "12.23.456,012345" );
|
||||
QVERIFY( doubleField.convertCompatible( stringDouble ) );
|
||||
QCOMPARE( stringDouble.type(), QVariant::Double );
|
||||
QCOMPARE( stringDouble, QVariant( 1223456.012345 ) );
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user