[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
Public Slots | Signals | Public Member Functions | Properties
KLFUnitSpinBox Class Reference

A spin box that can display values in different units. More...

#include <klfunitinput.h>

List of all members.

Public Slots

void setUnit (double unitfactor)
void setUnitWithSuffix (double unitfactor, const QString &suffix)
void setShowUnitSuffix (bool show)
void setValueInRefUnit (double value)

Signals

void valueInRefUnitChanged (double value)

Public Member Functions

 KLFUnitSpinBox (QWidget *parent=NULL)
virtual ~KLFUnitSpinBox ()
double unitFactor () const
bool showUnitSuffix () const
double valueInRefUnit () const

Properties

double valurInRefUnit
double unitFactor
bool showUnitSuffix

Detailed Description

A spin box that can display values in different units.

This widget presents a spin box which displays a value, which by default is shown in the 'reference unit', for which the 'unit factor' is 1.

Other units may be set (eg. by connecting our setUnit(double) slot to the unitChanged(double) signal of a KLFUnitChooser) which have other unit factors telling how to convert the other value into the 'ref unit' value.

Example:

   // as the programmer, we have only to think which units the _program_ requests and define
   // that value to be the 'reference unit'. We assume for this example that the (fictive)
   // function  perform_adjustment(double)  requests an argument that is a length in millimeters.
   KLFUnitSpinBox spn = new KLFUnitSpinBox;
   spn->setValue(18); // We display the value 18 ref-units. (= mm here)
   spn->setUnit(25.4); // set a unit that is 25.4 'ref-units': will now display the value 0.709
   //                     which is 18mm in inches.
   ...
   // other units may be set with spn->setUnit(double unitfactor)
   ...
   // at the end, retrieve the value
   double valueInMM = spn->valueInRefUnit();
   perform_adjustment(valueInMM);

When units are changed, the minimum and maximum are adjusted to the value in the new units.

The precision ( QDoubleSpinBox::setDecimals()) is also adjusted to the right order of magnitude (power of 10). For example, if the value of 18.3mm is displayed with 1 decimal place, and a unit is set with factor of 1000 (m) then the presision is adjusted to 4 decimal places. And if a unit is set with factor of 304.8 (foot) then the precision is adjusted to 3 decimal places. Details: the number of decimal places to adjust is determined by rounding the value log_10(unit-factor) to the nearest integer.

Note:
'unit-factor' of unit XYZ is defined as the number of ref units needed to amount to one XYZ.

Definition at line 149 of file klfunitinput.h.


Constructor & Destructor Documentation

KLFUnitSpinBox::KLFUnitSpinBox ( QWidget *  parent = NULL)

Definition at line 150 of file klfunitinput.cpp.

Definition at line 157 of file klfunitinput.cpp.


Member Function Documentation

void KLFUnitSpinBox::setShowUnitSuffix ( bool  show) [slot]

Whether to display the unit suffix or not. This only works if you use setUnitWithSuffix() to set new units.

Definition at line 201 of file klfunitinput.cpp.

void KLFUnitSpinBox::setUnit ( double  unitfactor) [slot]

Definition at line 161 of file klfunitinput.cpp.

References klfDbg.

Referenced by setUnitWithSuffix().

void KLFUnitSpinBox::setUnitWithSuffix ( double  unitfactor,
const QString suffix 
) [slot]

Display the current value converted to the new unit using unitfactor, and if showUnitSuffix() is TRUE, then displays the given suffix.

Definition at line 189 of file klfunitinput.cpp.

References setUnit().

void KLFUnitSpinBox::setValueInRefUnit ( double  value) [slot]

Definition at line 196 of file klfunitinput.cpp.

bool KLFUnitSpinBox::showUnitSuffix ( ) const [inline]

Definition at line 161 of file klfunitinput.h.

double KLFUnitSpinBox::unitFactor ( ) const [inline]

Definition at line 159 of file klfunitinput.h.

double KLFUnitSpinBox::valueInRefUnit ( ) const [inline]

Definition at line 163 of file klfunitinput.h.

void KLFUnitSpinBox::valueInRefUnitChanged ( double  value) [signal]

Property Documentation

bool KLFUnitSpinBox::showUnitSuffix [read, write]

Definition at line 154 of file klfunitinput.h.

double KLFUnitSpinBox::unitFactor [read, write]

Definition at line 153 of file klfunitinput.h.

double KLFUnitSpinBox::valurInRefUnit [read, write]

Definition at line 152 of file klfunitinput.h.


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

Generated by doxygen 1.7.6.1. The KLatexFormula website is hosted on sourceforge.net