Loading...
Searching...
No Matches
QwtScaleDraw Class Reference

A class for drawing scales. More...

`#include <qwt_scale_draw.h>`

Inheritance diagram for QwtScaleDraw:

## 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

## Public Member Functions

| QwtScaleDraw ()
| Constructor.
virtual | ~QwtScaleDraw ()
| Destructor.
void | getBorderDistHint (const QFont &, int &start, int &end) const
| Determine the minimum border distance.
int | minLabelDist (const QFont &) const
int | minLength (const QFont &) const
virtual double | extent (const QFont &) const override
void | move (double x, double y)
void | move (const QPointF &)
| Move the position of the scale.
void | setLength (double length)
Alignment | alignment () const
void | setAlignment (Alignment)
Qt::Orientation | orientation () const
QPointF | pos () const
double | length () const
void | setLabelAlignment (Qt::Alignment)
| Change the label flags.
Qt::Alignment | labelAlignment () const
void | setLabelRotation (double rotation)
double | labelRotation () const
int | maxLabelHeight (const QFont &) const
int | maxLabelWidth (const QFont &) const
QPointF | labelPosition (double value) const
QRectF | labelRect (const QFont &, double value) const
QSizeF | labelSize (const QFont &, double value) const
QRect | boundingLabelRect (const QFont &, double value) const
| Find the bounding rectangle for the label.
Public Member Functions inherited from QwtAbstractScaleDraw
| QwtAbstractScaleDraw ()
| Constructor.
virtual | ~QwtAbstractScaleDraw ()
| Destructor.
void | setScaleDiv (const QwtScaleDiv &)
const QwtScaleDiv & | scaleDiv () const
void | setTransformation (QwtTransform *)
const QwtScaleMap & | scaleMap () const
QwtScaleMap & | scaleMap ()
void | enableComponent (ScaleComponent, bool enable=true)
bool | hasComponent (ScaleComponent) const
void | setTickLength (QwtScaleDiv::TickType, double length)
double | tickLength (QwtScaleDiv::TickType) const
double | maxTickLength () const
void | setSpacing (double)
| Set the spacing between tick and labels.
double | spacing () const
| Get the spacing.
void | setPenWidthF (qreal width)
| Specify the width of the scale pen.
qreal | penWidthF () const
virtual void | draw (QPainter *, const QPalette &) const
| Draw the scale.
virtual QwtText | label (double) const
| Convert a value into its representing label.
void | setMinimumExtent (double)
| Set a minimum for the extent.
double | minimumExtent () const
void | invalidateCache ()

## Protected Member Functions

QTransform | labelTransformation (const QPointF &, const QSizeF &) const
virtual void | drawTick (QPainter *, double value, double len) const override
virtual void | drawBackbone (QPainter *) const override
virtual void | drawLabel (QPainter *, double value) const override
Protected Member Functions inherited from QwtAbstractScaleDraw
const QwtText & | tickLabel (const QFont &, double value) const
| Convert a value into its representing label and cache it.

## Detailed Description

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 35 of file qwt_scale_draw.h.

## Member Enumeration Documentation

## Alignment

enum QwtScaleDraw::Alignment

Alignment of the scale draw

See also
  setAlignment(), alignment()

Enumerator
BottomScale | The scale is below.
TopScale | The scale is above.
LeftScale | The scale is left.
RightScale | The scale is right.

Definition at line 42 of file qwt_scale_draw.h.

## Constructor & Destructor Documentation

## QwtScaleDraw()

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 292 of file qwt_scale_draw.cpp.

## ~QwtScaleDraw()

QwtScaleDraw::~QwtScaleDraw | ( |  | ) |

virtual

Destructor.

Definition at line 299 of file qwt_scale_draw.cpp.

## Member Function Documentation

## alignment()

QwtScaleDraw::Alignment QwtScaleDraw::alignment | ( |  | ) | const

Return alignment of the scale

See also
  setAlignment()

Returns
  Alignment of the scale

