Classes | Public Types | Public Member Functions

QwtPlotItem Class Reference

Base class for items on the plot canvas. More...

#include <qwt_plot_item.h>

Inheritance diagram for QwtPlotItem:
Inheritance graph
[legend]
Collaboration diagram for QwtPlotItem:
Collaboration graph
[legend]

List of all members.

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.
QwtPlotplot () const
 Return attached plot.
void setTitle (const QString &title)
void setTitle (const QwtText &title)
const QwtTexttitle () 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

Detailed Description

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.

See also:
The cpuplot example shows the implementation of additional plot items.

Definition at line 65 of file qwt_plot_item.h.


Member Enumeration Documentation

Plot Item Attributes

  • Legend
    The item is represented on the legend.
  • AutoScale
    The boundingRect() of the item is included in the autoscaling calculation.
See also:
setItemAttribute(), testItemAttribute()
Enumerator:
Legend 
AutoScale 

Definition at line 100 of file qwt_plot_item.h.

    {
        Legend = 1,
        AutoScale = 2
    };

Runtime type information.

RttiValues is used to cast plot items, without having to enable runtime type information of the compiler.

Enumerator:
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 & Destructor Documentation

QwtPlotItem::QwtPlotItem ( const QwtText title = QwtText() ) [explicit]

Constructor

Parameters:
titleTitle of the item

Definition at line 51 of file qwt_plot_item.cpp.

References title(), and QwtPlotItem::PrivateData::title.

{
    d_data = new PrivateData;
    d_data->title = title;
}
QwtPlotItem::~QwtPlotItem (  ) [virtual]

Destroy the QwtPlotItem.

Definition at line 58 of file qwt_plot_item.cpp.

References attach().

{
    attach(NULL);
    delete d_data;
}

Member Function Documentation

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.

Parameters:
plotPlot widget
See also:
QwtPlotItem::detach()

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]
Returns:
An invalid bounding rect: QwtDoubleRect(1.0, 1.0, -2.0, -2.0)

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 )

See also:
attach( QwtPlot* plot )

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.

Parameters:
painterPainter
xMapMaps x-values into pixel coordinates.
yMapMaps y-values into pixel coordinates.
canvasRectContents 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

Parameters:
xMapX map
yMapY map
rectRectangle in paint coordinates
Returns:
Rectangle in scale coordinates
See also:
transform()

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
Returns:
true if visible
See also:
setVisible(), show(), hide()

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.

See also:
updateLegend()

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

Returns:
QwtLegendItem()
See also:
updateLegend() QwtLegend()

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.

Parameters:
xMapX map
yMapX map
Returns:
Bounding rect of the scale maps

Definition at line 509 of file qwt_plot_item.cpp.

References QwtScaleMap::p1(), and QwtScaleMap::pDist().

Referenced by QwtPlotRasterItem::draw().

{
    const QRect rect( qRound(xMap.p1()), qRound(yMap.p1()),
        qRound(xMap.pDist()), qRound(yMap.pDist()) );

    return rect;
}
QwtPlot * QwtPlotItem::plot (  ) const
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<...>.

Returns:
rtti value
See also:
RttiValues

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.

Parameters:
xMapX map
yMapX map
Returns:
Bounding rect of the scale maps

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.

Parameters:
xAxisX Axis
yAxisY Axis
See also:
setXAxis(), setYAxis(), xAxis(), yAxis()

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.

void QwtPlotItem::setItemAttribute ( ItemAttribute  attribute,
bool  on = true 
)

Toggle an item attribute

Parameters:
attributeAttribute type
ontrue/false
See also:
testItemAttribute(), ItemAttribute

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 )

Set a new title

Parameters:
titleTitle
See also:
title()

Definition at line 170 of file qwt_plot_item.cpp.

void QwtPlotItem::setTitle ( const QwtText title )

Set a new title

Parameters:
titleTitle
See also:
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

Parameters:
onShow if true, otherwise hide
See also:
isVisible(), show(), 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.

Parameters:
axisX Axis
See also:
setAxis(), setYAxis(), xAxis()

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.

Parameters:
axisY Axis
See also:
setAxis(), setXAxis(), yAxis()

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.

Parameters:
zZ-value
See also:
z(), QwtPlotDict::itemList()

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

{ 
    if ( d_data->z != z )
    {
        d_data->z = z; 
        if ( d_data->plot )
        {
            // update the z order
            d_data->plot->attachItem(this, false);
            d_data->plot->attachItem(this, true);
        }
        itemChanged();
    }
}
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

Parameters:
attributeAttribute type
Returns:
true/false
See also:
setItemAttribute(), ItemAttribute

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
Returns:
Title of the item
See also:
setTitle()

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

Parameters:
xMapX map
yMapY map
rectRectangle in scale coordinates
Returns:
Rectangle in paint coordinates
See also:
invTransform()

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

{
    int x1 = qRound(xMap.transform(rect.left()));
    int x2 = qRound(xMap.transform(rect.right()));
    int y1 = qRound(yMap.transform(rect.top()));
    int y2 = qRound(yMap.transform(rect.bottom()));

    if ( x2 < x1 )
        qSwap(x1, x2);
    if ( y2 < y1 )
        qSwap(y1, y2);

    return QRect(x1, y1, x2 - x1 + 1, y2 - y1 + 1);
}
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().

Parameters:
legendLegend
See also:
legendItem(), itemChanged(), QwtLegend()

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

Parameters:
xScaleDivScale division of the x-axis
yScaleDivScale division of the y-axis
See also:
QwtPlot::updateAxes()

Reimplemented in QwtPlotGrid, and QwtPlotScaleItem.

Definition at line 481 of file qwt_plot_item.cpp.

Referenced by QwtPlot::updateAxes().

{ 
}
int QwtPlotItem::xAxis (  ) const
int QwtPlotItem::yAxis (  ) const
double QwtPlotItem::z (  ) const

Plot items are painted in increasing z-order.

Returns:
setZ(), QwtPlotDict::itemList()

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; 
}

The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines