Version: 8.3.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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. More...
 
 QtxDoubleSpinBox (double, double, double=1, QWidget *=0)
 Constructor. More...
 
 QtxDoubleSpinBox (double, double, double, int, int, QWidget *=0)
 Constructor. More...
 
virtual ~QtxDoubleSpinBox ()
 Destructor. More...
 
bool isCleared () const
 Check if spin box is in the "cleared" state. More...
 
virtual void setCleared (const bool)
 Change "cleared" status of the spin box. More...
 
int getPrecision () const
 Get precision value of the spin box. More...
 
void setPrecision (const int)
 Set precision of the spin box. More...
 
virtual void stepBy (int)
 Perform steps increment/decrement steps. More...
 
virtual double valueFromText (const QString &) const
 Interpret text entered by the user as a value. More...
 
virtual QString textFromValue (double) const
 This function is used by the spin box whenever it needs to display the given value. More...
 
virtual QValidator::State validate (QString &, int &) const
 This function is used to determine whether input is valid. More...
 

Protected Slots

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

Protected Member Functions

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

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

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

References myPrecision.

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

References myCleared.

void QtxDoubleSpinBox::onTextChanged ( const QString &  )
protectedvirtualslot
Parameters
txtcurrent spin box text (not used)

References myCleared.

QString QtxDoubleSpinBox::removeTrailingZeroes ( const QString &  src) const
protected
Parameters
strsource string
Returns
resulting string
void QtxDoubleSpinBox::setCleared ( const bool  on)
virtual
Parameters
onnew "cleared" status
See Also
isCleared()

References myCleared.

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.

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, removeTrailingZeroes(), and s.

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.

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.

Member Data Documentation

bool QtxDoubleSpinBox::myCleared
private
int QtxDoubleSpinBox::myPrecision
private

The documentation for this class was generated from the following files: