Classes | Public Types | Public Member Functions | Protected Member Functions

QwtScaleEngine Class Reference

Base class for scale engines. More...

#include <qwt_scale_engine.h>

Inheritance diagram for QwtScaleEngine:
Inheritance graph
[legend]
Collaboration diagram for QwtScaleEngine:
Collaboration graph
[legend]

List of all members.

Classes

class  PrivateData

Public Types

enum  Attribute {
  NoAttribute = 0, IncludeReference = 1, Symmetric = 2, Floating = 4,
  Inverted = 8
}

Public Member Functions

 QwtScaleEngine ()
 Constructor.
virtual ~QwtScaleEngine ()
 Destructor.
void setAttribute (Attribute, bool on=true)
bool testAttribute (Attribute) const
void setAttributes (int)
int attributes () const
void setReference (double reference)
 Specify a reference point.
double reference () const
void setMargins (double lower, double upper)
 Specify margins at the scale's endpoints.
double lowerMargin () const
double upperMargin () const
virtual void autoScale (int maxNumSteps, double &x1, double &x2, double &stepSize) const =0
virtual QwtScaleDiv divideScale (double x1, double x2, int maxMajSteps, int maxMinSteps, double stepSize=0.0) const =0
 Calculate a scale division.
virtual QwtScaleTransformationtransformation () const =0

Protected Member Functions

bool contains (const QwtDoubleInterval &, double val) const
QwtValueList strip (const QwtValueList &, const QwtDoubleInterval &) const
double divideInterval (double interval, int numSteps) const
QwtDoubleInterval buildInterval (double v) const
 Build an interval for a value.

Detailed Description

Base class for scale engines.

A scale engine trys to find "reasonable" ranges and step sizes for scales.

The layout of the scale can be varied with setAttribute().

Qwt offers implementations for logarithmic (log10) and linear scales. Contributions for other types of scale engines (date/time, log2 ... ) are welcome.

Definition at line 50 of file qwt_scale_engine.h.


Member Enumeration Documentation

  • IncludeReference
    Build a scale which includes the reference() value.
  • Symmetric
    Build a scale which is symmetric to the reference() value.
  • Floating
    The endpoints of the scale are supposed to be equal the outmost included values plus the specified margins (see setMargins()). If this attribute is *not* set, the endpoints of the scale will be integer multiples of the step size.
  • Inverted
    Turn the scale upside down.
See also:
setAttribute(), testAttribute(), reference(), lowerMargin(), upperMargin()
Enumerator:
NoAttribute 
IncludeReference 
Symmetric 
Floating 
Inverted 

Definition at line 69 of file qwt_scale_engine.h.

    {
        NoAttribute = 0,
        IncludeReference = 1, 
        Symmetric = 2, 
        Floating = 4,
        Inverted = 8 
    };

Constructor & Destructor Documentation

QwtScaleEngine::QwtScaleEngine (  ) [explicit]

Constructor.

Definition at line 169 of file qwt_scale_engine.cpp.

{
    d_data = new PrivateData;
}
QwtScaleEngine::~QwtScaleEngine (  ) [virtual]

Destructor.

Definition at line 176 of file qwt_scale_engine.cpp.

{
    delete d_data;
}

Member Function Documentation

int QwtScaleEngine::attributes (  ) const

Return the scale attributes

See also:
Attribute, setAttributes(), testAttribute()

Definition at line 357 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::attributes.

Referenced by QwtLog10ScaleEngine::divideScale(), and setAttributes().

{
    return d_data->attributes;
}
virtual void QwtScaleEngine::autoScale ( int  maxNumSteps,
double &  x1,
double &  x2,
double &  stepSize 
) const [pure virtual]

Align and divide an interval

Parameters:
maxNumStepsMax. number of steps
x1First limit of the interval (In/Out)
x2Second limit of the interval (In/Out)
stepSizeStep size (Return value)

Implemented in QwtLinearScaleEngine, and QwtLog10ScaleEngine.

Referenced by QwtPlot::updateAxes().

QwtDoubleInterval QwtScaleEngine::buildInterval ( double  v ) const [protected]

Build an interval for a value.

In case of v == 0.0 the interval is [-0.5, 0.5], otherwide it is [0.5 * v, 1.5 * v]

Definition at line 309 of file qwt_scale_engine.cpp.

References qwtAbs.

Referenced by QwtLog10ScaleEngine::autoScale(), and QwtLinearScaleEngine::autoScale().

{
    const double delta = (v == 0.0) ? 0.5 : qwtAbs(0.5 * v);
    return QwtDoubleInterval(v - delta, v + delta);
}
bool QwtScaleEngine::contains ( const QwtDoubleInterval interval,
double  value 
) const [protected]

Check if an interval "contains" a value

Parameters:
intervalInterval
valueValue
See also:
QwtScaleArithmetic::compareEps()

Definition at line 251 of file qwt_scale_engine.cpp.

References QwtScaleArithmetic::compareEps(), QwtDoubleInterval::isValid(), QwtDoubleInterval::maxValue(), QwtDoubleInterval::minValue(), and QwtDoubleInterval::width().

Referenced by strip().

{
    if (!interval.isValid() )
        return false;
    
    if ( QwtScaleArithmetic::compareEps(value, 
        interval.minValue(), interval.width()) < 0 )
    {
        return false;
    }

    if ( QwtScaleArithmetic::compareEps(value, 
        interval.maxValue(), interval.width()) > 0 )
    {
        return false;
    }

    return true;
}
double QwtScaleEngine::divideInterval ( double  intervalSize,
int  numSteps 
) const [protected]

