QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
After a scale division has been specified as a QwtScaleDiv object using QwtAbstractScaleDraw::setScaleDiv(const QwtScaleDiv &s), the scale can be drawn with the QwtAbstractScaleDraw::draw() member.
Definition at line 37 of file qwt_abstract_scale_draw.h.
Public Types | |
enum | ScaleComponent { Backbone = 1, Ticks = 2, Labels = 4 } |
Public Member Functions | |
QwtAbstractScaleDraw () | |
QwtAbstractScaleDraw (const QwtAbstractScaleDraw &) | |
virtual | ~QwtAbstractScaleDraw () |
QwtAbstractScaleDraw & | operator= (const QwtAbstractScaleDraw &) |
void | setScaleDiv (const QwtScaleDiv &s) |
const QwtScaleDiv & | scaleDiv () const |
void | setTransformation (QwtScaleTransformation *) |
const QwtScaleMap & | map () const |
void | enableComponent (ScaleComponent, bool enable=true) |
bool | hasComponent (ScaleComponent) const |
void | setTickLength (QwtScaleDiv::TickType, int length) |
int | tickLength (QwtScaleDiv::TickType) const |
int | majTickLength () const |
void | setSpacing (int margin) |
int | spacing () const |
virtual void | draw (QPainter *, const QPalette &) const |
virtual QwtText | label (double) const |
virtual int | extent (const QPen &, const QFont &) const =0 |
void | setMinimumExtent (int) |
int | minimumExtent () const |
QwtScaleMap & | scaleMap () |
Protected Member Functions | |
virtual void | drawTick (QPainter *painter, double value, int len) const =0 |
virtual void | drawBackbone (QPainter *painter) const =0 |
virtual void | drawLabel (QPainter *painter, double value) const =0 |
void | invalidateCache () |
const QwtText & | tickLabel (const QFont &, double value) const |
QwtAbstractScaleDraw::QwtAbstractScaleDraw | ( | ) |
Constructor.
The range of the scale is initialized to [0, 100], The spacing (distance between ticks and labels) is set to 4, the tick lengths are set to 4,6 and 8 pixels
Definition at line 55 of file qwt_abstract_scale_draw.cpp.
QwtAbstractScaleDraw::QwtAbstractScaleDraw | ( | const QwtAbstractScaleDraw & | other | ) |
QwtAbstractScaleDraw::~QwtAbstractScaleDraw | ( | ) | [virtual] |
QwtAbstractScaleDraw & QwtAbstractScaleDraw::operator= | ( | const QwtAbstractScaleDraw & | other | ) |
void QwtAbstractScaleDraw::setScaleDiv | ( | const QwtScaleDiv & | sd | ) |
Change the scale division
sd | New scale division |
Definition at line 108 of file qwt_abstract_scale_draw.cpp.
References QwtScaleDiv::hBound(), and QwtScaleDiv::lBound().
Referenced by QwtAbstractScale::setAbstractScaleDraw(), QwtScaleWidget::setScaleDiv(), and QwtPlotScaleItem::updateScaleDiv().
const QwtScaleDiv & QwtAbstractScaleDraw::scaleDiv | ( | ) | const |
Definition at line 138 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtScaleDraw::maxLabelHeight(), QwtScaleDraw::maxLabelWidth(), QwtScaleDraw::minLabelDist(), QwtScaleDraw::minLength(), QwtScaleWidget::setScaleDiv(), and QwtPlot::sizeHint().
void QwtAbstractScaleDraw::setTransformation | ( | QwtScaleTransformation * | transformation | ) |
Change the transformation of the scale
transformation | New scale transformation |
Definition at line 119 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtPlotScaleItem::draw(), and QwtScaleWidget::setScaleDiv().
const QwtScaleMap & QwtAbstractScaleDraw::map | ( | ) | const |
Definition at line 126 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::drawBackbone(), QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::drawTick(), QwtRoundScaleDraw::drawTick(), QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtSlider::getScrollMode(), QwtScaleDraw::labelPosition(), and QwtScaleWidget::setScaleDiv().
void QwtAbstractScaleDraw::enableComponent | ( | ScaleComponent | component, | |
bool | enable = true | |||
) |
En/Disable a component of the scale
component | Scale component | |
enable | On/Off |
Definition at line 86 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtDial::setScaleOptions().
bool QwtAbstractScaleDraw::hasComponent | ( | ScaleComponent | component | ) | const |
Check if a component is enabled
Definition at line 99 of file qwt_abstract_scale_draw.cpp.
Referenced by draw(), QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtScaleDraw::labelPosition(), QwtPlotLayout::minimumSizeHint(), QwtScaleDraw::minLabelDist(), and QwtScaleDraw::minLength().
void QwtAbstractScaleDraw::setTickLength | ( | QwtScaleDiv::TickType | tickType, | |
int | length | |||
) |
Set the length of the ticks
tickType | Tick type | |
length | New length |
Definition at line 306 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtDial::setScaleTicks().
int QwtAbstractScaleDraw::tickLength | ( | QwtScaleDiv::TickType | tickType | ) | const |
int QwtAbstractScaleDraw::majTickLength | ( | ) | const |
The same as QwtAbstractScaleDraw::tickLength(QwtScaleDiv::MajorTick).
Definition at line 345 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtScaleDraw::labelPosition(), and QwtPlotLayout::minimumSizeHint().
void QwtAbstractScaleDraw::setSpacing | ( | int | spacing | ) |
Set the spacing between tick and labels.
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
spacing | Spacing |
Definition at line 247 of file qwt_abstract_scale_draw.cpp.
int QwtAbstractScaleDraw::spacing | ( | ) | const |
Get the spacing.
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
Definition at line 263 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), and QwtScaleDraw::labelPosition().
void QwtAbstractScaleDraw::draw | ( | QPainter * | painter, | |
const QPalette & | palette | |||
) | const [virtual] |
Draw the scale.
painter | The painter | |
palette | Palette, text color is used for the labels, foreground color for ticks and backbone |
Definition at line 165 of file qwt_abstract_scale_draw.cpp.
References drawBackbone(), drawLabel(), drawTick(), and hasComponent().
Referenced by QwtThermo::draw(), QwtSlider::draw(), QwtPlotScaleItem::draw(), QwtKnob::draw(), and QwtPlot::printScale().
QwtText QwtAbstractScaleDraw::label | ( | double | value | ) | const [virtual] |
Convert a value into its representing label.
The value is converted to a plain text using QLocale::system().toString(value). This method is often overloaded by applications to have individual labels.
value | Value |
Reimplemented in QwtDialScaleDraw.
Definition at line 361 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), QwtDialScaleDraw::label(), and tickLabel().
virtual int QwtAbstractScaleDraw::extent | ( | const QPen & | , | |
const QFont & | ||||
) | const [pure virtual] |
Calculate the extent
The extent is the distcance from the baseline to the outermost pixel of the scale draw in opposite to its orientation. It is at least minimumExtent() pixels.
Implemented in QwtRoundScaleDraw, and QwtScaleDraw.
void QwtAbstractScaleDraw::setMinimumExtent | ( | int | minExtent | ) |
Set a minimum for the extent.
The extent is calculated from the coomponents of the scale draw. In situations, where the labels are changing and the layout depends on the extent (f.e scrolling a scale), setting an upper limit as minimum extent will avoid jumps of the layout.
minExtent | Minimum extent |
Definition at line 281 of file qwt_abstract_scale_draw.cpp.
int QwtAbstractScaleDraw::minimumExtent | ( | ) | const |
Get the minimum extent
Definition at line 293 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtScaleDraw::extent(), and QwtRoundScaleDraw::extent().
QwtScaleMap & QwtAbstractScaleDraw::scaleMap | ( | ) |
Definition at line 132 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtScaleDraw::drawTick(), QwtRoundScaleDraw::QwtRoundScaleDraw(), and QwtRoundScaleDraw::setAngleRange().
virtual void QwtAbstractScaleDraw::drawTick | ( | QPainter * | painter, | |
double | value, | |||
int | len | |||
) | const [protected, pure virtual] |
Draw a tick
painter | Painter | |
value | Value of the tick | |
len | Lenght of the tick |
Implemented in QwtRoundScaleDraw, and QwtScaleDraw.
Referenced by draw().
virtual void QwtAbstractScaleDraw::drawBackbone | ( | QPainter * | painter | ) | const [protected, pure virtual] |
Draws the baseline of the scale
painter | Painter |
Implemented in QwtRoundScaleDraw, and QwtScaleDraw.
Referenced by draw().
virtual void QwtAbstractScaleDraw::drawLabel | ( | QPainter * | painter, | |
double | value | |||
) | const [protected, pure virtual] |
Draws the label for a major scale tick
painter | Painter | |
value | Value |
Implemented in QwtRoundScaleDraw, and QwtScaleDraw.
Referenced by draw().
void QwtAbstractScaleDraw::invalidateCache | ( | ) | [protected] |
Invalidate the cache used by QwtAbstractScaleDraw::tickLabel
The cache is invalidated, when a new QwtScaleDiv is set. If the labels need to be changed. while the same QwtScaleDiv is set, QwtAbstractScaleDraw::invalidateCache needs to be called manually.
Definition at line 404 of file qwt_abstract_scale_draw.cpp.
const QwtText & QwtAbstractScaleDraw::tickLabel | ( | const QFont & | font, | |
double | value | |||
) | const [protected] |
Convert a value into its representing label and cache it.
The conversion between value and label is called very often in the layout and painting code. Unfortunately the calculation of the label sizes might be slow (really slow for rich text in Qt4), so it's necessary to cache the labels.
font | Font | |
value | Value |
Definition at line 379 of file qwt_abstract_scale_draw.cpp.
References label(), QwtText::setLayoutAttribute(), QwtText::setRenderFlags(), and QwtText::textSize().
Referenced by QwtScaleDraw::boundingLabelRect(), QwtScaleDraw::drawLabel(), QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), and QwtScaleDraw::labelRect().