Qwt User's Guide
svn
|
#include <qwt_scale_draw.h>
Inherits QwtAbstractScaleDraw.
Public Types | |
enum | Alignment { BottomScale, TopScale, LeftScale, RightScale } |
enum | ScaleComponent { Backbone = 0x01, Ticks = 0x02, Labels = 0x04 } |
typedef QFlags< ScaleComponent > | ScaleComponents |
Public Member Functions | |
Alignment | alignment () const |
QRect | boundingLabelRect (const QFont &, double val) const |
virtual void | draw (QPainter *, const QPalette &) const |
void | enableComponent (ScaleComponent, bool enable=true) |
virtual double | extent (const QFont &) const |
void | getBorderDistHint (const QFont &, int &start, int &end) const |
bool | hasComponent (ScaleComponent) const |
virtual QwtText | label (double) const |
Qt::Alignment | labelAlignment () const |
QPointF | labelPosition (double val) const |
QRectF | labelRect (const QFont &, double val) const |
double | labelRotation () const |
QSizeF | labelSize (const QFont &, double val) const |
double | length () const |
int | maxLabelHeight (const QFont &) const |
int | maxLabelWidth (const QFont &) const |
double | maxTickLength () const |
double | minimumExtent () const |
int | minLabelDist (const QFont &) const |
int | minLength (const QFont &) const |
void | move (double x, double y) |
void | move (const QPointF &) |
Qt::Orientation | orientation () const |
int | penWidth () const |
QPointF | pos () const |
QwtScaleDraw () | |
const QwtScaleDiv & | scaleDiv () const |
const QwtScaleMap & | scaleMap () const |
QwtScaleMap & | scaleMap () |
void | setAlignment (Alignment) |
void | setLabelAlignment (Qt::Alignment) |
void | setLabelRotation (double rotation) |
void | setLength (double length) |
void | setMinimumExtent (double) |
void | setPenWidth (int width) |
void | setScaleDiv (const QwtScaleDiv &s) |
void | setSpacing (double margin) |
void | setTickLength (QwtScaleDiv::TickType, double length) |
void | setTransformation (QwtScaleTransformation *) |
double | spacing () const |
double | tickLength (QwtScaleDiv::TickType) const |
virtual | ~QwtScaleDraw () |
Protected Member Functions | |
virtual void | drawBackbone (QPainter *) const |
virtual void | drawLabel (QPainter *, double val) const |
virtual void | drawTick (QPainter *, double val, double len) const |
void | invalidateCache () |
QTransform | labelTransformation (const QPointF &, const QSizeF &) const |
const QwtText & | tickLabel (const QFont &, double value) const |
A class for drawing scales.
QwtScaleDraw can be used to draw linear or logarithmic scales. A scale has a position, an alignment and a length, which can be specified . The labels can be rotated and aligned to the ticks using setLabelRotation() and setLabelAlignment().
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.
typedef QFlags<ScaleComponent> QwtAbstractScaleDraw::ScaleComponents [inherited] |
Scale components.
Alignment of the scale draw
enum QwtAbstractScaleDraw::ScaleComponent [inherited] |
Components of a scale
QwtScaleDraw::QwtScaleDraw | ( | ) |
Constructor.
The range of the scale is initialized to [0, 100], The position is at (0, 0) with a length of 100. The orientation is QwtAbstractScaleDraw::Bottom.
QwtScaleDraw::~QwtScaleDraw | ( | ) | [virtual] |
Destructor.
QwtScaleDraw::Alignment QwtScaleDraw::alignment | ( | ) | const |
Return alignment of the scale
QRect QwtScaleDraw::boundingLabelRect | ( | const QFont & | font, |
double | value | ||
) | const |
Find the bounding rect for the label. The coordinates of the rect are absolute coordinates ( calculated from pos() ). in direction of the tick.
font | Font used for painting |
value | Value |
void QwtAbstractScaleDraw::draw | ( | QPainter * | painter, |
const QPalette & | palette | ||
) | const [virtual, inherited] |
Draw the scale.
painter | The painter |
palette | Palette, text color is used for the labels, foreground color for ticks and backbone |
void QwtScaleDraw::drawBackbone | ( | QPainter * | painter | ) | const [protected, virtual] |
Draws the baseline of the scale
painter | Painter |
Implements QwtAbstractScaleDraw.
void QwtScaleDraw::drawLabel | ( | QPainter * | painter, |
double | value | ||
) | const [protected, virtual] |
Draws the label for a major scale tick
painter | Painter |
value | Value |
Implements QwtAbstractScaleDraw.
void QwtScaleDraw::drawTick | ( | QPainter * | painter, |
double | value, | ||
double | len | ||
) | const [protected, virtual] |
Draw a tick
painter | Painter |
value | Value of the tick |
len | Lenght of the tick |
Implements QwtAbstractScaleDraw.
void QwtAbstractScaleDraw::enableComponent | ( | ScaleComponent | component, |
bool | enable = true |
||
) | [inherited] |
En/Disable a component of the scale
component | Scale component |
enable | On/Off |
double QwtScaleDraw::extent | ( | const QFont & | font | ) | const [virtual] |
Calculate the width/height that is needed for a vertical/horizontal scale.
The extent is calculated from the pen width of the backbone, the major tick length, the spacing and the maximum width/height of the labels.
font | Font used for painting the labels |
Implements QwtAbstractScaleDraw.
void QwtScaleDraw::getBorderDistHint | ( | const QFont & | font, |
int & | start, | ||
int & | end | ||
) | const |
Determine the minimum border distance.
This member function returns the minimum space needed to draw the mark labels at the scale's endpoints.
font | Font |
start | Start border distance |
end | End border distance |
bool QwtAbstractScaleDraw::hasComponent | ( | ScaleComponent | component | ) | const [inherited] |
Check if a component is enabled
void QwtAbstractScaleDraw::invalidateCache | ( | ) | [protected, inherited] |
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, invalidateCache() needs to be called manually.
QwtText QwtAbstractScaleDraw::label | ( | double | value | ) | const [virtual, inherited] |
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.
Qt::Alignment QwtScaleDraw::labelAlignment | ( | ) | const |
QPointF QwtScaleDraw::labelPosition | ( | double | value | ) | const |
Find the position, where to paint a label
The position has a distance of majTickLength() + spacing() + 1 from the backbone. The direction depends on the alignment()
value | Value |
QRectF QwtScaleDraw::labelRect | ( | const QFont & | font, |
double | value | ||
) | const |
Find the bounding rect for the label. The coordinates of the rect are relative to spacing + ticklength from the backbone in direction of the tick.
font | Font used for painting |
value | Value |
double QwtScaleDraw::labelRotation | ( | ) | const |
QSizeF QwtScaleDraw::labelSize | ( | const QFont & | font, |
double | value | ||
) | const |
Calculate the size that is needed to draw a label
font | Label font |
value | Value |
QTransform QwtScaleDraw::labelTransformation | ( | const QPointF & | pos, |
const QSizeF & | size | ||
) | const [protected] |
Calculate the transformation that is needed to paint a label depending on its alignment and rotation.
pos | Position where to paint the label |
size | Size of the label |
double QwtScaleDraw::length | ( | ) | const |
int QwtScaleDraw::maxLabelHeight | ( | const QFont & | font | ) | const |
font | Font |
int QwtScaleDraw::maxLabelWidth | ( | const QFont & | font | ) | const |
font | Font |
double QwtAbstractScaleDraw::maxTickLength | ( | ) | const [inherited] |
Useful for layout calculations
double QwtAbstractScaleDraw::minimumExtent | ( | ) | const [inherited] |
Get the minimum extent
int QwtScaleDraw::minLabelDist | ( | const QFont & | font | ) | const |
Determine the minimum distance between two labels, that is necessary that the texts don't overlap.
font | Font |
int QwtScaleDraw::minLength | ( | const QFont & | font | ) | const |
Calculate the minimum length that is needed to draw the scale
font | Font used for painting the labels |
void QwtScaleDraw::move | ( | double | x, |
double | y | ||
) | [inline] |
Move the position of the scale
void QwtScaleDraw::move | ( | const QPointF & | pos | ) |
Move the position of the scale.
The meaning of the parameter pos depends on the alignment:
pos | Origin of the scale |
Qt::Orientation QwtScaleDraw::orientation | ( | ) | const |
Return the orientation
TopScale, BottomScale are horizontal (Qt::Horizontal) scales, LeftScale, RightScale are vertical (Qt::Vertical) scales.
int QwtAbstractScaleDraw::penWidth | ( | ) | const [inherited] |
const QwtScaleDiv & QwtAbstractScaleDraw::scaleDiv | ( | ) | const [inherited] |
const QwtScaleMap & QwtAbstractScaleDraw::scaleMap | ( | ) | const [inherited] |
QwtScaleMap & QwtAbstractScaleDraw::scaleMap | ( | ) | [inherited] |
void QwtScaleDraw::setAlignment | ( | Alignment | align | ) |
Set the alignment of the scale
The default alignment is QwtScaleDraw::BottomScale
void QwtScaleDraw::setLabelAlignment | ( | Qt::Alignment | alignment | ) |
Change the label flags.
Labels are aligned to the point ticklength + spacing away from the backbone.
The alignment is relative to the orientation of the label text. In case of an flags of 0 the label will be aligned depending on the orientation of the scale:
QwtScaleDraw::TopScale: Qt::AlignHCenter | Qt::AlignTop
QwtScaleDraw::BottomScale: Qt::AlignHCenter | Qt::AlignBottom
QwtScaleDraw::LeftScale: Qt::AlignLeft | Qt::AlignVCenter
QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter
Changing the alignment is often necessary for rotated labels.
alignment | Or'd Qt::AlignmentFlags see <qnamespace.h> |
void QwtScaleDraw::setLabelRotation | ( | double | rotation | ) |
Rotate all labels.
When changing the rotation, it might be necessary to adjust the label flags too. Finding a useful combination is often the result of try and error.
rotation | Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too. |
void QwtScaleDraw::setLength | ( | double | length | ) |
Set the length of the backbone.
The length doesn't include the space needed for overlapping labels.
void QwtAbstractScaleDraw::setMinimumExtent | ( | double | minExtent | ) | [inherited] |
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 |
void QwtAbstractScaleDraw::setPenWidth | ( | int | width | ) | [inherited] |
void QwtAbstractScaleDraw::setScaleDiv | ( | const QwtScaleDiv & | sd | ) | [inherited] |
Change the scale division
sd | New scale division |
void QwtAbstractScaleDraw::setSpacing | ( | double | spacing | ) | [inherited] |
Set the spacing between tick and labels.
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
spacing | Spacing |
void QwtAbstractScaleDraw::setTickLength | ( | QwtScaleDiv::TickType | tickType, |
double | length | ||
) | [inherited] |
Set the length of the ticks
tickType | Tick type |
length | New length |
void QwtAbstractScaleDraw::setTransformation | ( | QwtScaleTransformation * | transformation | ) | [inherited] |
Change the transformation of the scale
transformation | New scale transformation |
double QwtAbstractScaleDraw::spacing | ( | ) | const [inherited] |
Get the spacing.
The spacing is the distance between ticks and labels. The default spacing is 4 pixels.
const QwtText & QwtAbstractScaleDraw::tickLabel | ( | const QFont & | font, |
double | value | ||
) | const [protected, inherited] |
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 |
double QwtAbstractScaleDraw::tickLength | ( | QwtScaleDiv::TickType | tickType | ) | const [inherited] |
Return the length of the ticks