A class which draws a scale inside the plot canvas. More...
#include <qwt_plot_scaleitem.h>
Classes | |
class | PrivateData |
Public Member Functions | |
QwtPlotScaleItem (QwtScaleDraw::Alignment=QwtScaleDraw::BottomScale, const double pos=0.0) | |
Constructor for scale item at the position pos. | |
virtual | ~QwtPlotScaleItem () |
Destructor. | |
virtual int | rtti () const |
void | setScaleDiv (const QwtScaleDiv &) |
Assign a scale division. | |
const QwtScaleDiv & | scaleDiv () const |
void | setScaleDivFromAxis (bool on) |
bool | isScaleDivFromAxis () const |
void | setColorGroup (const QColorGroup &) |
QColorGroup | colorGroup () const |
void | setFont (const QFont &) |
QFont | font () const |
void | setScaleDraw (QwtScaleDraw *) |
Set a scale draw. | |
const QwtScaleDraw * | scaleDraw () const |
QwtScaleDraw * | scaleDraw () |
void | setPosition (double pos) |
double | position () const |
void | setBorderDistance (int numPixels) |
Align the scale to the canvas. | |
int | borderDistance () const |
void | setAlignment (QwtScaleDraw::Alignment) |
virtual void | draw (QPainter *p, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &rect) const |
Draw the scale. | |
virtual void | updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &) |
Update the item to changes of the axes scale division. |
A class which draws a scale inside the plot canvas.
QwtPlotScaleItem can be used to draw an axis inside the plot canvas. It might by synchronized to one of the axis of the plot, but can also display its own ticks and labels.
It is allowed to synchronize the scale item with a disabled axis. In plots with vertical and horizontal scale items, it might be necessary to remove ticks at the intersections, by overloading updateScaleDiv().
The scale might be at a specific position (f.e 0.0) or it might be aligned to a canvas border.
QwtPlotScaleItem *scaleItem = new QwtPlotScaleItem(QwtScaleDraw::RightScale, 0.0); scaleItem->setFont(plot->axisWidget(QwtPlot::yLeft)->font()); scaleItem->attach(plot); plot->enableAxis(QwtPlot::yLeft, false);
Definition at line 51 of file qwt_plot_scaleitem.h.
QwtPlotScaleItem::QwtPlotScaleItem | ( | QwtScaleDraw::Alignment | alignment = QwtScaleDraw::BottomScale , |
const double | pos = 0.0 |
||
) | [explicit] |
Constructor for scale item at the position pos.
alignment | In case of QwtScaleDraw::BottomScale/QwtScaleDrawTopScale the scale item is corresponding to the xAxis(), otherwise it corresponds to the yAxis(). |
pos | x or y position, depending on the corresponding axis. |
Definition at line 58 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::position, QwtPlotScaleItem::PrivateData::scaleDraw, QwtScaleDraw::setAlignment(), and QwtPlotItem::setZ().
: QwtPlotItem(QwtText("Scale")) { d_data = new PrivateData; d_data->position = pos; d_data->scaleDraw->setAlignment(alignment); setZ(11.0); }
QwtPlotScaleItem::~QwtPlotScaleItem | ( | ) | [virtual] |
int QwtPlotScaleItem::borderDistance | ( | ) | const |
Definition at line 320 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::borderDistance.
{ return d_data->borderDistance; }
QColorGroup QwtPlotScaleItem::colorGroup | ( | ) | const |
Definition at line 156 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::colorGroup.
Referenced by setColorGroup().
{ return d_data->colorGroup; }
void QwtPlotScaleItem::draw | ( | QPainter * | p, |
const QwtScaleMap & | xMap, | ||
const QwtScaleMap & | yMap, | ||
const QRect & | rect | ||
) | const [virtual] |
Draw the scale.
Implements QwtPlotItem.
Definition at line 354 of file qwt_plot_scaleitem.cpp.
References QwtScaleDraw::alignment(), QwtPlotScaleItem::PrivateData::borderDistance, QwtScaleDraw::BottomScale, QwtPlotScaleItem::PrivateData::canvasRectCache, QwtPlotScaleItem::PrivateData::colorGroup, QwtScaleTransformation::copy(), QwtAbstractScaleDraw::draw(), QwtPlotScaleItem::PrivateData::font, QwtScaleDraw::move(), QwtScaleDraw::orientation(), QwtPlotScaleItem::PrivateData::position, QwtScaleDraw::RightScale, QwtPlotScaleItem::PrivateData::scaleDraw, QwtScaleDraw::setLength(), QwtAbstractScaleDraw::setTransformation(), QwtScaleMap::transform(), and QwtScaleMap::transformation().
{ if ( canvasRect != d_data->canvasRectCache ) { QwtPlotScaleItem* that = (QwtPlotScaleItem*)this; that->updateBorders(); } QPen pen = painter->pen(); pen.setStyle(Qt::SolidLine); painter->setPen(pen); int pw = painter->pen().width(); if ( pw == 0 ) pw = 1; QwtScaleDraw *sd = d_data->scaleDraw; if ( sd->orientation() == Qt::Horizontal ) { int y; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::BottomScale ) y = canvasRect.top() + d_data->borderDistance; else { y = canvasRect.bottom() - d_data->borderDistance - pw + 1; } } else { y = yMap.transform(d_data->position); } if ( y < canvasRect.top() || y > canvasRect.bottom() ) return; sd->move(canvasRect.left(), y); sd->setLength(canvasRect.width() - 1); sd->setTransformation(xMap.transformation()->copy()); } else // == Qt::Vertical { int x; if ( d_data->borderDistance >= 0 ) { if ( sd->alignment() == QwtScaleDraw::RightScale ) x = canvasRect.left() + d_data->borderDistance; else { x = canvasRect.right() - d_data->borderDistance - pw + 1; } } else { x = xMap.transform(d_data->position); } if ( x < canvasRect.left() || x > canvasRect.right() ) return; sd->move(x, canvasRect.top()); sd->setLength(canvasRect.height() - 1); sd->setTransformation(yMap.transformation()->copy()); } painter->setFont(d_data->font); #if QT_VERSION < 0x040000 sd->draw(painter, d_data->colorGroup); #else sd->draw(painter, d_data->palette); #endif }
QFont QwtPlotScaleItem::font | ( | ) | const |
Definition at line 204 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::font.
Referenced by setFont().
{ return d_data->font; }
bool QwtPlotScaleItem::isScaleDivFromAxis | ( | ) | const |
Definition at line 132 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::scaleDivFromAxis.
{ return d_data->scaleDivFromAxis; }
double QwtPlotScaleItem::position | ( | ) | const |
Definition at line 283 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::position.
{ return d_data->position; }
int QwtPlotScaleItem::rtti | ( | ) | const [virtual] |
Reimplemented from QwtPlotItem.
Definition at line 76 of file qwt_plot_scaleitem.cpp.
References QwtPlotItem::Rtti_PlotScale.
{ return QwtPlotItem::Rtti_PlotScale; }
const QwtScaleDiv & QwtPlotScaleItem::scaleDiv | ( | ) | const |
Definition at line 97 of file qwt_plot_scaleitem.cpp.
References QwtAbstractScaleDraw::scaleDiv(), and QwtPlotScaleItem::PrivateData::scaleDraw.
const QwtScaleDraw * QwtPlotScaleItem::scaleDraw | ( | ) | const |
Definition at line 244 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::scaleDraw.
Referenced by setScaleDraw().
{ return d_data->scaleDraw; }
QwtScaleDraw * QwtPlotScaleItem::scaleDraw | ( | ) |
Definition at line 253 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::scaleDraw.
{ return d_data->scaleDraw; }
void QwtPlotScaleItem::setAlignment | ( | QwtScaleDraw::Alignment | alignment ) |
Change the alignment of the scale
The alignment sets the orientation of the scale and the position of the ticks:
For horizontal scales the position corresponds to QwtPlotItem::yAxis(), otherwise to QwtPlotItem::xAxis().
Definition at line 341 of file qwt_plot_scaleitem.cpp.
References QwtScaleDraw::alignment(), QwtPlotItem::itemChanged(), QwtPlotScaleItem::PrivateData::scaleDraw, and QwtScaleDraw::setAlignment().
{ QwtScaleDraw *sd = d_data->scaleDraw; if ( sd->alignment() != alignment ) { sd->setAlignment(alignment); itemChanged(); } }
void QwtPlotScaleItem::setBorderDistance | ( | int | distance ) |
Align the scale to the canvas.
If distance is >= 0 the scale will be aligned to a border of the contents rect of the canvas. If alignment() is QwtScaleDraw::LeftScale, the scale will be aligned to the right border, if it is QwtScaleDraw::TopScale it will be aligned to the bottom (and vice versa),
If distance is < 0 the scale will be at the position().
distance | Number of pixels between the canvas border and the backbone of the scale. |
Definition at line 304 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::borderDistance, QuadProgPP::distance(), and QwtPlotItem::itemChanged().
{ if ( distance < 0 ) distance = -1; if ( distance != d_data->borderDistance ) { d_data->borderDistance = distance; itemChanged(); } }
void QwtPlotScaleItem::setColorGroup | ( | const QColorGroup & | colorGroup ) |
Set the color group
Definition at line 143 of file qwt_plot_scaleitem.cpp.
References colorGroup(), QwtPlotScaleItem::PrivateData::colorGroup, and QwtPlotItem::itemChanged().
{ if ( colorGroup != d_data->colorGroup ) { d_data->colorGroup = colorGroup; itemChanged(); } }
void QwtPlotScaleItem::setFont | ( | const QFont & | font ) |
Change the tick label font
Definition at line 191 of file qwt_plot_scaleitem.cpp.
References font(), QwtPlotScaleItem::PrivateData::font, and QwtPlotItem::itemChanged().
{ if ( font != d_data->font ) { d_data->font = font; itemChanged(); } }
void QwtPlotScaleItem::setPosition | ( | double | pos ) |
Change the position of the scale
The position is interpreted as y value for horizontal axes and as x value for vertical axes.
The border distance is set to -1.
pos | New position |
Definition at line 269 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::borderDistance, QwtPlotItem::itemChanged(), and QwtPlotScaleItem::PrivateData::position.
{ if ( d_data->position != pos ) { d_data->position = pos; d_data->borderDistance = -1; itemChanged(); } }
void QwtPlotScaleItem::setScaleDiv | ( | const QwtScaleDiv & | scaleDiv ) |
Assign a scale division.
When assigning a scaleDiv the scale division won't be synchronized with the corresponding axis anymore.
scaleDiv | Scale division |
Definition at line 90 of file qwt_plot_scaleitem.cpp.
References QwtPlotScaleItem::PrivateData::scaleDivFromAxis, QwtPlotScaleItem::PrivateData::scaleDraw, and QwtAbstractScaleDraw::setScaleDiv().
{ d_data->scaleDivFromAxis = false; d_data->scaleDraw->setScaleDiv(scaleDiv); }
void QwtPlotScaleItem::setScaleDivFromAxis | ( | bool | on ) |
Enable/Disable the synchronization of the scale division with the corresponding axis.
on | true/false |
Definition at line 109 of file qwt_plot_scaleitem.cpp.
References QwtPlot::axisScaleDiv(), QwtPlotItem::itemChanged(), QwtPlotItem::plot(), QwtPlotScaleItem::PrivateData::scaleDivFromAxis, updateScaleDiv(), QwtPlotItem::xAxis(), and QwtPlotItem::yAxis().
{ if ( on != d_data->scaleDivFromAxis ) { d_data->scaleDivFromAxis = on; if ( on ) { const QwtPlot *plt = plot(); if ( plt ) { updateScaleDiv( *plt->axisScaleDiv(xAxis()), *plt->axisScaleDiv(yAxis()) ); itemChanged(); } } } }
void QwtPlotScaleItem::setScaleDraw | ( | QwtScaleDraw * | scaleDraw ) |
Set a scale draw.
scaleDraw | object responsible for drawing scales. |
The main use case for replacing the default QwtScaleDraw is to overload QwtAbstractScaleDraw::label, to replace or swallow tick labels.
Definition at line 220 of file qwt_plot_scaleitem.cpp.
References QwtPlot::axisScaleDiv(), QwtPlotItem::itemChanged(), QwtPlotItem::plot(), scaleDraw(), QwtPlotScaleItem::PrivateData::scaleDraw, updateScaleDiv(), QwtPlotItem::xAxis(), and QwtPlotItem::yAxis().
{ if ( scaleDraw == NULL ) return; if ( scaleDraw != d_data->scaleDraw ) delete d_data->scaleDraw; d_data->scaleDraw = scaleDraw; const QwtPlot *plt = plot(); if ( plt ) { updateScaleDiv( *plt->axisScaleDiv(xAxis()), *plt->axisScaleDiv(yAxis()) ); } itemChanged(); }
void QwtPlotScaleItem::updateScaleDiv | ( | const QwtScaleDiv & | xScaleDiv, |
const QwtScaleDiv & | yScaleDiv | ||
) | [virtual] |
Update the item to changes of the axes scale division.
In case of isScaleDivFromAxis(), the scale draw is synchronized to the correspond axis.
xScaleDiv | Scale division of the x-axis |
yScaleDiv | Scale division of the y-axis |
Reimplemented from QwtPlotItem.
Definition at line 444 of file qwt_plot_scaleitem.cpp.
References QwtScaleDraw::orientation(), QwtPlotScaleItem::PrivateData::scaleDivFromAxis, QwtPlotScaleItem::PrivateData::scaleDraw, and QwtAbstractScaleDraw::setScaleDiv().
Referenced by setScaleDivFromAxis(), and setScaleDraw().
{ QwtScaleDraw *sd = d_data->scaleDraw; if ( d_data->scaleDivFromAxis && sd ) { sd->setScaleDiv( sd->orientation() == Qt::Horizontal ? xScaleDiv : yScaleDiv); updateBorders(); } }