• Skip to content
  • Skip to link menu
KDE 3.5 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

kdeui

KDoubleSpinBox Class Reference

A spin box for fractional numbers. More...

#include <knuminput.h>

Inheritance diagram for KDoubleSpinBox:

Inheritance graph
[legend]

List of all members.


Public Slots

virtual void setValue (double value)

Signals

void valueChanged (double value)

Public Member Functions

bool acceptLocalizedNumbers () const
 KDoubleSpinBox (double lower, double upper, double step, double value, int precision=2, QWidget *parent=0, const char *name=0)
 KDoubleSpinBox (QWidget *parent=0, const char *name=0)
double lineStep () const
double maxValue () const
double minValue () const
int precision () const
virtual void setAcceptLocalizedNumbers (bool accept)
void setLineStep (double step)
void setMaxValue (double value)
void setMinValue (double value)
virtual void setPrecision (int precision, bool force)
void setPrecision (int precision)
void setRange (double lower, double upper, double step=0.01, int precision=2)
void setValidator (const QValidator *)
double value () const
virtual ~KDoubleSpinBox ()

Protected Slots

void slotValueChanged (int value)

Protected Member Functions

virtual int mapTextToValue (bool *)
virtual QString mapValueToText (int)
virtual void virtual_hook (int id, void *data)

Properties

bool acceptLocalizedNumbers
int precision

Detailed Description

A spin box for fractional numbers.

This class provides a spin box for fractional numbers.

kdoublespinbox.png

KDE Fractional Number Spinbox

See below for code examples on how to use this class.

Parameters

To make successful use of KDoubleSpinBox, you need to understand the relationship between precision and available range.

  • precision: The number of digits after the decimal point.
  • maxValue/minValue: upper and lower bounds of the valid range
  • lineStep: the size of the step that is made when the user hits the up or down buttons
