Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Respect locale decimal separator in input fields
  • Loading branch information
elpaso committed Jun 9, 2018
1 parent 8c74dde commit f853c8d
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions src/gui/qgsfieldvalidator.cpp
Expand Up @@ -56,7 +56,16 @@ QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, co
{
if ( mField.length() > 0 && mField.precision() > 0 )
{
QString re = QStringLiteral( "-?\\d{0,%1}([\\.,]\\d{0,%2})?" ).arg( mField.length() - mField.precision() ).arg( mField.precision() );
QString re;
// Also accept locale's decimalPoint if it's not a dot
if ( QLocale().decimalPoint() != '.' )
{
re = QStringLiteral( "-?\\d{0,%1}([\\.%2]\\d{0,%3})?" ).arg( mField.length() - mField.precision() ).arg( QLocale().decimalPoint() ).arg( mField.precision() );
}
else
{
re = QStringLiteral( "-?\\d{0,%1}([\\.,]\\d{0,%2})?" ).arg( mField.length() - mField.precision() ).arg( mField.precision() );
}
mValidator = new QRegExpValidator( QRegExp( re ), parent );
}
else if ( mField.length() > 0 && mField.precision() == 0 )
Expand All @@ -66,7 +75,16 @@ QgsFieldValidator::QgsFieldValidator( QObject *parent, const QgsField &field, co
}
else if ( mField.precision() > 0 )
{
QString re = QStringLiteral( "-?\\d*([\\.,]\\d{0,%1})?" ).arg( mField.precision() );
QString re;
// Also accept locale's decimalPoint if it's not a dot
if ( QLocale().decimalPoint() != '.' )
{
re = QStringLiteral( "-?\\d*([\\.%1]\\d{0,%2})?" ).arg( QLocale().decimalPoint(), mField.precision() );
}
else
{
re = QStringLiteral( "-?\\d*([\\.]\\d{0,%1})?" ).arg( mField.precision() );
}
mValidator = new QRegExpValidator( QRegExp( re ), parent );
}
else
Expand Down

0 comments on commit f853c8d

Please sign in to comment.