Definition at line 309 of file qwt_scale_draw.cpp.

## boundingLabelRect()

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.

Parameters

  font | Font used for painting
  value | Value

Returns
  Bounding rectangle

See also
  labelRect()

Definition at line 794 of file qwt_scale_draw.cpp.

## drawBackbone()

void QwtScaleDraw::drawBackbone | ( | QPainter * | painter | ) | const

overrideprotectedvirtual

Draws the baseline of the scale

Parameters

  painter | Painter

See also
  drawTick(), drawLabel()

Implements QwtAbstractScaleDraw.

Definition at line 668 of file qwt_scale_draw.cpp.

## drawLabel()

void QwtScaleDraw::drawLabel | ( | QPainter * | painter,
|  | double | value ) const

overrideprotectedvirtual

Draws the label for a major scale tick

Parameters

  painter | Painter
  value | Value

See also
  drawTick(), drawBackbone(), boundingLabelRect()

Implements QwtAbstractScaleDraw.

Definition at line 762 of file qwt_scale_draw.cpp.

## drawTick()

void QwtScaleDraw::drawTick | ( | QPainter * | painter,
|  | double | value,
|  | double | len ) const

overrideprotectedvirtual

Draw a tick

Parameters

  painter | Painter
  value | Value of the tick
  len | Length of the tick

See also
  drawBackbone(), drawLabel()

Implements QwtAbstractScaleDraw.

Definition at line 649 of file qwt_scale_draw.cpp.

## extent()

double QwtScaleDraw::extent | ( | const QFont & | font | ) | const

overridevirtual

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.

Parameters

  font | Font used for painting the labels

Returns
  Extent

See also
  minLength()

Implements QwtAbstractScaleDraw.

Definition at line 523 of file qwt_scale_draw.cpp.

## getBorderDistHint()

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.

Parameters

  font | Font
  start | Start border distance
  end | End border distance

Definition at line 361 of file qwt_scale_draw.cpp.

## labelAlignment()

Qt::Alignment QwtScaleDraw::labelAlignment | ( |  | ) | const

Returns
  the label flags

See also
  setLabelAlignment(), labelRotation()

Definition at line 978 of file qwt_scale_draw.cpp.

## labelPosition()

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().

Parameters

  value | Value

Returns
  Position, where to paint a label

Definition at line 596 of file qwt_scale_draw.cpp.

## labelRect()

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.

Parameters

  font | Font used for painting
  value | Value

Returns
  Bounding rectangle that is needed to draw a label

Definition at line 887 of file qwt_scale_draw.cpp.

## labelRotation()

double QwtScaleDraw::labelRotation | ( |  | ) | const

Returns
  the label rotation

See also
  setLabelRotation(), labelAlignment()

Definition at line 939 of file qwt_scale_draw.cpp.

## labelSize()

QSizeF QwtScaleDraw::labelSize | ( | const QFont & | font,
|  | double | value ) const

Calculate the size that is needed to draw a label

Parameters

  font | Label font
  value | Value

Returns
  Size that is needed to draw a label

Definition at line 912 of file qwt_scale_draw.cpp.

## labelTransformation()

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.

Parameters

  pos | Position where to paint the label
  size | Size of the label

Returns
  Transformation matrix

See also
  setLabelAlignment(), setLabelRotation()

Definition at line 817 of file qwt_scale_draw.cpp.

## length()

double QwtScaleDraw::length | ( |  | ) | const

Returns
  the length of the backbone

See also
  setLength(), pos()

Definition at line 749 of file qwt_scale_draw.cpp.

## maxLabelHeight()

int QwtScaleDraw::maxLabelHeight | ( | const QFont & | font | ) | const

Parameters

  font | Font

Returns
  the maximum height of a label

Definition at line 1010 of file qwt_scale_draw.cpp.

## maxLabelWidth()

int QwtScaleDraw::maxLabelWidth | ( | const QFont & | font | ) | const