Since we work with fixed-point numbers internally, the maximum precision is a function of the valid range and vice versa. More precisely, the following relationships hold:
   max( abs(minValue()), abs(maxValue() ) <= INT_MAX/10^precision
   maxPrecision = floor( log10( INT_MAX/max(abs(minValue()),abs(maxValue())) ) )

Since the value, bounds and lineStep are rounded to the current precision, you may find that the order of setting these parameters matters. As an example, the following are not equivalent (try it!):

 sets precision,
 then min/max value (rounded to precision and clipped to obtainable range if needed)
 then value and lineStep
   KDoubleSpinBox * spin = new KDoubleSpinBox( 0, 9.999, 0.001, 4.321, 3, this );

 sets minValue to 0; maxValue to 10.00(!); value to 4.32(!) and only then
 increases the precision - too late, since e.g. value has already been rounded...
   KDoubleSpinBox * spin = new KDoubleSpinBox( this );
   spin->setMinValue( 0 );
   spin->setMaxValue( 9.999 );
   spin->setValue( 4.321 );
   spin->setPrecision( 3 );

Author:
Marc Mutz <mutz@kde.org>
Version:
$Id$
Since:
3.1

Definition at line 834 of file knuminput.h.


Constructor & Destructor Documentation

KDoubleSpinBox::KDoubleSpinBox ( QWidget *  parent = 0,
const char *  name = 0 
)

Constructs a KDoubleSpinBox with parent parent and default values for range and value (whatever QRangeControl uses) and precision (2).

Definition at line 996 of file knuminput.cpp.

KDoubleSpinBox::KDoubleSpinBox ( double  lower,
double  upper,
double  step,
double  value,
int  precision = 2,
QWidget *  parent = 0,
const char *  name = 0 
)

Constructs a KDoubleSpinBox with parent parent, range [ lower, upper ], lineStep step, precision precision and initial value value.

Definition at line 1005 of file knuminput.cpp.

KDoubleSpinBox::~KDoubleSpinBox (  )  [virtual]

Definition at line 1017 of file knuminput.cpp.


Member Function Documentation

bool KDoubleSpinBox::acceptLocalizedNumbers (  )  const

Returns:
whether the spinbox uses localized numbers

double KDoubleSpinBox::lineStep (  )  const

Returns:
the current step size

Reimplemented from QSpinBox.

Definition at line 1114 of file knuminput.cpp.

int KDoubleSpinBox::mapTextToValue ( bool *  ok  )  [protected, virtual]

Reimplemented from QSpinBox.

Definition at line 1134 of file knuminput.cpp.

QString KDoubleSpinBox::mapValueToText ( int  value  )  [protected, virtual]

Reimplemented from QSpinBox.

Definition at line 1126 of file knuminput.cpp.

double KDoubleSpinBox::maxValue (  )  const

Returns:
the current upper bound

Reimplemented from QSpinBox.

Definition at line 1102 of file knuminput.cpp.

double KDoubleSpinBox::minValue (  )  const

Returns:
the current lower bound

Reimplemented from QSpinBox.

Definition at line 1089 of file knuminput.cpp.

int KDoubleSpinBox::precision (  )  const

Returns:
the current number of digits displayed to the right of the decimal point.

void KDoubleSpinBox::setAcceptLocalizedNumbers ( bool  accept  )  [virtual]

Sets whether to use and accept localized numbers as returned by KLocale::formatNumber().

Definition at line 1027 of file knuminput.cpp.

void KDoubleSpinBox::setLineStep ( double  step  ) 

Sets the step size for clicking the up/down buttons to step, subject to the constraints that step is first rounded to the current precision and then clipped to the meaningful interval [ 1, maxValue() - minValue() ].

Definition at line 1118 of file knuminput.cpp.

void KDoubleSpinBox::setMaxValue ( double  value  ) 

Sets the upper bound of the range to value, subject to the contraints that value is first rounded to the current precision and then clipped to the maximum range interval that can be handled at that precision.

See also:
minValue, maxValue, setMinValue, setRange

Definition at line 1106 of file knuminput.cpp.

void KDoubleSpinBox::setMinValue ( double  value  ) 

Sets the lower bound of the range to value, subject to the contraints that value is first rounded to the current precision and then clipped to the maximum range interval that can be handled at that precision.

See also:
maxValue, minValue, setMaxValue, setRange

Definition at line 1093 of file knuminput.cpp.

void KDoubleSpinBox::setPrecision ( int  precision,
bool  force 
) [virtual]

Sets the precision (number of digits to the right of the decimal point).

Note that there is a tradeoff between the precision used and the available range of values. See the class documentation above for more information on this.

Parameters:
precision the new precision to use
force if true, disables checking of bounds violations that can arise if you increase the precision so much that the minimum and maximum values can't be represented anymore. Disabling is useful if you were going to disable range control in any case.

Definition at line 1050 of file knuminput.cpp.

void KDoubleSpinBox::setPrecision ( int  precision  ) 

Equivalent to setPrecision( precision, false ); Needed since Qt's moc doesn't ignore trailing parameters with default args when searching for a property setter method.

Definition at line 1046 of file knuminput.cpp.

void KDoubleSpinBox::setRange ( double  lower,
double  upper,
double  step = 0.01,
int  precision = 2 
)

Sets a new range for the spin box values.

Note that lower, upper and step are rounded to precision decimal points first.

Definition at line 1032 of file knuminput.cpp.

void KDoubleSpinBox::setValidator ( const QValidator *   ) 

Overridden to ignore any setValidator() calls.

Reimplemented from QSpinBox.

Definition at line 1148 of file knuminput.cpp.

void KDoubleSpinBox::setValue ( double  value  )  [virtual, slot]

Sets the current value to value, subject to the constraints that value is first rounded to the current precision and then clipped to the interval [ minValue() , maxValue() ].

Definition at line 1076 of file knuminput.cpp.

void KDoubleSpinBox::slotValueChanged ( int  value  )  [protected, slot]

Definition at line 1152 of file knuminput.cpp.

double KDoubleSpinBox::value (  )  const

Returns:
the current value

Reimplemented from QSpinBox.

Definition at line 1072 of file knuminput.cpp.

void KDoubleSpinBox::valueChanged ( double  value  )  [signal]

Emitted whenever QSpinBox::valueChanged( int ) is emitted.

void KDoubleSpinBox::virtual_hook ( int  id,
void *  data 
) [protected, virtual]

Definition at line 1177 of file knuminput.cpp.


Property Documentation

bool KDoubleSpinBox::acceptLocalizedNumbers [read, write]

Definition at line 836 of file knuminput.h.

int KDoubleSpinBox::precision [read, write]

Definition at line 841 of file knuminput.h.


The documentation for this class was generated from the following files:
  • knuminput.h
  • knuminput.cpp

kdeui

Skip menu "kdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

API Reference

Skip menu "API Reference"
  • dcop
  • DNSSD
  • interfaces
  • Kate
  • kconf_update
  • KDECore
  • KDED
  • kdefx
  • KDEsu
  • kdeui
  • KDocTools
  • KHTML
  • KImgIO
  • KInit
  • kio
  • kioslave
  • KJS
  • KNewStuff
  • KParts
  • KUtils
Generated for API Reference by doxygen 1.5.9
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal