From 8e8c82c3df1422de87aaed3acfade0da713fc8a2 Mon Sep 17 00:00:00 2001 From: stv Date: Tue, 29 Nov 2005 10:11:34 +0000 Subject: [PATCH] no message --- src/Qtx/QtxDblSpinBox.cxx | 29 +++++++++++++++++++++++++---- src/Qtx/QtxDblSpinBox.h | 4 +++- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/src/Qtx/QtxDblSpinBox.cxx b/src/Qtx/QtxDblSpinBox.cxx index 971bef49f..e00944da6 100755 --- a/src/Qtx/QtxDblSpinBox.cxx +++ b/src/Qtx/QtxDblSpinBox.cxx @@ -371,15 +371,15 @@ QString QtxDblSpinBox::currentValueText() QString QtxDblSpinBox::mapValueToText( double v ) { QString s; - s.setNum( v, myPrecision < 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); - return s; + s.setNum( v, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); + return removeTrailingZeroes( s ); } QString QtxDblSpinBox::mapValueToText( int ) { QString s; - s.setNum( myValue, myPrecision < 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); - return s; + s.setNum( myValue, myPrecision >= 0 ? 'f' : 'g', myPrecision == 0 ? 6 : QABS( myPrecision ) ); + return removeTrailingZeroes( s ); } double QtxDblSpinBox::mapTextToDoubleValue( bool* ok ) @@ -424,3 +424,24 @@ void QtxDblSpinBox::onTextChanged( const QString& str ) if ( !myBlocked ) myCleared = false; } + +QString QtxDblSpinBox::removeTrailingZeroes( const QString& src ) const +{ + QString delim( "." ); + + int idx = src.findRev( delim ); + if ( idx == -1 ) + return src; + + QString iPart = src.left( idx ); + QString fPart = src.mid( idx + 1 ); + + while ( !fPart.isEmpty() && fPart.at( fPart.length() - 1 ) == '0' ) + fPart.remove( fPart.length() - 1, 1 ); + + QString res = iPart; + if ( !fPart.isEmpty() ) + res += delim + fPart; + + return res; +} diff --git a/src/Qtx/QtxDblSpinBox.h b/src/Qtx/QtxDblSpinBox.h index eea959f7a..9b7a0cf95 100755 --- a/src/Qtx/QtxDblSpinBox.h +++ b/src/Qtx/QtxDblSpinBox.h @@ -75,7 +75,9 @@ protected: virtual void wheelEvent( QWheelEvent* ); double bound( double ); - + + QString removeTrailingZeroes( const QString& ) const; + private: double myMin; double myMax; -- 2.39.2