+// 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
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 )
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;
+}