OpenHantek
SiSpinBox Class Reference

A spin box with SI prefix support. This spin box supports the SI prefixes (k/M/G/T) after its value and allows floating point values. The step size is increasing in an exponential way, to keep the percentual difference between the steps at equal levels. More...

#include <sispinbox.h>

Inheritance diagram for SiSpinBox:

Public Member Functions

 SiSpinBox (QWidget *parent=nullptr)
 Initializes the SiSpinBox internals. More...
 
 SiSpinBox (Unit unit, QWidget *parent=nullptr)
 Initializes the SiSpinBox, allowing the user to choose the unit. More...
 
 ~SiSpinBox ()
 Cleans up the main window. More...
 
QValidator::State validate (QString &input, int &pos) const
 Validates the text after user input. More...
 
double valueFromText (const QString &text) const
 Parse value from input text. More...
 
QString textFromValue (double val) const
 Get string representation of value. More...
 
void fixup (QString &input) const
 Fixes the text after the user finished changing it. More...
 
void stepBy (int steps)
 Increase/decrease the values in fixed steps. More...
 
bool setUnit (Unit unit)
 Set the unit for this spin box. More...
 
void setUnitPostfix (const QString &postfix)
 Set the unit postfix for this spin box. More...
 
void setSteps (const QList< double > &steps)
 Set the steps the spin box will take. More...
 
void setMode (const int mode)
 Set the mode. More...
 

Private Slots

void resetSteppedTo ()
 Resets the ::steppedTo flag after the value has been changed. More...
 

Private Member Functions

void init ()
 Generic initializations. More...
 
void setBackground ()
 

Private Attributes

Unit unit
 The SI unit used for this spin box. More...
 
QString unitPostfix
 Shown after the unit. More...
 
QList< double > steps
 The steps, begins from start after last element. More...
 
int mode
 The mode, fixed or constant. More...
 
bool steppedTo
 true, if the current value was reached using stepBy More...
 
int stepId
 The index of the last step reached using stepBy. More...
 

Detailed Description

A spin box with SI prefix support. This spin box supports the SI prefixes (k/M/G/T) after its value and allows floating point values. The step size is increasing in an exponential way, to keep the percentual difference between the steps at equal levels.

Constructor & Destructor Documentation

◆ SiSpinBox() [1/2]

SiSpinBox::SiSpinBox ( QWidget *  parent = nullptr)
explicit

Initializes the SiSpinBox internals.

Parameters
parentThe parent widget.

◆ SiSpinBox() [2/2]

SiSpinBox::SiSpinBox ( Unit  unit,
QWidget *  parent = nullptr 
)

Initializes the SiSpinBox, allowing the user to choose the unit.

Parameters
unitThe unit shown for the value in the spin box.
parentThe parent widget.

◆ ~SiSpinBox()

SiSpinBox::~SiSpinBox ( )

Cleans up the main window.

Member Function Documentation

◆ fixup()

void SiSpinBox::fixup ( QString &  input) const

Fixes the text after the user finished changing it.

Parameters
inputThe content of the text box.

◆ init()

void SiSpinBox::init ( )
private

Generic initializations.

◆ resetSteppedTo

void SiSpinBox::resetSteppedTo ( )
privateslot

Resets the ::steppedTo flag after the value has been changed.

◆ setBackground()

void SiSpinBox::setBackground ( )
private

◆ setMode()

void SiSpinBox::setMode ( const int  newMode)

Set the mode.

Parameters
modeThe mode, the value 0 will have fixed interval, otherwise the value will have interval within steps itself.

◆ setSteps()

void SiSpinBox::setSteps ( const QList< double > &  newSteps)

Set the steps the spin box will take.

Parameters
newStepsThe steps, will be extended with the ratio from the start after the last element.

◆ setUnit()

bool SiSpinBox::setUnit ( Unit  newUnit)

Set the unit for this spin box.

Parameters
newUnitThe unit shown for the value in the spin box.
Returns
true on success, false on invalid unit.

◆ setUnitPostfix()

void SiSpinBox::setUnitPostfix ( const QString &  postfix)

Set the unit postfix for this spin box.

Parameters
postfixthe string shown after the unit in the spin box.

◆ stepBy()

void SiSpinBox::stepBy ( int  doStep)

Increase/decrease the values in fixed steps.

Parameters
doStepThe number of steps, positive means increase.

◆ textFromValue()

QString SiSpinBox::textFromValue ( double  val) const

Get string representation of value.

Parameters
valValue in base unit.
Returns
String representation containing value and (prefix+)unit.

◆ validate()

QValidator::State SiSpinBox::validate ( QString &  input,
int &  pos 
) const

Validates the text after user input.

Parameters
inputThe content of the text box.
posThe position of the cursor in the text box.
Returns
Validity of the current text.

◆ valueFromText()

double SiSpinBox::valueFromText ( const QString &  text) const

Parse value from input text.

Parameters
textThe content of the text box.
Returns
Value in base unit.

Field Documentation

◆ mode

int SiSpinBox::mode
private

The mode, fixed or constant.

◆ stepId

int SiSpinBox::stepId
private

The index of the last step reached using stepBy.

◆ steppedTo

bool SiSpinBox::steppedTo
private

true, if the current value was reached using stepBy

◆ steps

QList<double> SiSpinBox::steps
private

The steps, begins from start after last element.

◆ unit

Unit SiSpinBox::unit
private

The SI unit used for this spin box.

◆ unitPostfix

QString SiSpinBox::unitPostfix
private

Shown after the unit.


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