Version: 6.3.1
Public Member Functions | Protected Slots | Protected Member Functions | Private Attributes

QtxDoubleSpinBox Class Reference

Enhanced version of the Qt's double spin box. More...

#include <QtxDoubleSpinBox.h>

Inheritance diagram for QtxDoubleSpinBox:
Inheritance graph

Public Member Functions

 QtxDoubleSpinBox (QWidget *=0)
 Constructor.
 QtxDoubleSpinBox (double, double, double=1, QWidget *=0)
 Constructor.
 QtxDoubleSpinBox (double, double, double, int, int, QWidget *=0)
 Constructor.
virtual ~QtxDoubleSpinBox ()
 Destructor.
bool isCleared () const
 Check if spin box is in the "cleared" state.
virtual void setCleared (const bool)
 Change "cleared" status of the spin box.
int getPrecision () const
 Get precision value of the spin box.
void setPrecision (const int)
 Set precision of the spin box.
virtual void stepBy (int)
 Perform steps increment/decrement steps.
virtual double valueFromText (const QString &) const
 Interpret text entered by the user as a value.
virtual QString textFromValue (double) const
 This function is used by the spin box whenever it needs to display the given value.
virtual QValidator::State validate (QString &, int &) const
 This function is used to determine whether input is valid.

Protected Slots

virtual void onTextChanged (const QString &)
 Called when user enters the text in the spin box.

Protected Member Functions

QString removeTrailingZeroes (const QString &) const
 Return source string with removed leading and trailing zeros.

Private Attributes

bool myCleared
int myPrecision

Detailed Description

The QtxDoubleSpinBox class represents the widget for entering the floating point values. In addition to the functionality provided by QDoubleSpinBox, this class supports "cleared" state - this is the state corresponding to "None" (or empty) entered value.

To set "cleared" state use setCleared() method. To check if the spin box stores "cleared" state, use isCleared() method. For example:

  if (myDblSpinBox->isCleared()) {
    ... // process "None" state
  }
  else {
    double value = myDblSpinBox->value();
    ... // process entered value
  }

Another useful feature is possibility to use scientific notation (e.g. 1.234e+18) for the widegt text. To enable this, negative precision should be specified either through a constructor or using setPrecision() method.

Note that "decimals" property of QDoubleSpinBox is almost completely substituted by "myPrecision" field of QtxDoubleSpinBox class. "decimals" is still used for proper size hint calculation and for rounding minimum and maximum bounds of the spin box range.


Constructor & Destructor Documentation

QtxDoubleSpinBox::QtxDoubleSpinBox ( QWidget parent = 0)

Constructs a spin box with 0.0 as minimum value and 99.99 as maximum value, a step value of 1.0 and a precision of 2 decimal places. The value is initially set to 0.00.

Parameters:
parentparent object

References myPrecision, and onTextChanged().

QtxDoubleSpinBox::QtxDoubleSpinBox ( double  min,
double  max,
double  step = 1,
QWidget parent = 0 
)

Constructs a spin box with specified minimum, maximum and step value. The precision is set to 2 decimal places. The value is initially set to the minimum value.

Parameters:
minspin box minimum possible value
maxspin box maximum possible value
stepspin box increment/decrement value
parentparent object

References myPrecision, and onTextChanged().

QtxDoubleSpinBox::QtxDoubleSpinBox ( double  min,
double  max,
double  step,
int  prec,
int  dec,
QWidget parent = 0 
)

Constructs a spin box with specified minimum, maximum and step value. The precision is set to <prec> decimal places. The value is initially set to the minimum value.

Parameters:
minspin box minimum possible value
maxspin box maximum possible value
stepspin box increment/decrement value
precnon-negative values means the number of digits after the decimal point, negative value means the maximum number of significant digits for the scientific notation
decnumber of digits after the decimal point passed to base Qt class (used for correct control sizing only!)
parentparent object

References onTextChanged().

QtxDoubleSpinBox::~QtxDoubleSpinBox ( ) [virtual]

Member Function Documentation

bool QtxDoubleSpinBox::isCleared ( ) const
Returns:
true if spin box is cleared
See also:
setCleared()

References myCleared.

void QtxDoubleSpinBox::setCleared ( const bool  on) [virtual]
Parameters:
onnew "cleared" status
See also:
isCleared()

References myCleared.

int QtxDoubleSpinBox::getPrecision ( ) const
Returns:
current prevision value
See also:
setPrecision()

References myPrecision.

void QtxDoubleSpinBox::setPrecision ( const int  prec)

If precision value is less than 0, the 'g' format is used for value output, otherwise 'f' format is used.

Parameters:
precnew precision value.
See also:
precision()

References myPrecision.

void QtxDoubleSpinBox::stepBy ( int  steps) [virtual]

The steps value can be any integer number. If it is > 0, the value incrementing is done, otherwise value is decremented steps times.

Parameters:
stepsnumber of increment/decrement steps

Reimplemented in SalomeApp_DoubleSpinBox.

References myCleared, and PSEUDO_ZERO.

double QtxDoubleSpinBox::valueFromText ( const QString &  text) const [virtual]
Parameters:
texttext entered by the user
Returns:
mapped value
See also:
textFromValue()

Reimplemented in SalomeApp_DoubleSpinBox.

References myPrecision.

QString QtxDoubleSpinBox::textFromValue ( double  val) const [virtual]
Parameters:
valspin box value
Returns:
text representation of the value
See also:
valueFromText()

Reimplemented in SalomeApp_DoubleSpinBox.

References myPrecision, and removeTrailingZeroes().

QValidator::State QtxDoubleSpinBox::validate ( QString &  str,
int &  pos 
) const [virtual]
Parameters:
strcurrently entered value
poscursor position in the string
Returns:
validating operation result

Reimplemented in SalomeApp_DoubleSpinBox.

References myPrecision.

void QtxDoubleSpinBox::onTextChanged ( const QString &  ) [protected, virtual, slot]
Parameters:
txtcurrent spin box text (not used)

Reimplemented in SalomeApp_DoubleSpinBox.

References myCleared.

QString QtxDoubleSpinBox::removeTrailingZeroes ( const QString &  src) const [protected]
Parameters:
strsource string
Returns:
resulting string

Field Documentation

Copyright © 2007-2011 CEA/DEN, EDF R&D, OPEN CASCADE
Copyright © 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS