]> SALOME platform Git repositories - modules/gui.git/commitdiff
Salome HOME
Fix for bug IPAL19434 : Qt4 porting. Number of digits after comma are too much (14...
authormkr <mkr@opencascade.com>
Mon, 7 Apr 2008 10:44:39 +0000 (10:44 +0000)
committermkr <mkr@opencascade.com>
Mon, 7 Apr 2008 10:44:39 +0000 (10:44 +0000)
src/Qtx/QtxDoubleSpinBox.cxx
src/Qtx/QtxDoubleSpinBox.h

index c79e581c0354790b962700ab7b9fefbfa7e545c8..535fa4b96bbfdeb09b4f6221d3349d9318156c2e 100644 (file)
@@ -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;
 }
 
 /*!
index 45ef5434b517feb359106ad160dbd11dd3dd68c4..fe180c2d2fd4ea309c959281c59c3e1c9c1de57d 100644 (file)
@@ -45,6 +45,8 @@ private slots:
 
 protected:
   virtual QString textFromValue( double ) const;
+  
+  QString         removeTrailingZeroes( const QString& ) const;
 
 private:
   bool            myCleared;