Calculate a step size for an interval size

Parameters:
intervalSizeInterval size
numStepsNumber of steps
Returns:
Step size

Definition at line 233 of file qwt_scale_engine.cpp.

References QwtScaleArithmetic::ceil125(), and QwtScaleArithmetic::divideEps().

Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), QwtLog10ScaleEngine::divideScale(), and QwtLinearScaleEngine::divideScale().

{
    if ( numSteps <= 0 )
        return 0.0;

    double v = QwtScaleArithmetic::divideEps(intervalSize, numSteps);
    return QwtScaleArithmetic::ceil125(v);
}
virtual QwtScaleDiv QwtScaleEngine::divideScale ( double  x1,
double  x2,
int  maxMajSteps,
int  maxMinSteps,
double  stepSize = 0.0 
) const [pure virtual]

Calculate a scale division.

Parameters:
x1First interval limit
x2Second interval limit
maxMajStepsMaximum for the number of major steps
maxMinStepsMaximum number of minor steps
stepSizeStep size. If stepSize == 0.0, the scaleEngine calculates one.

Implemented in QwtLinearScaleEngine, and QwtLog10ScaleEngine.

Referenced by QwtAbstractScale::rescale(), and QwtPlot::updateAxes().

double QwtScaleEngine::lowerMargin (  ) const
Returns:
the margin at the lower end of the scale The default margin is 0.
See also:
setMargins()

Definition at line 187 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::lowerMargin.

Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), and QwtLog10ScaleEngine::divideScale().

{ 
    return d_data->lowerMargin; 
}
double QwtScaleEngine::reference (  ) const
void QwtScaleEngine::setAttribute ( Attribute  attribute,
bool  on = true 
)

Change a scale attribute

Parameters:
attributeAttribute to change
onOn/Off
See also:
Attribute, testAttribute()

Definition at line 323 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::attributes.

{
    if (on)
       d_data->attributes |= attribute;
    else
       d_data->attributes &= (~attribute);
}
void QwtScaleEngine::setAttributes ( int  attributes )

Change the scale attribute

Parameters:
attributesSet scale attributes
See also:
Attribute, attributes()

Definition at line 348 of file qwt_scale_engine.cpp.

References attributes(), and QwtScaleEngine::PrivateData::attributes.

Referenced by QwtLog10ScaleEngine::divideScale().

{
    d_data->attributes = attributes;
}
void QwtScaleEngine::setMargins ( double  lower,
double  upper 
)

Specify margins at the scale's endpoints.

Parameters:
lowerminimum distance between the scale's lower boundary and the smallest enclosed value
upperminimum distance between the scale's upper boundary and the greatest enclosed value

Margins can be used to leave a minimum amount of space between the enclosed intervals and the boundaries of the scale.

Warning:
See also:
upperMargin(), lowerMargin()

Definition at line 219 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::lowerMargin, qwtMax, and QwtScaleEngine::PrivateData::upperMargin.

Referenced by QwtLog10ScaleEngine::divideScale().

{
    d_data->lowerMargin = qwtMax(lower, 0.0);
    d_data->upperMargin = qwtMax(upper, 0.0);
}
void QwtScaleEngine::setReference ( double  r )

Specify a reference point.

Parameters:
rnew reference value

The reference point is needed if options IncludeReference or Symmetric are active. Its default value is 0.0.

See also:
Attribute

Definition at line 371 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::referenceValue.

Referenced by QwtLog10ScaleEngine::divideScale().

{
    d_data->referenceValue = r;
}
QwtValueList QwtScaleEngine::strip ( const QwtValueList ticks,
const QwtDoubleInterval interval 
) const [protected]

Remove ticks from a list, that are not inside an interval

Parameters:
ticksTick list
intervalInterval
Returns:
Stripped tick list

Definition at line 280 of file qwt_scale_engine.cpp.

References contains(), int(), and QwtDoubleInterval::isValid().

{
    if ( !interval.isValid() || ticks.count() == 0 )
        return QwtValueList();

    if ( contains(interval, ticks.first())
        && contains(interval, ticks.last()) )
    {
        return ticks;
    }

    QwtValueList strippedTicks;
    for ( int i = 0; i < (int)ticks.count(); i++ )
    {
        if ( contains(interval, ticks[i]) )
            strippedTicks += ticks[i];
    }
    return strippedTicks;
}
bool QwtScaleEngine::testAttribute ( Attribute  attribute ) const

Check if a attribute is set.

Parameters:
attributeAttribute to be tested
See also:
Attribute, setAttribute()

Definition at line 337 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::attributes.

Referenced by QwtLog10ScaleEngine::autoScale(), and QwtLinearScaleEngine::autoScale().

{
    return bool(d_data->attributes & attribute);
}
virtual QwtScaleTransformation* QwtScaleEngine::transformation (  ) const [pure virtual]
Returns:
a transformation

Implemented in QwtLinearScaleEngine, and QwtLog10ScaleEngine.

Referenced by QwtAbstractScale::rescale(), and QwtPlot::updateAxes().

double QwtScaleEngine::upperMargin (  ) const
Returns:
the margin at the upper end of the scale The default margin is 0.
See also:
setMargins()

Definition at line 198 of file qwt_scale_engine.cpp.

References QwtScaleEngine::PrivateData::upperMargin.

Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), and QwtLog10ScaleEngine::divideScale().

{ 
    return d_data->upperMargin; 
}

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