From a308ab09bc626f851741c80c265c5f444663f107 Mon Sep 17 00:00:00 2001 From: vsr Date: Thu, 1 Jul 2010 06:28:17 +0000 Subject: [PATCH] IPAL21822: Thousand separators in double spin boxes (inconsistent behavior) --- src/Qtx/QtxDoubleSpinBox.cxx | 27 +++++++++++++++++++---- src/Qtx/QtxIntSpinBox.cxx | 12 ++++++++++ src/SalomeApp/SalomeApp_DoubleSpinBox.cxx | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/src/Qtx/QtxDoubleSpinBox.cxx b/src/Qtx/QtxDoubleSpinBox.cxx index 87120b243..50717e4f9 100644 --- a/src/Qtx/QtxDoubleSpinBox.cxx +++ b/src/Qtx/QtxDoubleSpinBox.cxx @@ -75,6 +75,12 @@ QtxDoubleSpinBox::QtxDoubleSpinBox( QWidget* parent ) : QDoubleSpinBox( parent ), myCleared( false ) { + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid incosistency of double-2-string and string-2-double conversion) + QLocale loc; + loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); + setLocale(loc); + // Use precision equal to default Qt decimals myPrecision = decimals(); @@ -98,6 +104,12 @@ QtxDoubleSpinBox::QtxDoubleSpinBox( double min, double max, double step, QWidget : QDoubleSpinBox( parent ), myCleared( false ) { + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid incosistency of double-2-string and string-2-double conversion) + QLocale loc; + loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); + setLocale(loc); + // Use precision equal to default Qt decimals myPrecision = decimals(); @@ -129,6 +141,12 @@ QtxDoubleSpinBox::QtxDoubleSpinBox( double min, double max, double step, int pre myCleared( false ), myPrecision( prec ) { + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid incosistency of double-2-string and string-2-double conversion) + QLocale loc; + loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); + setLocale(loc); + setDecimals( dec ); setMinimum( min ); setMaximum( max ); @@ -221,7 +239,7 @@ double QtxDoubleSpinBox::valueFromText( const QString& text ) const */ QString QtxDoubleSpinBox::textFromValue( double val ) const { - QString s = QLocale().toString( val, myPrecision >= 0 ? 'f' : 'g', qAbs( myPrecision ) ); + QString s = locale().toString( val, myPrecision >= 0 ? 'f' : 'g', qAbs( myPrecision ) ); return removeTrailingZeroes( s ); } @@ -232,7 +250,7 @@ QString QtxDoubleSpinBox::textFromValue( double val ) const */ QString QtxDoubleSpinBox::removeTrailingZeroes( const QString& src ) const { - QString delim( QLocale().decimalPoint() ); + QString delim( locale().decimalPoint() ); int idx = src.lastIndexOf( delim ); if ( idx == -1 ) @@ -298,8 +316,9 @@ QValidator::State QtxDoubleSpinBox::validate( QString& str, int& pos ) const v.setNotation( myPrecision >= 0 ? QDoubleValidator::StandardNotation : QDoubleValidator::ScientificNotation ); - if ( overhead == 0 ) + if ( overhead == 0 ) { state = v.validate( str, pos ); + } else { if ( str.length() >= overhead && str.startsWith( pref ) && @@ -344,7 +363,7 @@ QValidator::State QtxDoubleSpinBox::validate( QString& str, int& pos ) const } else if ( myPrecision < 0 ){ // Consider too large negative exponent as Invalid - QChar e( QLocale().exponential() ); + QChar e( locale().exponential() ); int epos = str.indexOf( e, 0, Qt::CaseInsensitive ); if ( epos != -1 ){ epos++; // Skip exponential symbol itself diff --git a/src/Qtx/QtxIntSpinBox.cxx b/src/Qtx/QtxIntSpinBox.cxx index cb3dd5bff..a851c3cf4 100755 --- a/src/Qtx/QtxIntSpinBox.cxx +++ b/src/Qtx/QtxIntSpinBox.cxx @@ -61,6 +61,12 @@ QtxIntSpinBox::QtxIntSpinBox( QWidget* parent ) : QSpinBox( parent ), myCleared( false ) { + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid incosistency of double-2-string and string-2-double conversion) + QLocale loc; + loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); + setLocale(loc); + setCorrectionMode( QSpinBox::CorrectToNearestValue ); connect( lineEdit(), SIGNAL( textChanged( const QString& ) ), this, SLOT( onTextChanged( const QString& ) ) ); @@ -81,6 +87,12 @@ QtxIntSpinBox::QtxIntSpinBox( int min, int max, int step, QWidget* parent ) : QSpinBox( parent ), myCleared( false ) { + // VSR 01/07/2010: Disable thousands separator for spin box + // (to avoid incosistency of double-2-string and string-2-double conversion) + QLocale loc; + loc.setNumberOptions(loc.numberOptions() | QLocale::OmitGroupSeparator | QLocale::RejectGroupSeparator); + setLocale(loc); + setMinimum( min ); setMaximum( max ); setSingleStep( step ); diff --git a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx index 984bb04b0..3ef39e1bf 100644 --- a/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx +++ b/src/SalomeApp/SalomeApp_DoubleSpinBox.cxx @@ -377,7 +377,7 @@ SalomeApp_DoubleSpinBox::State SalomeApp_DoubleSpinBox::isValid( const QString& if( aSearchState == NotFound ) { bool ok = false; - value = QLocale().toDouble( text, &ok ); + value = locale().toDouble( text, &ok ); if ( !ok ) return NoVariable; } -- 2.39.2