Base class for scale engines. More...
#include <qwt_scale_engine.h>
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 QwtScaleTransformation * | transformation () 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. |
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.
Definition at line 69 of file qwt_scale_engine.h.
{ NoAttribute = 0, IncludeReference = 1, Symmetric = 2, Floating = 4, Inverted = 8 };
QwtScaleEngine::QwtScaleEngine | ( | ) | [explicit] |
QwtScaleEngine::~QwtScaleEngine | ( | ) | [virtual] |
int QwtScaleEngine::attributes | ( | ) | const |
Return the scale attributes
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
maxNumSteps | Max. number of steps |
x1 | First limit of the interval (In/Out) |
x2 | Second limit of the interval (In/Out) |
stepSize | Step 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
interval | Interval |
value | Value |
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
intervalSize | Interval size |
numSteps | Number of steps |
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.
x1 | First interval limit |
x2 | Second interval limit |
maxMajSteps | Maximum for the number of major steps |
maxMinSteps | Maximum number of minor steps |
stepSize | Step 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 |
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 |
Definition at line 380 of file qwt_scale_engine.cpp.
References QwtScaleEngine::PrivateData::referenceValue.
Referenced by QwtLog10ScaleEngine::autoScale(), QwtLinearScaleEngine::autoScale(), and QwtLog10ScaleEngine::divideScale().
{ return d_data->referenceValue; }
void QwtScaleEngine::setAttribute | ( | Attribute | attribute, |
bool | on = true |
||
) |
Change a scale attribute
attribute | Attribute to change |
on | On/Off |
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
attributes | Set scale 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.
lower | minimum distance between the scale's lower boundary and the smallest enclosed value |
upper | minimum 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.
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.
r | new reference value |
The reference point is needed if options IncludeReference or Symmetric are active. Its default value is 0.0.
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
ticks | Tick list |
interval | Interval |
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.
attribute | Attribute to be tested |
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] |
Implemented in QwtLinearScaleEngine, and QwtLog10ScaleEngine.
Referenced by QwtAbstractScale::rescale(), and QwtPlot::updateAxes().
double QwtScaleEngine::upperMargin | ( | ) | const |
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; }