// 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.opencascade.org/SALOME/ or email : webmaster.salome@opencascade.org
+// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
//
//
//
// Module : GEOM
// $Header$
-using namespace std;
#include "DlgRef_SpinBox.h"
#include <qvalidator.h>
+#include <math.h>
//=================================================================================
// class : DlgRef_SpinBox()
// purpose : constructor of specific widget accepting floats in double precision.
//=================================================================================
DlgRef_SpinBox::DlgRef_SpinBox(QWidget* parent, const char* name)
-: QAD_SpinBoxDbl(parent, name)
+ : QtxDblSpinBox(parent, name)
{
}
void DlgRef_SpinBox::RangeStepAndValidator(double min, double max,double step,
unsigned short decimals)
{
+ setPrecision(-decimals); // PAL12789. Minus is for using 'g' double->string conversion specifier,
+ // see QtxDblSpinBox::mapValueToText( double v )
setRange(min, max);
setLineStep(step);
((QDoubleValidator*)validator())->setRange(min, max, decimals);
}
+
+QString DlgRef_SpinBox::PrintDoubleValue (double theValue, int thePrecision)
+{
+ const double prec = 1e-12;
+
+ QString aRes;
+ aRes.setNum(theValue, 'g', thePrecision);
+
+ if ( prec > 0 ) {
+ int p = 0;
+ while ( p < thePrecision ) {
+ aRes.setNum( theValue, 'g', p++ );
+ double v = aRes.toDouble();
+ double err = fabs( theValue - v );
+ if ( err > 0 && err <= prec )
+ break;
+ }
+ }
+
+ // remove trailing zeroes
+ QString delim( "." );
+
+ int idx = aRes.findRev( delim );
+ if ( idx == -1 )
+ return aRes;
+
+ QString iPart = aRes.left( idx );
+ QString fPart = aRes.mid( idx + 1 );
+
+ while ( !fPart.isEmpty() && fPart.at( fPart.length() - 1 ) == '0' )
+ fPart.remove( fPart.length() - 1, 1 );
+
+ aRes = iPart;
+ if ( !fPart.isEmpty() )
+ aRes += delim + fPart;
+
+ return aRes;
+}