Qwt User's Guide: QwtDateScaleDraw Class Reference

Qwt User's Guide 6.2.0

Public Member Functions | Protected Member Functions | List of all members
QwtDateScaleDraw Class Reference

A class for drawing datetime scales. More...

`#include <qwt_date_scale_draw.h>`

Inheritance diagram for QwtDateScaleDraw:

## Public Member Functions
| QwtDateScaleDraw (Qt::TimeSpec=Qt::LocalTime)
| Constructor. More...
virtual | ~QwtDateScaleDraw ()
| Destructor.
void | setDateFormat (QwtDate::IntervalType, const QString &)
QString | dateFormat (QwtDate::IntervalType) const
void | setTimeSpec (Qt::TimeSpec)
Qt::TimeSpec | timeSpec () const
void | setUtcOffset (int seconds)
int | utcOffset () const
void | setWeek0Type (QwtDate::Week0Type)
QwtDate::Week0Type | week0Type () const
virtual QwtText | label (double) const override
| Convert a value into its representing label. More...
QDateTime | toDateTime (double) const
Public Member Functions inherited from QwtScaleDraw
| QwtScaleDraw ()
| Constructor. More...
virtual | ~QwtScaleDraw ()
| Destructor.
void | getBorderDistHint (const QFont &, int &start, int &end) const
| Determine the minimum border distance. More...
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. More...
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. More...
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. More...
Public Member Functions inherited from QwtAbstractScaleDraw
| QwtAbstractScaleDraw ()
| Constructor. More...
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. More...
double | spacing () const
| Get the spacing. More...
void | setPenWidthF (qreal width)
| Specify the width of the scale pen. More...
qreal | penWidthF () const
virtual void | draw (QPainter *, const QPalette &) const
| Draw the scale. More...
void | setMinimumExtent (double)
| Set a minimum for the extent. More...
double | minimumExtent () const
void | invalidateCache ()

## Protected Member Functions
virtual QwtDate::IntervalType | intervalType (const QwtScaleDiv &) const
virtual QString | dateFormatOfDate (const QDateTime &, QwtDate::IntervalType) const
Protected Member Functions inherited from QwtScaleDraw
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. More...

## Additional Inherited Members
Public Types inherited from QwtScaleDraw
enum | Alignment { BottomScale , TopScale , LeftScale , RightScale }
Public Types inherited from QwtAbstractScaleDraw
enum | ScaleComponent { Backbone = 0x01 , Ticks = 0x02 , Labels = 0x04 }
typedef QFlags< ScaleComponent > | ScaleComponents

## Detailed Description

A class for drawing datetime scales.

QwtDateScaleDraw displays values as datetime labels. The format of the labels depends on the alignment of the major tick labels.

The default format strings are:

- Millisecond
  "hh:mm:ss:zzz\nddd dd MMM yyyy"
- Second
  "hh:mm:ss\nddd dd MMM yyyy"
- Minute
  "hh:mm\nddd dd MMM yyyy"
- Hour
  "hh:mm\nddd dd MMM yyyy"
- Day
  "ddd dd MMM yyyy"
- Week
  "Www yyyy"
- Month
  "MMM yyyy"
- Year
  "yyyy"

The format strings can be modified using setDateFormat() or individually for each tick label by overloading dateFormatOfDate(),

Usually QwtDateScaleDraw is used in combination with QwtDateScaleEngine, that calculates scales for datetime intervals.

See also
  QwtDateScaleEngine, QwtPlot::setAxisScaleDraw()

Definition at line 52 of file qwt_date_scale_draw.h.

## Constructor & Destructor Documentation

## ◆ QwtDateScaleDraw()

QwtDateScaleDraw::QwtDateScaleDraw | ( | Qt::TimeSpec | timeSpec = `Qt::LocalTime` | ) |
| explicit

Constructor.

The default setting is to display tick labels for the given time specification. The first week of a year is defined like for QwtDate::FirstThursday.

Parameters

  timeSpec | Time specification

See also
  setTimeSpec(), setWeek0Type()

Definition at line 48 of file qwt_date_scale_draw.cpp.

## Member Function Documentation

## ◆ dateFormat()

QString QwtDateScaleDraw::dateFormat | ( | QwtDate::IntervalType | intervalType | ) | const

Parameters

  intervalType | Interval type

Returns
  Default format string for an datetime interval type

See also
  setDateFormat(), dateFormatOfDate()

Definition at line 152 of file qwt_date_scale_draw.cpp.

## ◆ dateFormatOfDate()