Parameters

  font | Font

Returns
  the maximum width of a label

Definition at line 987 of file qwt_scale_draw.cpp.

## minLabelDist()

int QwtScaleDraw::minLabelDist | ( | const QFont & | font | ) | const

Determine the minimum distance between two labels, that is necessary that the texts don't overlap.

Parameters

  font | Font

Returns
  The maximum width of a label

See also
  getBorderDistHint()

Definition at line 436 of file qwt_scale_draw.cpp.

## minLength()

int QwtScaleDraw::minLength | ( | const QFont & | font | ) | const

Calculate the minimum length that is needed to draw the scale

Parameters

  font | Font used for painting the labels

Returns
  Minimum length that is needed to draw the scale

See also
  extent()

Definition at line 560 of file qwt_scale_draw.cpp.

## move() [1/2]

void QwtScaleDraw::move | ( | const QPointF & | pos | ) |

Move the position of the scale.

The meaning of the parameter pos depends on the alignment:

QwtScaleDraw::LeftScale
  The origin is the topmost point of the backbone. The backbone is a vertical line. Scale marks and labels are drawn at the left of the backbone.
QwtScaleDraw::RightScale
  The origin is the topmost point of the backbone. The backbone is a vertical line. Scale marks and labels are drawn at the right of the backbone.
QwtScaleDraw::TopScale
  The origin is the leftmost point of the backbone. The backbone is a horizontal line. Scale marks and labels are drawn above the backbone.
QwtScaleDraw::BottomScale
  The origin is the leftmost point of the backbone. The backbone is a horizontal line Scale marks and labels are drawn below the backbone.

Parameters

  pos | Origin of the scale

See also
  pos(), setLength()

Definition at line 707 of file qwt_scale_draw.cpp.

## move() [2/2]

void QwtScaleDraw::move | ( | double | x,
|  | double | y )

inline

Move the position of the scale

Parameters

  x | X coordinate
  y | Y coordinate

See also
  move(const QPointF &)

Definition at line 118 of file qwt_scale_draw.h.

## orientation()

Qt::Orientation QwtScaleDraw::orientation | ( |  | ) | const

Return the orientation

TopScale, BottomScale are horizontal (Qt::Horizontal) scales, LeftScale, RightScale are vertical (Qt::Vertical) scales.

Returns
  Orientation of the scale

See also
  alignment()

Definition at line 337 of file qwt_scale_draw.cpp.

## pos()

QPointF QwtScaleDraw::pos | ( |  | ) | const

Returns
  Origin of the scale

See also
  move(), length()

Definition at line 717 of file qwt_scale_draw.cpp.

## setAlignment()

void QwtScaleDraw::setAlignment | ( | Alignment | align | ) |

Set the alignment of the scale

Parameters

  align | Alignment of the scale

The default alignment is QwtScaleDraw::BottomScale

See also
  alignment()

Definition at line 322 of file qwt_scale_draw.cpp.

## setLabelAlignment()

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
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.

Parameters

  alignment | Or'd Qt::AlignmentFlags see <qnamespace.h>

See also
  setLabelRotation(), labelRotation(), labelAlignment()

Warning
  The various alignments might be confusing. The alignment of the label is not the alignment of the scale and is not the alignment of the flags ( QwtText::flags() ) returned from QwtAbstractScaleDraw::label().

Definition at line 969 of file qwt_scale_draw.cpp.

## setLabelRotation()

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.

Parameters

  rotation | Angle in degrees. When changing the label rotation, the label flags often needs to be adjusted too.

See also
  setLabelAlignment(), labelRotation(), labelAlignment().

Definition at line 930 of file qwt_scale_draw.cpp.

## setLength()

void QwtScaleDraw::setLength | ( | double | length | ) |

Set the length of the backbone.

The length doesn't include the space needed for overlapping labels.

Parameters

  length | Length of the backbone

See also
  move(), minLabelDist()

Definition at line 732 of file qwt_scale_draw.cpp.