Public Member Functions | Protected Member Functions

QwtDoubleRange Class Reference

A class which controls a value within an interval. More...

#include <qwt_double_range.h>

Inheritance diagram for QwtDoubleRange:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 QwtDoubleRange ()
virtual ~QwtDoubleRange ()
 Destroys the QwtDoubleRange.
void setRange (double vmin, double vmax, double vstep=0.0, int pagesize=1)
 Specify range and step size.
void setValid (bool)
 Set the value to be valid/invalid.
bool isValid () const
 Indicates if the value is valid.
virtual void setValue (double)
 Set a new value without adjusting to the step raster.
double value () const
 Returns the current value.
void setPeriodic (bool tf)
 Make the range periodic.
bool periodic () const
 Returns true if the range is periodic.
void setStep (double)
 Change the step raster.
double step () const
double maxValue () const
 Returns the value of the second border of the range.
double minValue () const
 Returns the value at the first border of the range.
int pageSize () const
 Returns the page size in steps.
virtual void incValue (int)
 Increment the value by a specified number of steps.
virtual void incPages (int)
 Increment the value by a specified number of pages.
virtual void fitValue (double)
 Adjust the value to the closest point in the step raster.

Protected Member Functions

double exactValue () const
 Returns the exact value.
double exactPrevValue () const
 Returns the exact previous value.
double prevValue () const
 Returns the previous value.
virtual void valueChange ()
 Notify a change of value.
virtual void stepChange ()
 Notify a change of the step size.
virtual void rangeChange ()
 Notify a change of the range.

Detailed Description

A class which controls a value within an interval.

This class is useful as a base class or a member for sliders. It represents an interval of type double within which a value can be moved. The value can be either an arbitrary point inside the interval (see QwtDoubleRange::setValue), or it can be fitted into a step raster (see QwtDoubleRange::fitValue and QwtDoubleRange::incValue).

As a special case, a QwtDoubleRange can be periodic, which means that a value outside the interval will be mapped to a value inside the interval when QwtDoubleRange::setValue(), QwtDoubleRange::fitValue(), QwtDoubleRange::incValue() or QwtDoubleRange::incPages() are called.

Definition at line 31 of file qwt_double_range.h.


Constructor & Destructor Documentation

QwtDoubleRange::QwtDoubleRange (  )

The range is initialized to [0.0, 100.0], the step size to 1.0, and the value to 0.0.

Definition at line 22 of file qwt_double_range.cpp.

                              :
    d_minValue(0.0),
    d_maxValue(0.0),
    d_step(1.0),
    d_pageSize(1),
    d_isValid(false),
    d_value(0.0),
    d_exactValue(0.0),
    d_exactPrevValue(0.0),
    d_prevValue(0.0),
    d_periodic(false)
{
}
QwtDoubleRange::~QwtDoubleRange (  ) [virtual]

Destroys the QwtDoubleRange.

Definition at line 37 of file qwt_double_range.cpp.

{
}

Member Function Documentation

double QwtDoubleRange::exactPrevValue (  ) const [protected]

Returns the exact previous value.

Definition at line 383 of file qwt_double_range.cpp.

Referenced by QwtAbstractSlider::mouseMoveEvent().

{ 
    return d_exactPrevValue; 
}
double QwtDoubleRange::exactValue (  ) const [protected]

Returns the exact value.

The exact value is the value which QwtDoubleRange::value would return if the value were not adjusted to the step raster. It differs from the current value only if QwtDoubleRange::fitValue or QwtDoubleRange::incValue have been used before. This function is intended for internal use in derived classes.

Definition at line 377 of file qwt_double_range.cpp.

Referenced by QwtAbstractSlider::mouseMoveEvent(), and QwtAbstractSlider::timerEvent().

{ 
    return d_exactValue; 
}
void QwtDoubleRange::fitValue ( double  x ) [virtual]

Adjust the value to the closest point in the step raster.

Parameters:
xvalue
Warning:
The value is clipped when it lies outside the range. When the range is QwtDoubleRange::periodic, it will be mapped to a point in the interval such that
new value := x + n * (max. value - min. value)
with an integer number n.

Reimplemented in QwtAbstractSlider.

Definition at line 135 of file qwt_double_range.cpp.

{
    setNewValue(x, true);
}
void QwtDoubleRange::incPages ( int  nPages ) [virtual]

