Qwt User's Guide 6.0.2

- Main Page
- Related Pages
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Protected Member Functions
QwtScaleDraw Class Reference

`#include <qwt_scale_draw.h>`

Inheritance diagram for QwtScaleDraw:
[legend]

List of all members.

## 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 ()
virtual | ~QwtScaleDraw ()
Alignment | alignment () const
QRect | boundingLabelRect (const QFont &, double val) const
virtual double | extent (const QFont &) const
void | getBorderDistHint (const QFont &, int &start, int &end) 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
int | minLabelDist (const QFont &) const
int | minLength (const QFont &) const
void | move (double x, double y)
void | move (const QPointF &)
Qt::Orientation | orientation () const
QPointF | pos () const
void | setAlignment (Alignment)
void | setLabelAlignment (Qt::Alignment)
void | setLabelRotation (double rotation)
void | setLength (double length)
Public Member Functions inherited from QwtAbstractScaleDraw
| QwtAbstractScaleDraw ()
virtual | ~QwtAbstractScaleDraw ()
virtual void | draw (QPainter *, const QPalette &) const
void | enableComponent (ScaleComponent, bool enable=true)
bool | hasComponent (ScaleComponent) const
virtual QwtText | label (double) const
double | maxTickLength () const
double | minimumExtent () const
int | penWidth () const
const QwtScaleDiv & | scaleDiv () const
const QwtScaleMap & | scaleMap () const
QwtScaleMap & | scaleMap ()
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

## 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
void | invalidateCache ()
const QwtText & | tickLabel (const QFont &, double value) const

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

## Member Enumeration Documentation

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.

## Constructor & Destructor Documentation

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.

## Member Function Documentation

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

Return alignment of the scale

See also:
  setAlignment()

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.

Parameters:

  font | Font used for painting
  value | Value

See also:
  labelRect()

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

Draws the baseline of the scale

Parameters:

  painter | Painter

See also:
  drawTick(), drawLabel()

Implements QwtAbstractScaleDraw.

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

Draws the label for a major scale tick

Parameters:

  painter | Painter
  value | Value

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

Implements QwtAbstractScaleDraw.

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

Draw a tick

Parameters:

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

See also:
  drawBackbone(), drawLabel()

Implements QwtAbstractScaleDraw.

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.

Parameters:

  font | Font used for painting the labels

See also:
  minLength()

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.

Parameters:

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

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

Returns:
  the label flags

See also:
  setLabelAlignment(), labelRotation()

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

Parameters:

  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.

Parameters:

  font | Font used for painting
  value | Value

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

Returns:
  the label rotation

See also:
  setLabelRotation(), labelAlignment()

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

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

See also:
  setLabelAlignment(), setLabelRotation()

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

Returns:
  the length of the backbone

See also:
  setLength(), pos()

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

Parameters:

  font | Font

Returns:
  the maximum height of a label

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

Parameters:

  font | Font

Returns:
  the maximum width of a label

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

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

See also:
  extent()

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

Move the position of the scale

See also:
  move(const QPointF &)

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

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

Return the orientation

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

See also:
  alignment()

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

Returns:
  Origin of the scale

See also:
  move(), length()

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

Set the alignment of the scale

The default alignment is QwtScaleDraw::BottomScale

See also:
  alignment()

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

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

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

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

Set the length of the backbone.

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

See also:
  move(), minLabelDist()