From ebcd472f3b85a67f0735e5578c026a104442931f Mon Sep 17 00:00:00 2001 From: mkr Date: Mon, 7 Apr 2008 10:44:39 +0000 Subject: [PATCH] Fix for bug IPAL19434 : Qt4 porting. Number of digits after comma are too much (14) in some dialog boxes. --- src/Qtx/QtxDoubleSpinBox.cxx | 26 +++++++++++++++++++++++++- src/Qtx/QtxDoubleSpinBox.h | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) 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; -- 2.39.2