From: mkr Date: Mon, 7 Apr 2008 10:44:39 +0000 (+0000) Subject: Fix for bug IPAL19434 : Qt4 porting. Number of digits after comma are too much (14... X-Git-Tag: V5_0_0~20 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=ebcd472f3b85a67f0735e5578c026a104442931f;p=modules%2Fgui.git Fix for bug IPAL19434 : Qt4 porting. Number of digits after comma are too much (14) in some dialog boxes. --- diff --git a/src/Qtx/QtxDoubleSpinBox.cxx b/src/Qtx/QtxDoubleSpinBox.cxx index c79e581c0..535fa4b96 100644 --- a/src/Qtx/QtxDoubleSpinBox.cxx +++ b/src/Qtx/QtxDoubleSpinBox.cxx @@ -123,7 +123,31 @@ void QtxDoubleSpinBox::setCleared( const bool on ) */ QString QtxDoubleSpinBox::textFromValue( double val ) const { - return myCleared ? QString() : QDoubleSpinBox::textFromValue( val ); + return removeTrailingZeroes( myCleared ? QString() : QDoubleSpinBox::textFromValue( val ) ); +} + +/*! + \brief Return string without excess zeros in start and in end +*/ +QString QtxDoubleSpinBox::removeTrailingZeroes( const QString& src ) const +{ + QString delim( "." ); + + int idx = src.lastIndexOf( 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/QtxDoubleSpinBox.h b/src/Qtx/QtxDoubleSpinBox.h index 45ef5434b..fe180c2d2 100644 --- a/src/Qtx/QtxDoubleSpinBox.h +++ b/src/Qtx/QtxDoubleSpinBox.h @@ -45,6 +45,8 @@ private slots: protected: virtual QString textFromValue( double ) const; + + QString removeTrailingZeroes( const QString& ) const; private: bool myCleared;