A class for drawing scales. More...
#include <qwt_scale_draw.h>
Classes | |
class | PrivateData |
Public Types | |
enum | Alignment { BottomScale, TopScale, LeftScale, RightScale } |
Public Types inherited from QwtAbstractScaleDraw | |
enum | ScaleComponent { Backbone = 0x01, Ticks = 0x02, Labels = 0x04 } |
typedef QFlags< ScaleComponent > | ScaleComponents |
Scale components. More... | |
Public Member Functions | |
Alignment | alignment () const |
QRect | boundingLabelRect (const QFont &, double val) const |
Find the bounding rectangle for the label. More... | |
virtual double | extent (const QFont &) const |
void | getBorderDistHint (const QFont &, int &start, int &end) const |
Determine the minimum border distance. More... | |
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 |
int | minLabelDist (const QFont &) const |
int | minLength (const QFont &) const |
void | move (double x, double y) |
void | move (const QPointF &) |
Move the position of the scale. More... | |
Qt::Orientation | orientation () const |
QPointF | pos () const |
QwtScaleDraw () | |
Constructor. More... | |
void | setAlignment (Alignment) |
void | setLabelAlignment (Qt::Alignment) |
Change the label flags. More... | |
void | setLabelRotation (double rotation) |
void | setLength (double length) |
virtual | ~QwtScaleDraw () |
Destructor. More... | |
Public Member Functions inherited from QwtAbstractScaleDraw | |
virtual void | draw (QPainter *, const QPalette &) const |
Draw the scale. More... | |
void | enableComponent (ScaleComponent, bool enable=true) |
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 |
int | penWidth () const |
QwtAbstractScaleDraw () | |
Constructor. More... | |
const QwtScaleDiv & | scaleDiv () const |
const QwtScaleMap & | scaleMap () const |
QwtScaleMap & | scaleMap () |
void | setMinimumExtent (double) |
Set a minimum for the extent. More... | |
void | setPenWidth (int width) |
Specify the width of the scale pen. More... | |
void | setScaleDiv (const QwtScaleDiv &s) |
void | setSpacing (double margin) |
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 *) const |
virtual void | drawLabel (QPainter *, double val) const |
virtual void | drawTick (QPainter *, double val, double len) const |
QTransform | labelTransformation (const QPointF &, const QSizeF &) const |
Protected Member Functions inherited from QwtAbstractScaleDraw | |
const QwtText & | tickLabel (const QFont &, double value) const |
Convert a value into its representing label and cache it. More... | |
Private Member Functions | |
void | updateMap () |
Private Attributes | |
PrivateData * | d_data |
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.
Definition at line 31 of file qwt_scale_draw.h.
Alignment of the scale draw
Enumerator | |
---|---|
BottomScale |
The scale is below. |
TopScale |
The scale is above. |
LeftScale |
The scale is left. |
RightScale |
The scale is right. |
Definition at line 38 of file qwt_scale_draw.h.
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.
Definition at line 51 of file qwt_scale_draw.cpp.
|
virtual |
Destructor.
Definition at line 58 of file qwt_scale_draw.cpp.
QwtScaleDraw::Alignment QwtScaleDraw::alignment | ( | ) | const |
Return alignment of the scale
Definition at line 68 of file qwt_scale_draw.cpp.
QRect QwtScaleDraw::boundingLabelRect | ( | const QFont & | font, |
double | value | ||
) | const |
Find the bounding rectangle for the label.
The coordinates of the rectangle are absolute ( calculated from pos() ). in direction of the tick.
font | Font used for painting |
value | Value |
Definition at line 681 of file qwt_scale_draw.cpp.
|
protectedvirtual |
Draws the baseline of the scale
painter | Painter |
Implements QwtAbstractScaleDraw.
Definition at line 493 of file qwt_scale_draw.cpp.
|
protectedvirtual |
Draws the label for a major scale tick
painter | Painter |
value | Value |
Implements QwtAbstractScaleDraw.
Definition at line 649 of file qwt_scale_draw.cpp.
|
protectedvirtual |
Draw a tick
painter | Painter |
value | Value of the tick |
len | Length of the tick |
Implements QwtAbstractScaleDraw.
Definition at line 409 of file qwt_scale_draw.cpp.
|
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.
Definition at line 282 of file qwt_scale_draw.cpp.
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 |
Definition at line 120 of file qwt_scale_draw.cpp.
Qt::Alignment QwtScaleDraw::labelAlignment | ( | ) | const |
Definition at line 865 of file qwt_scale_draw.cpp.
QPointF QwtScaleDraw::labelPosition | ( | double | value | ) | const |
Find the position, where to paint a label
The position has a distance that depends on the length of the ticks in direction of the alignment().
value | Value |
Definition at line 356 of file qwt_scale_draw.cpp.
QRectF QwtScaleDraw::labelRect | ( | const QFont & | font, |
double | value | ||
) | const |
Find the bounding rectangle for the label. The coordinates of the rectangle are relative to spacing + tick length from the backbone in direction of the tick.
font | Font used for painting |
value | Value |
Definition at line 774 of file qwt_scale_draw.cpp.
double QwtScaleDraw::labelRotation | ( | ) | const |
Definition at line 826 of file qwt_scale_draw.cpp.
QSizeF QwtScaleDraw::labelSize | ( | const QFont & | font, |
double | value | ||
) | const |
Calculate the size that is needed to draw a label
font | Label font |
value | Value |
Definition at line 799 of file qwt_scale_draw.cpp.
|
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 |
Definition at line 704 of file qwt_scale_draw.cpp.
double QwtScaleDraw::length | ( | ) | const |
Definition at line 636 of file qwt_scale_draw.cpp.
int QwtScaleDraw::maxLabelHeight | ( | const QFont & | font | ) | const |
font | Font |
Definition at line 897 of file qwt_scale_draw.cpp.
int QwtScaleDraw::maxLabelWidth | ( | const QFont & | font | ) | const |
font | Font |
Definition at line 874 of file qwt_scale_draw.cpp.
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 |
Definition at line 195 of file qwt_scale_draw.cpp.
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 |
Definition at line 320 of file qwt_scale_draw.cpp.
|
inline |
Move the position of the scale
x | X coordinate |
y | Y coordinate |
Definition at line 112 of file qwt_scale_draw.h.
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 |
Definition at line 590 of file qwt_scale_draw.cpp.
Qt::Orientation QwtScaleDraw::orientation | ( | ) | const |
Return the orientation
TopScale, BottomScale are horizontal (Qt::Horizontal) scales, LeftScale, RightScale are vertical (Qt::Vertical) scales.
Definition at line 96 of file qwt_scale_draw.cpp.
QPointF QwtScaleDraw::pos | ( | ) | const |
Definition at line 600 of file qwt_scale_draw.cpp.
void QwtScaleDraw::setAlignment | ( | Alignment | align | ) |
Set the alignment of the scale
align | Alignment of the scale |
The default alignment is QwtScaleDraw::BottomScale
Definition at line 81 of file qwt_scale_draw.cpp.
void QwtScaleDraw::setLabelAlignment | ( | Qt::Alignment | alignment | ) |
Change the label flags.
Labels are aligned to the point tick length + 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\n QwtScaleDraw::BottomScale: Qt::AlignHCenter | Qt::AlignBottom\n QwtScaleDraw::LeftScale: Qt::AlignLeft | Qt::AlignVCenter\n QwtScaleDraw::RightScale: Qt::AlignRight | Qt::AlignVCenter\n
Changing the alignment is often necessary for rotated labels.
alignment | Or'd Qt::AlignmentFlags see <qnamespace.h> |
Definition at line 856 of file qwt_scale_draw.cpp.
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. |
Definition at line 817 of file qwt_scale_draw.cpp.
void QwtScaleDraw::setLength | ( | double | length | ) |
Set the length of the backbone.
The length doesn't include the space needed for overlapping labels.
length | Length of the backbone |
Definition at line 615 of file qwt_scale_draw.cpp.
|
private |
Definition at line 916 of file qwt_scale_draw.cpp.
|
private |
Definition at line 100 of file qwt_scale_draw.h.