Increment the value by a specified number of pages.

Parameters:
nPagesNumber of pages to increment. A negative number decrements the value.
Warning:
The Page size is specified in the constructor.

Definition at line 274 of file qwt_double_range.cpp.

References isValid().

Referenced by QwtAbstractSlider::mouseReleaseEvent(), QwtAbstractSlider::timerEvent(), and QwtAbstractSlider::wheelEvent().

{
    if ( isValid() )
        setNewValue(d_value + double(nPages) * double(d_pageSize) * d_step, true);
}
void QwtDoubleRange::incValue ( int  nSteps ) [virtual]

Increment the value by a specified number of steps.

Parameters:
nStepsNumber of steps to increment
Warning:
As a result of this operation, the new value will always be adjusted to the step raster.

Reimplemented in QwtAbstractSlider.

Definition at line 262 of file qwt_double_range.cpp.

References isValid().

Referenced by QwtCounter::keyPressEvent(), and QwtCounter::wheelEvent().

{
    if ( isValid() )
        setNewValue(d_value + double(nSteps) * d_step, true);
}
bool QwtDoubleRange::isValid (  ) const

Indicates if the value is valid.

Reimplemented in QwtAbstractSlider.

Definition at line 52 of file qwt_double_range.cpp.

Referenced by incPages(), incValue(), setValid(), and QwtAbstractSlider::setValid().

{
    return d_isValid;
}
double QwtDoubleRange::maxValue (  ) const

Returns the value of the second border of the range.

maxValue returns the value which has been specified as the second parameter in QwtDoubleRange::setRange.

See also:
setRange()

Definition at line 329 of file qwt_double_range.cpp.

Referenced by QwtDial::drawContents(), QwtWheel::drawWheel(), QwtWheel::getValue(), QwtDial::getValue(), QwtDial::keyPressEvent(), QwtCounter::keyPressEvent(), QwtCounter::maxVal(), QwtSlider::rangeChange(), QwtCounter::setMinValue(), QwtCounter::sizeHint(), and QwtDial::updateScale().

{   
    return d_maxValue;
} 
double QwtDoubleRange::minValue (  ) const

Returns the value at the first border of the range.

minValue returns the value which has been specified as the first parameter in setRange().

See also:
setRange()

Definition at line 342 of file qwt_double_range.cpp.

Referenced by QwtDial::drawContents(), QwtWheel::drawWheel(), QwtWheel::getValue(), QwtDial::getValue(), QwtDial::keyPressEvent(), QwtCounter::keyPressEvent(), QwtCounter::minVal(), QwtSlider::rangeChange(), QwtCounter::setMaxValue(), QwtCounter::sizeHint(), and QwtDial::updateScale().

{
    return d_minValue; 
}   
int QwtDoubleRange::pageSize (  ) const

Returns the page size in steps.

Definition at line 357 of file qwt_double_range.cpp.

Referenced by QwtDial::keyPressEvent().

{ 
    return d_pageSize; 
}
bool QwtDoubleRange::periodic (  ) const

Returns true if the range is periodic.

See also:
setPeriodic()

Definition at line 351 of file qwt_double_range.cpp.

{ 
    return d_periodic; 
}
double QwtDoubleRange::prevValue (  ) const [protected]

Returns the previous value.

Definition at line 389 of file qwt_double_range.cpp.

Referenced by QwtDial::keyPressEvent(), QwtAbstractSlider::keyPressEvent(), QwtAbstractSlider::mouseMoveEvent(), and QwtAbstractSlider::wheelEvent().

{ 
    return d_prevValue; 
}
void QwtDoubleRange::rangeChange (  ) [protected, virtual]

Notify a change of the range.

This virtual function is called whenever the range changes. The default implementation does nothing.

Reimplemented in QwtCounter, QwtDial, and QwtSlider.

Definition at line 297 of file qwt_double_range.cpp.

Referenced by setRange().

{
}
void QwtDoubleRange::setPeriodic ( bool  tf )

Make the range periodic.

When the range is periodic, the value will be set to a point inside the interval such that

point = value + n * width 

if the user tries to set a new value which is outside the range. If the range is nonperiodic (the default), values outside the range will be clipped.

Parameters:
tftrue for a periodic range

Definition at line 251 of file qwt_double_range.cpp.

Referenced by QwtDial::setWrapping().

