Base class for items on the plot canvas. More...
#include <qwt_plot_item.h>
Classes | |
class | PrivateData |
Public Types | |
enum | RttiValues { Rtti_PlotItem = 0, Rtti_PlotGrid, Rtti_PlotScale, Rtti_PlotMarker, Rtti_PlotCurve, Rtti_PlotHistogram, Rtti_PlotSpectrogram, Rtti_PlotSVG, Rtti_PlotUserItem = 1000 } |
Runtime type information. More... | |
enum | ItemAttribute { Legend = 1, AutoScale = 2 } |
Public Member Functions | |
QwtPlotItem (const QwtText &title=QwtText()) | |
virtual | ~QwtPlotItem () |
Destroy the QwtPlotItem. | |
void | attach (QwtPlot *plot) |
Attach the item to a plot. | |
void | detach () |
This method detaches a QwtPlotItem from any QwtPlot it has been associated with. | |
QwtPlot * | plot () const |
Return attached plot. | |
void | setTitle (const QString &title) |
void | setTitle (const QwtText &title) |
const QwtText & | title () const |
virtual int | rtti () const |
void | setItemAttribute (ItemAttribute, bool on=true) |
bool | testItemAttribute (ItemAttribute) const |
double | z () const |
void | setZ (double z) |
Set the z value. | |
void | show () |
Show the item. | |
void | hide () |
Hide the item. | |
virtual void | setVisible (bool) |
bool | isVisible () const |
void | setAxis (int xAxis, int yAxis) |
void | setXAxis (int axis) |
int | xAxis () const |
Return xAxis. | |
void | setYAxis (int axis) |
int | yAxis () const |
Return yAxis. | |
virtual void | itemChanged () |
virtual void | draw (QPainter *painter, const QwtScaleMap &xMap, const QwtScaleMap &yMap, const QRect &canvasRect) const =0 |
Draw the item. | |
virtual QwtDoubleRect | boundingRect () const |
virtual void | updateLegend (QwtLegend *) const |
Update the widget that represents the item on the legend. | |
virtual void | updateScaleDiv (const QwtScaleDiv &, const QwtScaleDiv &) |
Update the item to changes of the axes scale division. | |
virtual QWidget * | legendItem () const |
Allocate the widget that represents the item on the legend. | |
QwtDoubleRect | scaleRect (const QwtScaleMap &, const QwtScaleMap &) const |
Calculate the bounding scale rect of 2 maps. | |
QRect | paintRect (const QwtScaleMap &, const QwtScaleMap &) const |
Calculate the bounding paint rect of 2 maps. | |
QRect | transform (const QwtScaleMap &, const QwtScaleMap &, const QwtDoubleRect &) const |
QwtDoubleRect | invTransform (const QwtScaleMap &, const QwtScaleMap &, const QRect &) const |
Base class for items on the plot canvas.
A plot item is "something", that can be painted on the plot canvas, or only affects the scales of the plot widget. They can be categorized as:
Depending on the QwtPlotItem::ItemAttribute flags, an item is included into autoscaling or has an entry on the legnd.
Before misusing the existing item classes it might be better to implement a new type of plot item ( don't implement a watermark as spectrogram ). Deriving a new type of QwtPlotItem primarily means to implement the YourPlotItem::draw() method.
Definition at line 65 of file qwt_plot_item.h.
Plot Item Attributes
Definition at line 100 of file qwt_plot_item.h.
Runtime type information.
RttiValues is used to cast plot items, without having to enable runtime type information of the compiler.
Rtti_PlotItem | |
Rtti_PlotGrid | |
Rtti_PlotScale | |
Rtti_PlotMarker | |
Rtti_PlotCurve | |
Rtti_PlotHistogram | |
Rtti_PlotSpectrogram | |
Rtti_PlotSVG | |
Rtti_PlotUserItem |
Definition at line 74 of file qwt_plot_item.h.
Constructor
title | Title of the item |
Definition at line 51 of file qwt_plot_item.cpp.
References title(), and QwtPlotItem::PrivateData::title.
QwtPlotItem::~QwtPlotItem | ( | ) | [virtual] |
Destroy the QwtPlotItem.
Definition at line 58 of file qwt_plot_item.cpp.
References attach().
{ attach(NULL); delete d_data; }
void QwtPlotItem::attach | ( | QwtPlot * | plot ) |
Attach the item to a plot.
This method will attach a QwtPlotItem to the QwtPlot argument. It will first detach the QwtPlotItem from any plot from a previous call to attach (if necessary). If a NULL argument is passed, it will detach from any QwtPlot it was attached to.
plot | Plot widget |
Definition at line 75 of file qwt_plot_item.cpp.
References QwtPlot::autoReplot(), QwtLegend::find(), itemChanged(), QwtPlot::legend(), legendItem(), plot(), and QwtPlotItem::PrivateData::plot.
Referenced by QwtPlotDict::detachItems(), QmitkHistogramWidget::InitializeMarker(), QmitkPlotWidget::InsertCurve(), QmitkHistogramWidget::QmitkHistogramWidget(), QmitkHistogramWidget::SetHistogram(), and ~QwtPlotItem().
{ if ( plot == d_data->plot ) return; // remove the item from the previous plot if ( d_data->plot ) { if ( d_data->plot->legend() ) { QWidget *legendItem = d_data->plot->legend()->find(this); if ( legendItem ) delete legendItem; } d_data->plot->attachItem(this, false); if ( d_data->plot->autoReplot() ) d_data->plot->update(); } d_data->plot = plot; if ( d_data->plot ) { // insert the item into the current plot d_data->plot->attachItem(this, true); itemChanged(); } }
QwtDoubleRect QwtPlotItem::boundingRect | ( | ) | const [virtual] |
Reimplemented in QmitkHistogram, QwtPlotCurve, QwtPlotMarker, QwtPlotSpectrogram, and QwtPlotSvgItem.
Definition at line 392 of file qwt_plot_item.cpp.
Referenced by QwtPlotRasterItem::draw(), QwtPlotCurve::maxXValue(), QwtPlotCurve::maxYValue(), QwtPlotCurve::minXValue(), QwtPlotCurve::minYValue(), and QwtPlot::updateAxes().
{ return QwtDoubleRect(1.0, 1.0, -2.0, -2.0); // invalid }
void QwtPlotItem::detach | ( | ) | [inline] |
This method detaches a QwtPlotItem from any QwtPlot it has been associated with.
detach() is equivalent to calling attach( NULL )
Definition at line 126 of file qwt_plot_item.h.
{ attach(NULL); }
virtual void QwtPlotItem::draw | ( | QPainter * | painter, |
const QwtScaleMap & | xMap, | ||
const QwtScaleMap & | yMap, | ||
const QRect & | canvasRect | ||
) | const [pure virtual] |
Draw the item.
painter | Painter |
xMap | Maps x-values into pixel coordinates. |
yMap | Maps y-values into pixel coordinates. |
canvasRect | Contents rect of the canvas in painter coordinates |
Implemented in QmitkHistogram, QwtPlotCurve, QwtPlotGrid, QwtPlotMarker, QwtPlotRasterItem, QwtPlotScaleItem, QwtPlotSpectrogram, and QwtPlotSvgItem.
Referenced by QwtPlot::drawItems().
void QwtPlotItem::hide | ( | ) |
Hide the item.
Definition at line 276 of file qwt_plot_item.cpp.
References setVisible().
{ setVisible(false); }
QwtDoubleRect QwtPlotItem::invTransform | ( | const QwtScaleMap & | xMap, |
const QwtScaleMap & | yMap, | ||
const QRect & | rect | ||
) | const |
Transform a rectangle from paint to scale coordinates
xMap | X map |
yMap | Y map |
rect | Rectangle in paint coordinates |
Definition at line 553 of file qwt_plot_item.cpp.
References QwtScaleMap::invTransform(), and QwtDoubleRect::normalized().
Referenced by QwtPlotSvgItem::draw(), QwtPlotSpectrogram::draw(), and QwtPlotRasterItem::draw().
{ const double x1 = xMap.invTransform(rect.left()); const double x2 = xMap.invTransform(rect.right()); const double y1 = yMap.invTransform(rect.top()); const double y2 = yMap.invTransform(rect.bottom()); const QwtDoubleRect r(x1, y1, x2 - x1, y2 - y1); return r.normalized(); }
bool QwtPlotItem::isVisible | ( | ) | const |
Definition at line 300 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::isVisible.
Referenced by QwtPlot::drawItems().
{ return d_data->isVisible; }
void QwtPlotItem::itemChanged | ( | ) | [virtual] |
Update the legend and call QwtPlot::autoRefresh for the parent plot.
Definition at line 311 of file qwt_plot_item.cpp.
References QwtPlot::autoRefresh(), QwtPlot::legend(), QwtPlotItem::PrivateData::plot, and updateLegend().
Referenced by attach(), QwtPlotGrid::enableX(), QwtPlotGrid::enableXMin(), QwtPlotGrid::enableY(), QwtPlotGrid::enableYMin(), QwtPlotSvgItem::loadData(), QwtPlotSvgItem::loadFile(), QwtPlotScaleItem::setAlignment(), QwtPlotRasterItem::setAlpha(), setAxis(), QwtPlotCurve::setBaseline(), QmitkHistogram::setBaseline(), QwtPlotScaleItem::setBorderDistance(), QwtPlotCurve::setBrush(), QwtPlotRasterItem::setCachePolicy(), QmitkHistogram::setColor(), QwtPlotScaleItem::setColorGroup(), QwtPlotSpectrogram::setColorMap(), QwtPlotSpectrogram::setConrecAttribute(), QwtPlotSpectrogram::setContourLevels(), QwtPlotCurve::setCurveAttribute(), QwtPlotCurve::setCurveFitter(), QwtPlotCurve::setCurveType(), QwtPlotSpectrogram::setData(), QwtPlotCurve::setData(), QmitkHistogram::setData(), QwtPlotSpectrogram::setDefaultContourPen(), QwtPlotSpectrogram::setDisplayMode(), QwtPlotScaleItem::setFont(), setItemAttribute(), QwtPlotMarker::setLabel(), QwtPlotMarker::setLabelOrientation(), QwtPlotMarker::setLinePen(), QwtPlotMarker::setLineStyle(), QwtPlotGrid::setMajPen(), QwtPlotGrid::setMinPen(), QwtPlotGrid::setPen(), QwtPlotCurve::setPen(), QwtPlotScaleItem::setPosition(), QwtPlotCurve::setRawData(), QwtPlotScaleItem::setScaleDivFromAxis(), QwtPlotScaleItem::setScaleDraw(), QwtPlotMarker::setSpacing(), QwtPlotCurve::setStyle(), QwtPlotMarker::setSymbol(), QwtPlotCurve::setSymbol(), setTitle(), QwtPlotMarker::setValue(), setVisible(), setXAxis(), QwtPlotGrid::setXDiv(), setYAxis(), QwtPlotGrid::setYDiv(), and setZ().
{ if ( d_data->plot ) { if ( d_data->plot->legend() ) updateLegend(d_data->plot->legend()); d_data->plot->autoRefresh(); } }
QWidget * QwtPlotItem::legendItem | ( | ) | const [virtual] |
Allocate the widget that represents the item on the legend.
The default implementation is made for QwtPlotCurve and returns a QwtLegendItem(), but an item could be represented by any type of widget, by overloading legendItem() and updateLegend().
Implements QwtLegendItemManager.
Definition at line 407 of file qwt_plot_item.cpp.
Referenced by attach(), updateLegend(), and QwtPlotCurve::updateLegend().
{ return new QwtLegendItem; }
QRect QwtPlotItem::paintRect | ( | const QwtScaleMap & | xMap, |
const QwtScaleMap & | yMap | ||
) | const |
Calculate the bounding paint rect of 2 maps.
xMap | X map |
yMap | X map |
Definition at line 509 of file qwt_plot_item.cpp.
References QwtScaleMap::p1(), and QwtScaleMap::pDist().
Referenced by QwtPlotRasterItem::draw().
QwtPlot * QwtPlotItem::plot | ( | ) | const |
Return attached plot.
Definition at line 126 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::plot.
Referenced by attach(), QwtPlotCurve::closestPoint(), QwtPlotCurve::draw(), QwtPlotScaleItem::setScaleDivFromAxis(), and QwtPlotScaleItem::setScaleDraw().
{ return d_data->plot; }
int QwtPlotItem::rtti | ( | ) | const [virtual] |
Return rtti for the specific class represented. QwtPlotItem is simply a virtual interface class, and base classes will implement this method with specific rtti values so a user can differentiate them.
The rtti value is useful for environments, where the runtime type information is disabled and it is not possible to do a dynamic_cast<...>.
Reimplemented in QwtPlotCurve, QwtPlotGrid, QwtPlotMarker, QwtPlotScaleItem, QwtPlotSpectrogram, and QwtPlotSvgItem.
Definition at line 120 of file qwt_plot_item.cpp.
References Rtti_PlotItem.
Referenced by QwtPlotPrintFilter::apply(), QwtPlotDict::detachItems(), QwtPlot::drawItems(), and QwtPlotPrintFilter::reset().
{ return Rtti_PlotItem; }
QwtDoubleRect QwtPlotItem::scaleRect | ( | const QwtScaleMap & | xMap, |
const QwtScaleMap & | yMap | ||
) | const |
Calculate the bounding scale rect of 2 maps.
xMap | X map |
yMap | X map |
Definition at line 494 of file qwt_plot_item.cpp.
References QwtScaleMap::s1(), and QwtScaleMap::sDist().
{ return QwtDoubleRect(xMap.s1(), yMap.s1(), xMap.sDist(), yMap.sDist() ); }
void QwtPlotItem::setAxis | ( | int | xAxis, |
int | yAxis | ||
) |
Set X and Y axis
The item will painted according to the coordinates its Axes.
xAxis | X Axis |
yAxis | Y Axis |
Definition at line 332 of file qwt_plot_item.cpp.
References itemChanged(), xAxis(), QwtPlotItem::PrivateData::xAxis, QwtPlot::xBottom, QwtPlot::xTop, yAxis(), QwtPlotItem::PrivateData::yAxis, QwtPlot::yLeft, and QwtPlot::yRight.
{ if (xAxis == QwtPlot::xBottom || xAxis == QwtPlot::xTop ) d_data->xAxis = xAxis; if (yAxis == QwtPlot::yLeft || yAxis == QwtPlot::yRight ) d_data->yAxis = yAxis; itemChanged(); }
void QwtPlotItem::setItemAttribute | ( | ItemAttribute | attribute, |
bool | on = true |
||
) |
Toggle an item attribute
attribute | Attribute type |
on | true/false |
Definition at line 207 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::attributes, and itemChanged().
Referenced by QwtPlotCurve::init(), and QwtPlotSpectrogram::QwtPlotSpectrogram().
{ if ( bool(d_data->attributes & attribute) != on ) { if ( on ) d_data->attributes |= attribute; else d_data->attributes &= ~attribute; itemChanged(); } }
void QwtPlotItem::setTitle | ( | const QString & | title ) |
void QwtPlotItem::setTitle | ( | const QwtText & | title ) |
Set a new title
title | Title |
Definition at line 181 of file qwt_plot_item.cpp.
References itemChanged(), title(), and QwtPlotItem::PrivateData::title.
{ if ( d_data->title != title ) { d_data->title = title; itemChanged(); } }
void QwtPlotItem::setVisible | ( | bool | on ) | [virtual] |
Show/Hide the item
on | Show if true, otherwise hide |
Definition at line 287 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::isVisible, and itemChanged().
Referenced by hide(), and show().
{ if ( on != d_data->isVisible ) { d_data->isVisible = on; itemChanged(); } }
void QwtPlotItem::setXAxis | ( | int | axis ) |
Set the X axis
The item will painted according to the coordinates its Axes.
axis | X Axis |
Definition at line 351 of file qwt_plot_item.cpp.
References itemChanged(), QwtPlotItem::PrivateData::xAxis, QwtPlot::xBottom, and QwtPlot::xTop.
{ if (axis == QwtPlot::xBottom || axis == QwtPlot::xTop ) { d_data->xAxis = axis; itemChanged(); } }
void QwtPlotItem::setYAxis | ( | int | axis ) |
Set the Y axis
The item will painted according to the coordinates its Axes.
axis | Y Axis |
Definition at line 368 of file qwt_plot_item.cpp.
References itemChanged(), QwtPlotItem::PrivateData::yAxis, QwtPlot::yLeft, and QwtPlot::yRight.
{ if (axis == QwtPlot::yLeft || axis == QwtPlot::yRight ) { d_data->yAxis = axis; itemChanged(); } }
void QwtPlotItem::setZ | ( | double | z ) |
Set the z value.
Plot items are painted in increasing z-order.
z | Z-value |
Definition at line 149 of file qwt_plot_item.cpp.
References itemChanged(), QwtPlotItem::PrivateData::plot, z(), and QwtPlotItem::PrivateData::z.
Referenced by QwtPlotCurve::init(), QwtPlotGrid::QwtPlotGrid(), QwtPlotMarker::QwtPlotMarker(), QwtPlotScaleItem::QwtPlotScaleItem(), and QwtPlotSpectrogram::QwtPlotSpectrogram().
void QwtPlotItem::show | ( | ) |
Show the item.
Definition at line 270 of file qwt_plot_item.cpp.
References setVisible().
{ setVisible(true); }
bool QwtPlotItem::testItemAttribute | ( | ItemAttribute | attribute ) | const |
Test an item attribute
attribute | Attribute type |
Definition at line 227 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::attributes.
Referenced by QwtPlot::updateAxes(), and updateLegend().
{ return d_data->attributes & attribute; }
const QwtText & QwtPlotItem::title | ( | ) | const |
Definition at line 194 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::title.
Referenced by QwtPlotItem(), setTitle(), and QwtPlotCurve::updateLegend().
{ return d_data->title; }
QRect QwtPlotItem::transform | ( | const QwtScaleMap & | xMap, |
const QwtScaleMap & | yMap, | ||
const QwtDoubleRect & | rect | ||
) | const |
Transform a rectangle
xMap | X map |
yMap | Y map |
rect | Rectangle in scale coordinates |
Definition at line 528 of file qwt_plot_item.cpp.
References QwtDoubleRect::bottom(), QwtDoubleRect::left(), QwtDoubleRect::right(), QwtDoubleRect::top(), and QwtScaleMap::transform().
Referenced by QwtPlotSvgItem::draw(), QwtPlotSpectrogram::draw(), QwtPlotRasterItem::draw(), and QwtPlotSpectrogram::renderImage().
void QwtPlotItem::updateLegend | ( | QwtLegend * | legend ) | const [virtual] |
Update the widget that represents the item on the legend.
updateLegend() is called from itemChanged() to adopt the widget representing the item on the legend to its new configuration.
The default implementation is made for QwtPlotCurve and updates a QwtLegendItem(), but an item could be represented by any type of widget, by overloading legendItem() and updateLegend().
legend | Legend |
Implements QwtLegendItemManager.
Reimplemented in QwtPlotCurve.
Definition at line 426 of file qwt_plot_item.cpp.
References QwtLegend::find(), QwtLegend::insert(), QwtLegend::itemMode(), Legend, legendItem(), QwtPlotItem::PrivateData::plot, QwtLegendItem::setItemMode(), QwtLegendItem::setText(), testItemAttribute(), and QwtPlotItem::PrivateData::title.
Referenced by itemChanged().
{ if ( !legend ) return; QWidget *lgdItem = legend->find(this); if ( testItemAttribute(QwtPlotItem::Legend) ) { if ( lgdItem == NULL ) { lgdItem = legendItem(); if ( lgdItem ) { if ( lgdItem->inherits("QwtLegendItem") ) { QwtLegendItem *label = (QwtLegendItem *)lgdItem; label->setItemMode(legend->itemMode()); if ( d_data->plot ) { QObject::connect(label, SIGNAL(clicked()), d_data->plot, SLOT(legendItemClicked())); QObject::connect(label, SIGNAL(checked(bool)), d_data->plot, SLOT(legendItemChecked(bool))); } } legend->insert(this, lgdItem); } } if ( lgdItem && lgdItem->inherits("QwtLegendItem") ) { QwtLegendItem* label = (QwtLegendItem*)lgdItem; if ( label ) label->setText(d_data->title); } } else { delete lgdItem; } }
void QwtPlotItem::updateScaleDiv | ( | const QwtScaleDiv & | , |
const QwtScaleDiv & | |||
) | [virtual] |
Update the item to changes of the axes scale division.
Update the item, when the axes of plot have changed. The default implementation does nothing, but items that depend on the scale division (like QwtPlotGrid()) have to reimplement updateScaleDiv()
xScaleDiv | Scale division of the x-axis |
yScaleDiv | Scale division of the y-axis |
Reimplemented in QwtPlotGrid, and QwtPlotScaleItem.
Definition at line 481 of file qwt_plot_item.cpp.
Referenced by QwtPlot::updateAxes().
{ }
int QwtPlotItem::xAxis | ( | ) | const |
Return xAxis.
Definition at line 378 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::xAxis.
Referenced by QwtPlotCurve::closestPoint(), QwtPlotCurve::draw(), QwtPlot::drawItems(), setAxis(), QwtPlotScaleItem::setScaleDivFromAxis(), QwtPlotScaleItem::setScaleDraw(), and QwtPlot::updateAxes().
{ return d_data->xAxis; }
int QwtPlotItem::yAxis | ( | ) | const |
Return yAxis.
Definition at line 384 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::yAxis.
Referenced by QwtPlotCurve::closestPoint(), QwtPlotCurve::draw(), QwtPlot::drawItems(), setAxis(), QwtPlotScaleItem::setScaleDivFromAxis(), QwtPlotScaleItem::setScaleDraw(), and QwtPlot::updateAxes().
{ return d_data->yAxis; }
double QwtPlotItem::z | ( | ) | const |
Plot items are painted in increasing z-order.
Definition at line 136 of file qwt_plot_item.cpp.
References QwtPlotItem::PrivateData::z.
Referenced by QwtPlotDict::PrivateData::ItemList::insertItem(), and setZ().
{ return d_data->z; }