QString QwtDateScaleDraw::dateFormatOfDate | ( | const QDateTime & | dateTime,
|  | QwtDate::IntervalType | intervalType
| ) |  | const
| protectedvirtual

Format string for the representation of a datetime

dateFormatOfDate() is intended to be overloaded for situations, where formats are individual for specific datetime values.

The default setting ignores dateTime and return the default format for the interval type.

Parameters

  dateTime | Datetime value
  intervalType | Interval type

Returns
  Format string

See also
  setDateFormat(), QwtDate::toString()

Definition at line 180 of file qwt_date_scale_draw.cpp.

## ◆ intervalType()

QwtDate::IntervalType QwtDateScaleDraw::intervalType | ( | const QwtScaleDiv & | scaleDiv | ) | const
| protectedvirtual

Find the less detailed datetime unit, where no rounding errors happen.

Parameters

  scaleDiv | Scale division

Returns
  Interval type

See also
  dateFormatOfDate()

Definition at line 223 of file qwt_date_scale_draw.cpp.

## ◆ label()

QwtText QwtDateScaleDraw::label | ( | double | value | ) | const
| overridevirtual

Convert a value into its representing label.

The value is converted to a datetime value using toDateTime() and converted to a plain text using QwtDate::toString().

Parameters

  value | Value

Returns
  Label string.

See also
  dateFormatOfDate()

Reimplemented from QwtAbstractScaleDraw.

Definition at line 205 of file qwt_date_scale_draw.cpp.

## ◆ setDateFormat()

void QwtDateScaleDraw::setDateFormat | ( | QwtDate::IntervalType | intervalType,
|  | const QString & | format
| ) |  |

Set the default format string for an datetime interval type

Parameters

  intervalType | Interval type
  format | Default format string

See also
  dateFormat(), dateFormatOfDate(), QwtDate::toString()

Definition at line 137 of file qwt_date_scale_draw.cpp.

## ◆ setTimeSpec()

void QwtDateScaleDraw::setTimeSpec | ( | Qt::TimeSpec | timeSpec | ) |

Set the time specification used for the tick labels

Parameters

  timeSpec | Time specification

See also
  timeSpec(), setUtcOffset(), toDateTime()

Definition at line 65 of file qwt_date_scale_draw.cpp.

## ◆ setUtcOffset()

void QwtDateScaleDraw::setUtcOffset | ( | int | seconds | ) |

Set the offset in seconds from Coordinated Universal Time

Parameters

  seconds | Offset in seconds

Note
  The offset has no effect beside for the time specification Qt::OffsetFromUTC.

See also
  QDate::utcOffset(), setTimeSpec(), toDateTime()

Definition at line 89 of file qwt_date_scale_draw.cpp.

## ◆ setWeek0Type()

void QwtDateScaleDraw::setWeek0Type | ( | QwtDate::Week0Type | week0Type | ) |

Sets how to identify the first week of a year.

Parameters

  week0Type | Mode how to identify the first week of a year

See also
  week0Type().

Note
  week0Type has no effect beside for intervals classified as QwtDate::Week.

Definition at line 115 of file qwt_date_scale_draw.cpp.

## ◆ timeSpec()

Qt::TimeSpec QwtDateScaleDraw::timeSpec | ( |  | ) | const

Returns
  Time specification used for the tick labels

See also
  setTimeSpec(), utcOffset(), toDateTime()

Definition at line 74 of file qwt_date_scale_draw.cpp.

## ◆ toDateTime()

QDateTime QwtDateScaleDraw::toDateTime | ( | double | value | ) | const

Translate a double value into a QDateTime object.

Returns
  QDateTime object initialized with timeSpec() and utcOffset().

See also
  timeSpec(), utcOffset(), QwtDate::toDateTime()

Definition at line 269 of file qwt_date_scale_draw.cpp.

## ◆ utcOffset()

int QwtDateScaleDraw::utcOffset | ( |  | ) | const

Returns
  Offset in seconds from Coordinated Universal Time

Note
  The offset has no effect beside for the time specification Qt::OffsetFromUTC.

See also
  QDate::setUtcOffset(), setTimeSpec(), toDateTime()

Definition at line 101 of file qwt_date_scale_draw.cpp.

## ◆ week0Type()

QwtDate::Week0Type QwtDateScaleDraw::week0Type | ( |  | ) | const

Returns
  Setting how to identify the first week of a year.

See also
  setWeek0Type()

Definition at line 124 of file qwt_date_scale_draw.cpp.