{
    d_periodic = tf;
}
void QwtDoubleRange::setRange ( double  vmin,
double  vmax,
double  vstep = 0.0,
int  pageSize = 1 
)

Specify range and step size.

Parameters:
vminlower boundary of the interval
vmaxhigher boundary of the interval
vstepstep width
pageSizepage size in steps
Warning:
  • A change of the range changes the value if it lies outside the new range. The current value will *not* be adjusted to the new step raster.
  • vmax < vmin is allowed.
  • If the step size is left out or set to zero, it will be set to 1/100 of the interval length.
  • If the step size has an absurd value, it will be corrected to a better one.

Definition at line 172 of file qwt_double_range.cpp.

References qwtAbs, qwtLim(), rangeChange(), and setStep().

Referenced by QwtCounter::setMaxValue(), and QwtCounter::setMinValue().

{
    bool rchg = ((d_maxValue != vmax) || (d_minValue != vmin));
    
    if (rchg) 
    {
        d_minValue = vmin;
        d_maxValue = vmax;
    }
    
    //
    // look if the step width has an acceptable 
    // value or otherwise change it.
    //
    setStep(vstep);

    //
    // limit page size
    //
    d_pageSize = qwtLim(pageSize,0, 
        int(qwtAbs((d_maxValue - d_minValue) / d_step))); 
    
    // 
    // If the value lies out of the range, it 
    // will be changed. Note that it will not be adjusted to 
    // the new step width.
    setNewValue(d_value, false);
    
    // call notifier after the step width has been 
    // adjusted.
    if (rchg)
       rangeChange();
}
void QwtDoubleRange::setStep ( double  vstep )

Change the step raster.

Parameters:
vstepnew step width
Warning:
The value will not be adjusted to the new step raster.

Reimplemented in QwtCounter.

Definition at line 211 of file qwt_double_range.cpp.

References DefaultRelStep, MinRelStep, and stepChange().

Referenced by setRange().

{
    double intv = d_maxValue - d_minValue;
    
    double newStep;
    if (vstep == 0.0)
       newStep = intv * DefaultRelStep;
    else
    {
        if ((intv > 0) && (vstep < 0) || (intv < 0) && (vstep > 0))
           newStep = -vstep;
        else
           newStep = vstep;
        
        if ( fabs(newStep) < fabs(MinRelStep * intv) )
           newStep = MinRelStep * intv;
    }
    
    if (newStep != d_step)
    {
        d_step = newStep;
        stepChange();
    }
}
void QwtDoubleRange::setValid ( bool  isValid )

Set the value to be valid/invalid.

Reimplemented in QwtAbstractSlider.

Definition at line 42 of file qwt_double_range.cpp.

References isValid(), and valueChange().

{
    if ( isValid != d_isValid )
    {
        d_isValid = isValid;
        valueChange();
    }
}
void QwtDoubleRange::setValue ( double  x ) [virtual]

Set a new value without adjusting to the step raster.

Parameters:
xnew value
Warning:
The value is clipped when it lies outside the range. When the range is QwtDoubleRange::periodic, it will be mapped to a point in the interval such that
new value := x + n * (max. value - min. value)
with an integer number n.

Reimplemented in QwtAbstractSlider, and QwtCounter.

Definition at line 150 of file qwt_double_range.cpp.

{
    setNewValue(x, false);
}
double QwtDoubleRange::step (  ) const
Returns:
the step size
See also:
setStep(), setRange()

Reimplemented in QwtCounter.

Definition at line 316 of file qwt_double_range.cpp.

References qwtAbs.

Referenced by QwtAbstractSlider::mouseReleaseEvent(), QwtDial::setScale(), and QwtAbstractSlider::timerEvent().

{
    return qwtAbs(d_step);
}
void QwtDoubleRange::stepChange (  ) [protected, virtual]

Notify a change of the step size.

This virtual function is called whenever the step size changes. The default implementation does nothing.

Definition at line 308 of file qwt_double_range.cpp.

Referenced by setStep().

{
}
double QwtDoubleRange::value (  ) const
void QwtDoubleRange::valueChange (  ) [protected, virtual]

Notify a change of value.

This virtual function is called whenever the value changes. The default implementation does nothing.

Reimplemented in QwtAbstractSlider, QwtDial, QwtSlider, and QwtWheel.

Definition at line 286 of file qwt_double_range.cpp.

Referenced by setValid().

{
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines