Skip to content
Permalink
Browse files

Respect locale decimal separator in input fields

  • Loading branch information
elpaso committed Jun 9, 2018
1 parent 8c74dde commit f853c8d1d9e64131096dac16faaefb72cfeb976a
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/gui/qgsfieldvalidator.cpp
@@ -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 )
@@ -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

0 comments on commit f853c8d

Please sign in to comment.
You can’t perform that action at this time.