SHAPER  9.12.0
ModuleBase_DoubleSpinBox Class Reference

An extension and customization of QDoubleSpinBox class. More...

Inheritance diagram for ModuleBase_DoubleSpinBox:
Inheritance graph

Public Member Functions

 ModuleBase_DoubleSpinBox (QWidget *theParent=0, int thePrecision=-12)
 Constructor. More...
 
virtual ~ModuleBase_DoubleSpinBox ()
 Destructor. More...
 
bool isCleared () const
 Returns true if the control is clear. More...
 
virtual void setCleared (const bool)
 Set control clear. More...
 
int getPrecision () const
 Returns current precision. More...
 
void setPrecision (const int)
 Set precision. More...
 
virtual void stepBy (int)
 Set step. More...
 
virtual double valueFromText (const QString &) const
 Converts value from string to double. More...
 
virtual QString textFromValue (double) const
 Convert value from double to string. More...
 
virtual QValidator::State validate (QString &, int &) const
 Validate current value. More...
 
void setValueEnabled (const bool &theEnable)
 Imitation of disable control value. More...
 

Protected Slots

virtual void onTextChanged (const QString &)
 Called on text changed. More...
 

Protected Member Functions

QString removeTrailingZeroes (const QString &) const
 Removes extra trailing zero symbols. More...
 

Detailed Description

An extension and customization of QDoubleSpinBox class.

Enhanced version of the Qt's double spin box.

The ModuleBase_DoubleSpinBox 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 widget 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 ModuleBase_DoubleSpinBox 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

◆ ModuleBase_DoubleSpinBox()

ModuleBase_DoubleSpinBox::ModuleBase_DoubleSpinBox ( QWidget theParent = 0,
int  thePrecision = -12 
)
explicit

Constructor.

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
theParentparent object
thePrecisionprecision of values input

◆ ~ModuleBase_DoubleSpinBox()

ModuleBase_DoubleSpinBox::~ModuleBase_DoubleSpinBox ( )
virtual

Destructor.

Member Function Documentation

◆ isCleared()

bool ModuleBase_DoubleSpinBox::isCleared ( ) const

Returns true if the control is clear.

Check if spin box is in the "cleared" state.

Returns
true if spin box is cleared
See also
setCleared()

◆ setCleared()

void ModuleBase_DoubleSpinBox::setCleared ( const bool  on)
virtual

Set control clear.

Change "cleared" status of the spin box.

Parameters
onnew "cleared" status
See also
isCleared()

◆ getPrecision()

int ModuleBase_DoubleSpinBox::getPrecision ( ) const

Returns current precision.

Get precision value of the spin box.

Returns
current precision value
See also
setPrecision()

◆ setPrecision()

void ModuleBase_DoubleSpinBox::setPrecision ( const int  prec)

Set precision.

Set precision of the spin box.

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()

◆ stepBy()

void ModuleBase_DoubleSpinBox::stepBy ( int  steps)
virtual

Set step.

Perform steps increment/decrement steps.

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

◆ valueFromText()

double ModuleBase_DoubleSpinBox::valueFromText ( const QString &  text) const
virtual

Converts value from string to double.

Interpret text entered by the user as a value.

Parameters
texttext entered by the user
Returns
mapped value
See also
textFromValue()

◆ textFromValue()

QString ModuleBase_DoubleSpinBox::textFromValue ( double  val) const
virtual

Convert value from double to string.

This function is used by the spin box whenever it needs to display the given value.

Parameters
valspin box value
Returns
text representation of the value
See also
valueFromText()

◆ validate()

QValidator::State ModuleBase_DoubleSpinBox::validate ( QString &  str,
int &  pos 
) const
virtual

Validate current value.

This function is used to determine whether input is valid.

Parameters
strcurrently entered value
poscursor position in the string
Returns
validating operation result

◆ setValueEnabled()

void ModuleBase_DoubleSpinBox::setValueEnabled ( const bool &  theEnable)

Imitation of disable control value.

If theEnable is false, the control becomes read only and base color is disabled.

◆ onTextChanged

void ModuleBase_DoubleSpinBox::onTextChanged ( const QString &  )
protectedvirtualslot

Called on text changed.

Called when user enters the text in the spin box.

◆ removeTrailingZeroes()

QString ModuleBase_DoubleSpinBox::removeTrailingZeroes ( const QString &  src) const
protected

Removes extra trailing zero symbols.

Return source string with removed leading and trailing zeros.

Parameters
srcsource string
Returns
resulting string