A abstract base class for drawing scales. More...
#include <qwt_abstract_scale_draw.h>
Classes | |
class | PrivateData |
Public Types | |
enum | ScaleComponent { Backbone = 0x01, Ticks = 0x02, Labels = 0x04 } |
Public Member Functions | |
virtual void | draw (QPainter *, const QPalette &) const |
Draw the scale. More... | |
void | enableComponent (ScaleComponent, bool enable=true) |
virtual double | extent (const QFont &font) const =0 |
bool | hasComponent (ScaleComponent) const |
void | invalidateCache () |
virtual QwtText | label (double) const |
Convert a value into its representing label. More... | |
double | maxTickLength () const |
double | minimumExtent () const |
qreal | penWidthF () const |
QwtAbstractScaleDraw () | |
Constructor. More... | |
const QwtScaleDiv & | scaleDiv () const |
QwtScaleMap & | scaleMap () |
const QwtScaleMap & | scaleMap () const |
void | setMinimumExtent (double) |
Set a minimum for the extent. More... | |
void | setPenWidthF (qreal width) |
Specify the width of the scale pen. More... | |
void | setScaleDiv (const QwtScaleDiv &) |
void | setSpacing (double) |
Set the spacing between tick and labels. More... | |
void | setTickLength (QwtScaleDiv::TickType, double length) |
void | setTransformation (QwtTransform *) |
double | spacing () const |
Get the spacing. More... | |
double | tickLength (QwtScaleDiv::TickType) const |
virtual | ~QwtAbstractScaleDraw () |
Destructor. More... | |
Protected Member Functions | |
virtual void | drawBackbone (QPainter *painter) const =0 |
virtual void | drawLabel (QPainter *painter, double value) const =0 |
virtual void | drawTick (QPainter *painter, double value, double len) const =0 |
const QwtText & | tickLabel (const QFont &, double value) const |
Convert a value into its representing label and cache it. More... | |
Private Attributes | |
PrivateData * | m_data |
A abstract base class for drawing scales.
QwtAbstractScaleDraw can be used to draw linear or logarithmic scales.
After a scale division has been specified as a QwtScaleDiv object using setScaleDiv(), the scale can be drawn with the draw() member.
Definition at line 31 of file qwt_abstract_scale_draw.h.
Components of a scale
Enumerator | |
---|---|
Backbone | Backbone = the line where the ticks are located. |
Ticks | Ticks. |
Labels | Labels. |
Definition at line 39 of file qwt_abstract_scale_draw.h.
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 60 of file qwt_abstract_scale_draw.cpp.
|
virtual |
Destructor.
Definition at line 66 of file qwt_abstract_scale_draw.cpp.
|
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 169 of file qwt_abstract_scale_draw.cpp.
|
protectedpure virtual |
Draws the baseline of the scale
painter | Painter |
Implemented in QwtScaleDraw, and QwtRoundScaleDraw.
|
protectedpure virtual |
Draws the label for a major scale tick
painter | Painter |
value | Value |
Implemented in QwtScaleDraw, and QwtRoundScaleDraw.
|
protectedpure virtual |
Draw a tick
painter | Painter |
value | Value of the tick |
len | Length of the tick |
Implemented in QwtScaleDraw, and QwtRoundScaleDraw.
void QwtAbstractScaleDraw::enableComponent | ( | ScaleComponent | component, |
bool | enable = true |
||
) |
En/Disable a component of the scale
component | Scale component |
enable | On/Off |
Definition at line 79 of file qwt_abstract_scale_draw.cpp.
|
pure virtual |
Calculate the extent
The extent is the distance from the baseline to the outermost pixel of the scale draw in opposite to its orientation. It is at least minimumExtent() pixels.
font | Font used for drawing the tick labels |
Implemented in QwtScaleDraw, and QwtRoundScaleDraw.
bool QwtAbstractScaleDraw::hasComponent | ( | ScaleComponent | component | ) | const |
Check if a component is enabled
component | Component type |
Definition at line 95 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::invalidateCache | ( | ) |
Invalidate the cache used by tickLabel()
The cache is invalidated, when a new QwtScaleDiv is set. If the labels need to be changed. while the same QwtScaleDiv is set, invalidateCache() needs to be called manually.
Definition at line 420 of file qwt_abstract_scale_draw.cpp.
|
virtual |
Convert a value into its representing label.
The value is converted to a plain text using QLocale().toString(value). This method is often overloaded by applications to have individual labels.
value | Value |
Reimplemented in QwtDateScaleDraw, QwtCompassScaleDraw, and TimeScaleDraw.
Definition at line 375 of file qwt_abstract_scale_draw.cpp.
double QwtAbstractScaleDraw::maxTickLength | ( | ) | const |
Useful for layout calculations
Definition at line 355 of file qwt_abstract_scale_draw.cpp.
double QwtAbstractScaleDraw::minimumExtent | ( | ) | const |
Get the minimum extent
Definition at line 302 of file qwt_abstract_scale_draw.cpp.
qreal QwtAbstractScaleDraw::penWidthF | ( | ) | const |
Definition at line 156 of file qwt_abstract_scale_draw.cpp.
const QwtScaleDiv & QwtAbstractScaleDraw::scaleDiv | ( | ) | const |
Definition at line 133 of file qwt_abstract_scale_draw.cpp.
QwtScaleMap& QwtAbstractScaleDraw::scaleMap | ( | ) |
QwtScaleMap & QwtAbstractScaleDraw::scaleMap | ( | ) | const |
Definition at line 121 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setMinimumExtent | ( | double | minExtent | ) |
Set a minimum for the extent.
The extent is calculated from the components 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 289 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setPenWidthF | ( | qreal | width | ) |
Specify the width of the scale pen.
width | Pen width |
Definition at line 144 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setScaleDiv | ( | const QwtScaleDiv & | scaleDiv | ) |
Change the scale division
scaleDiv | New scale division |
Definition at line 104 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setSpacing | ( | double | 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 254 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setTickLength | ( | QwtScaleDiv::TickType | tickType, |
double | length | ||
) |
Set the length of the ticks
tickType | Tick type |
length | New length |
Definition at line 315 of file qwt_abstract_scale_draw.cpp.
void QwtAbstractScaleDraw::setTransformation | ( | QwtTransform * | transformation | ) |
Change the transformation of the scale
transformation | New scale transformation |
Definition at line 115 of file qwt_abstract_scale_draw.cpp.
double QwtAbstractScaleDraw::spacing | ( | ) | const |
Get the spacing.
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
Definition at line 271 of file qwt_abstract_scale_draw.cpp.
|
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 396 of file qwt_abstract_scale_draw.cpp.
double QwtAbstractScaleDraw::tickLength | ( | QwtScaleDiv::TickType | tickType | ) | const |
Definition at line 338 of file qwt_abstract_scale_draw.cpp.
|
private |
Definition at line 134 of file qwt_abstract_scale_draw.h.