A abstract base class for drawing scales. More...
#include <qwt_abstract_scale_draw.h>
Classes | |
class | PrivateData |
Public Types | |
enum | ScaleComponent { Backbone = 1, Ticks = 2, Labels = 4 } |
Public Member Functions | |
QwtAbstractScaleDraw () | |
Constructor. | |
QwtAbstractScaleDraw (const QwtAbstractScaleDraw &) | |
Copy constructor. | |
virtual | ~QwtAbstractScaleDraw () |
Destructor. | |
QwtAbstractScaleDraw & | operator= (const QwtAbstractScaleDraw &) |
Assignment operator. | |
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) |
Set the spacing between tick and labels. | |
int | spacing () const |
Get the spacing. | |
virtual void | draw (QPainter *, const QColorGroup &) const |
Draw the scale. | |
virtual QwtText | label (double) const |
Convert a value into its representing label. | |
virtual int | extent (const QPen &, const QFont &) const =0 |
void | setMinimumExtent (int) |
Set a minimum for the extent. | |
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 |
Convert a value into its representing label and cache it. |
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 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.
Components of a scale
Definition at line 51 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 55 of file qwt_abstract_scale_draw.cpp.
{ d_data = new QwtAbstractScaleDraw::PrivateData; }
QwtAbstractScaleDraw::QwtAbstractScaleDraw | ( | const QwtAbstractScaleDraw & | other ) |
Copy constructor.
Definition at line 61 of file qwt_abstract_scale_draw.cpp.
{ d_data = new QwtAbstractScaleDraw::PrivateData(*other.d_data); }
QwtAbstractScaleDraw::~QwtAbstractScaleDraw | ( | ) | [virtual] |
void QwtAbstractScaleDraw::draw | ( | QPainter * | painter, |
const QColorGroup & | colorGroup | ||
) | const [virtual] |
Draw the scale.
painter | The painter |
colorGroup | Color group, text color is used for the labels, foreground color for ticks and backbone |
Definition at line 152 of file qwt_abstract_scale_draw.cpp.
References Backbone, int(), Labels, QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, QwtScaleDiv::NTickTypes, and Ticks.
Referenced by QwtThermo::draw(), QwtSlider::draw(), QwtScaleWidget::draw(), QwtPlotScaleItem::draw(), QwtKnob::draw(), QwtDial::drawScale(), and QwtPlot::printScale().
{ if ( hasComponent(QwtAbstractScaleDraw::Labels) ) { painter->save(); #if QT_VERSION < 0x040000 painter->setPen(colorGroup.text()); // ignore pen style #else painter->setPen(palette.color(QPalette::Text)); // ignore pen style #endif const QwtValueList &majorTicks = d_data->scldiv.ticks(QwtScaleDiv::MajorTick); for (int i = 0; i < (int)majorTicks.count(); i++) { const double v = majorTicks[i]; if ( d_data->scldiv.contains(v) ) drawLabel(painter, majorTicks[i]); } painter->restore(); } if ( hasComponent(QwtAbstractScaleDraw::Ticks) ) { painter->save(); QPen pen = painter->pen(); #if QT_VERSION < 0x040000 pen.setColor(colorGroup.foreground()); #else pen.setColor(palette.color(QPalette::Foreground)); #endif painter->setPen(pen); for ( int tickType = QwtScaleDiv::MinorTick; tickType < QwtScaleDiv::NTickTypes; tickType++ ) { const QwtValueList &ticks = d_data->scldiv.ticks(tickType); for (int i = 0; i < (int)ticks.count(); i++) { const double v = ticks[i]; if ( d_data->scldiv.contains(v) ) drawTick(painter, v, d_data->tickLength[tickType]); } } painter->restore(); } if ( hasComponent(QwtAbstractScaleDraw::Backbone) ) { painter->save(); QPen pen = painter->pen(); #if QT_VERSION < 0x040000 pen.setColor(colorGroup.foreground()); #else pen.setColor(palette.color(QPalette::Foreground)); #endif painter->setPen(pen); drawBackbone(painter); painter->restore(); } }
virtual void QwtAbstractScaleDraw::drawBackbone | ( | QPainter * | painter ) | const [protected, pure virtual] |
Draws the baseline of the scale
painter | Painter |
Implemented in QwtRoundScaleDraw, and QwtScaleDraw.
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.
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.
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.
References QwtAbstractScaleDraw::PrivateData::components.
Referenced by QwtDial::setScaleOptions().
{ if ( enable ) d_data->components |= component; else d_data->components &= ~component; }
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.
bool QwtAbstractScaleDraw::hasComponent | ( | ScaleComponent | component ) | const |
Check if a component is enabled
Definition at line 99 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::components.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtPlotLayout::LayoutData::init(), QwtScaleDraw::labelPosition(), QwtPlotLayout::minimumSizeHint(), QwtScaleDraw::minLabelDist(), and QwtScaleDraw::minLength().
{ return (d_data->components & component); }
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 403 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::labelCache.
{ d_data->labelCache.clear(); }
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 360 of file qwt_abstract_scale_draw.cpp.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), and tickLabel().
{
return QLocale::system().toString(value);
}
int QwtAbstractScaleDraw::majTickLength | ( | ) | const |
The same as QwtAbstractScaleDraw::tickLength(QwtScaleDiv::MajorTick).
Definition at line 344 of file qwt_abstract_scale_draw.cpp.
References QwtScaleDiv::MajorTick, and QwtAbstractScaleDraw::PrivateData::tickLength.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtPlotLayout::LayoutData::init(), QwtScaleDraw::labelPosition(), and QwtPlotLayout::minimumSizeHint().
{ return d_data->tickLength[QwtScaleDiv::MajorTick]; }
const QwtScaleMap & QwtAbstractScaleDraw::map | ( | ) | const |
Definition at line 126 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::map.
Referenced by QwtRoundScaleDraw::drawBackbone(), QwtScaleWidget::drawColorBar(), QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::drawTick(), QwtRoundScaleDraw::drawTick(), QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtSlider::getScrollMode(), QwtScaleDraw::labelPosition(), and QwtScaleWidget::setScaleDiv().
{ return d_data->map; }
int QwtAbstractScaleDraw::minimumExtent | ( | ) | const |
Get the minimum extent
Definition at line 293 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::minExtent.
Referenced by QwtScaleDraw::extent(), and QwtRoundScaleDraw::extent().
{ return d_data->minExtent; }
QwtAbstractScaleDraw & QwtAbstractScaleDraw::operator= | ( | const QwtAbstractScaleDraw & | other ) |
Assignment operator.
Definition at line 72 of file qwt_abstract_scale_draw.cpp.
{ *d_data = *other.d_data; return *this; }
const QwtScaleDiv & QwtAbstractScaleDraw::scaleDiv | ( | ) | const |
Definition at line 138 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::scldiv.
Referenced by QwtRoundScaleDraw::extent(), QwtScaleDraw::getBorderDistHint(), QwtScaleDraw::maxLabelHeight(), QwtScaleDraw::maxLabelWidth(), QwtScaleDraw::minLabelDist(), QwtScaleDraw::minLength(), QwtAbstractScale::rescale(), QwtPlotScaleItem::scaleDiv(), QwtAbstractScale::setAbstractScaleDraw(), QwtAbstractScale::setScale(), QwtScaleWidget::setScaleDiv(), and QwtPlot::sizeHint().
{ return d_data->scldiv; }
QwtScaleMap & QwtAbstractScaleDraw::scaleMap | ( | ) |
Definition at line 132 of file qwt_abstract_scale_draw.cpp.
References QwtAbstractScaleDraw::PrivateData::map.
Referenced by QwtScaleDraw::drawTick(), QwtRoundScaleDraw::QwtRoundScaleDraw(), QwtAbstractScale::scaleMap(), and QwtRoundScaleDraw::setAngleRange().
{ return d_data->map; }
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.
References QwtAbstractScaleDraw::PrivateData::minExtent.
{ if ( minExtent < 0 ) minExtent = 0; d_data->minExtent = minExtent; }
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 QwtAbstractScaleDraw::PrivateData::labelCache, QwtScaleDiv::lowerBound(), QwtAbstractScaleDraw::PrivateData::map, QwtAbstractScaleDraw::PrivateData::scldiv, QwtScaleMap::setScaleInterval(), and QwtScaleDiv::upperBound().
Referenced by QwtAbstractScale::rescale(), QwtAbstractScale::setAbstractScaleDraw(), QwtAbstractScale::setScale(), QwtScaleWidget::setScaleDiv(), QwtPlotScaleItem::setScaleDiv(), QwtDial::updateScale(), and QwtPlotScaleItem::updateScaleDiv().
{ d_data->scldiv = sd; d_data->map.setScaleInterval(sd.lowerBound(), sd.upperBound()); d_data->labelCache.clear(); }
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.
References spacing(), and QwtAbstractScaleDraw::PrivateData::spacing.
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.
References QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, and QwtAbstractScaleDraw::PrivateData::tickLength.
Referenced by QwtDial::setScaleTicks().
{ if ( tickType < QwtScaleDiv::MinorTick || tickType > QwtScaleDiv::MajorTick ) { return; } if ( length < 0 ) length = 0; const int maxTickLen = 1000; if ( length > maxTickLen ) length = 1000; d_data->tickLength[tickType] = length; }
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.
References QwtAbstractScaleDraw::PrivateData::map, and QwtScaleMap::setTransformation().
Referenced by QwtPlotScaleItem::draw(), QwtAbstractScale::rescale(), QwtScaleWidget::setScaleDiv(), and QwtDial::updateScale().
{ d_data->map.setTransformation(transformation); }
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.
References QwtAbstractScaleDraw::PrivateData::spacing.
Referenced by QwtRoundScaleDraw::drawLabel(), QwtScaleDraw::extent(), QwtRoundScaleDraw::extent(), QwtScaleDraw::labelPosition(), and setSpacing().
{ return d_data->spacing; }
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 378 of file qwt_abstract_scale_draw.cpp.
References label(), QwtAbstractScaleDraw::PrivateData::labelCache, QwtText::MinimumLayout, QwtText::setLayoutAttribute(), QwtText::setRenderFlags(), QwtText::textSize(), and void().
Referenced by QwtScaleDraw::boundingLabelRect(), QwtScaleDraw::drawLabel(), QwtRoundScaleDraw::drawLabel(), QwtRoundScaleDraw::extent(), and QwtScaleDraw::labelRect().
{ QMap<double, QwtText>::const_iterator it = d_data->labelCache.find(value); if ( it == d_data->labelCache.end() ) { QwtText lbl = label(value); lbl.setRenderFlags(0); lbl.setLayoutAttribute(QwtText::MinimumLayout); (void)lbl.textSize(font); // initialize the internal cache it = d_data->labelCache.insert(value, lbl); } return (*it); }
int QwtAbstractScaleDraw::tickLength | ( | QwtScaleDiv::TickType | tickType ) | const |
Return the length of the ticks
Definition at line 330 of file qwt_abstract_scale_draw.cpp.
References QwtScaleDiv::MajorTick, QwtScaleDiv::MinorTick, and QwtAbstractScaleDraw::PrivateData::tickLength.
{ if ( tickType < QwtScaleDiv::MinorTick || tickType > QwtScaleDiv::MajorTick ) { return 0; } return d_data->tickLength[tickType]; }