Salome HOME
Copyrights update
[modules/gui.git] / src / Qtx / QtxDblSpinBox.cxx
index 971bef49f0f932dfee51bad50e7f818ff4735505..235218ff35964fd29dfca98349608a41dc124b9d 100755 (executable)
@@ -1,3 +1,21 @@
+// Copyright (C) 2005  OPEN CASCADE, CEA/DEN, EDF R&D, PRINCIPIA R&D
+// 
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either 
+// version 2.1 of the License.
+// 
+// This library is distributed in the hope that it will be useful 
+// but WITHOUT ANY WARRANTY; without even the implied warranty of 
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU 
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public  
+// License along with this library; if not, write to the Free Software 
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
+//
+// See http://www.salome-platform.org/
+//
 // File:      QtxDblSpinBox.cxx
 // Author:    Sergey TELKOV
 
@@ -371,15 +389,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 +442,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;
+}