Qwt User's Guide  5.2.3
Public Types | Public Slots | Signals | Public Member Functions | Protected Slots | Protected Member Functions | Static Protected Member Functions
QwtPlot Class Reference

#include <qwt_plot.h>

Inheritance diagram for QwtPlot:
Inheritance graph
[legend]

List of all members.

Public Types

enum  Axis {
  yLeft,
  yRight,
  xBottom,
  xTop,
  axisCnt
}
enum  LegendPosition {
  LeftLegend,
  RightLegend,
  BottomLegend,
  TopLegend,
  ExternalLegend
}

Public Slots

void autoRefresh ()
virtual void clear ()
virtual void replot ()

Signals

void legendChecked (QwtPlotItem *plotItem, bool on)
void legendClicked (QwtPlotItem *plotItem)

Public Member Functions

 QwtPlot (QWidget *=NULL)
 QwtPlot (const QwtText &title, QWidget *p=NULL)
virtual ~QwtPlot ()
void applyProperties (const QString &)
bool autoReplot () const
bool axisAutoScale (int axisId) const
bool axisEnabled (int axisId) const
QFont axisFont (int axisId) const
int axisMaxMajor (int axisId) const
int axisMaxMinor (int axisId) const
const QwtScaleDivaxisScaleDiv (int axisId) const
QwtScaleDivaxisScaleDiv (int axisId)
const QwtScaleDrawaxisScaleDraw (int axisId) const
QwtScaleDrawaxisScaleDraw (int axisId)
QwtScaleEngineaxisScaleEngine (int axisId)
const QwtScaleEngineaxisScaleEngine (int axisId) const
double axisStepSize (int axisId) const
QwtText axisTitle (int axisId) const
const QwtScaleWidgetaxisWidget (int axisId) const
QwtScaleWidgetaxisWidget (int axisId)
QwtPlotCanvascanvas ()
const QwtPlotCanvascanvas () const
const QColor & canvasBackground () const
int canvasLineWidth () const
virtual QwtScaleMap canvasMap (int axisId) const
virtual void drawCanvas (QPainter *)
void enableAxis (int axisId, bool tf=true)
virtual bool event (QEvent *)
QString grabProperties () const
void insertLegend (QwtLegend *, LegendPosition=QwtPlot::RightLegend, double ratio=-1.0)
double invTransform (int axisId, int pos) const
QwtLegendlegend ()
const QwtLegendlegend () const
int margin () const
virtual QSize minimumSizeHint () const
QwtPlotLayoutplotLayout ()
const QwtPlotLayoutplotLayout () const
virtual void polish ()
void print (QPaintDevice &p, const QwtPlotPrintFilter &=QwtPlotPrintFilter()) const
virtual void print (QPainter *, const QRect &rect, const QwtPlotPrintFilter &=QwtPlotPrintFilter()) const
void setAutoReplot (bool tf=true)
void setAxisAutoScale (int axisId)
void setAxisFont (int axisId, const QFont &f)
void setAxisLabelAlignment (int axisId, Qt::Alignment)
void setAxisLabelRotation (int axisId, double rotation)
void setAxisMaxMajor (int axisId, int maxMajor)
void setAxisMaxMinor (int axisId, int maxMinor)
void setAxisScale (int axisId, double min, double max, double step=0)
void setAxisScaleDiv (int axisId, const QwtScaleDiv &)
void setAxisScaleDraw (int axisId, QwtScaleDraw *)
void setAxisScaleEngine (int axisId, QwtScaleEngine *)
void setAxisTitle (int axisId, const QString &)
void setAxisTitle (int axisId, const QwtText &)
void setCanvasBackground (const QColor &c)
void setCanvasLineWidth (int w)
void setMargin (int margin)
void setTitle (const QString &)
void setTitle (const QwtText &t)
virtual QSize sizeHint () const
QwtText title () const
QwtTextLabeltitleLabel ()
const QwtTextLabeltitleLabel () const
int transform (int axisId, double value) const
void updateAxes ()
virtual void updateLayout ()
- Public Member Functions inherited from QwtPlotDict
 QwtPlotDict ()
 ~QwtPlotDict ()
bool autoDelete () const
void detachItems (int rtti=QwtPlotItem::Rtti_PlotItem, bool autoDelete=true)
const QwtPlotItemList & itemList () const
void setAutoDelete (bool)

Protected Slots

virtual void legendItemChecked (bool)
virtual void legendItemClicked ()

Protected Member Functions

virtual void drawItems (QPainter *, const QRect &, const QwtScaleMap maps[axisCnt], const QwtPlotPrintFilter &) const
virtual void printCanvas (QPainter *, const QRect &boundingRect, const QRect &canvasRect, const QwtScaleMap maps[axisCnt], const QwtPlotPrintFilter &) const
virtual void printLegend (QPainter *, const QRect &) const
virtual void printLegendItem (QPainter *, const QWidget *, const QRect &) const
virtual void printScale (QPainter *, int axisId, int startDist, int endDist, int baseDist, const QRect &) const
virtual void printTitle (QPainter *, const QRect &) const
virtual void resizeEvent (QResizeEvent *e)
virtual void updateTabOrder ()

Static Protected Member Functions

static bool axisValid (int axisId)

Detailed Description

A 2-D plotting widget.

QwtPlot is a widget for plotting two-dimensional graphs. An unlimited number of plot items can be displayed on its canvas. Plot items might be curves (QwtPlotCurve), markers (QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived from QwtPlotItem. A plot can have up to four axes, with each plot item attached to an x- and a y axis. The scales at the axes can be explicitely set (QwtScaleDiv), or are calculated from the plot items, using algorithms (QwtScaleEngine) which can be configured separately for each axis.

plot.png
Example
The following example shows (schematically) the most simple way to use QwtPlot. By default, only the left and bottom axes are visible and their scales are computed automatically.
#include <qwt_plot.h>
#include <qwt_plot_curve.h>

QwtPlot *myPlot = new QwtPlot("Two Curves", parent);

// add curves
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");

// copy the data into the curves
curve1->setData(...);
curve2->setData(...);

curve1->attach(myPlot);
curve2->attach(myPlot);

// finally, refresh the plot
myPlot->replot();

Member Enumeration Documentation

Axis index

  • yLeft
  • yRight
  • xBottom
  • xTop

Position of the legend, relative to the canvas.

  • LeftLegend
    The legend will be left from the yLeft axis.
  • RightLegend
    The legend will be right from the yLeft axis.
  • BottomLegend
    The legend will be right below the xBottom axis.
  • TopLegend
    The legend will be between xTop axis and the title.
  • ExternalLegend
    External means that only the content of the legend will be handled by QwtPlot, but not its geometry. This might be interesting if an application wants to have a legend in an external window ( or on the canvas ).
Note:
In case of ExternalLegend, the legend is not printed by print().
See also:
insertLegend()

Constructor & Destructor Documentation

QwtPlot::QwtPlot ( QWidget *  parent = NULL)
explicit

Constructor.

Parameters:
parentParent widget
QwtPlot::QwtPlot ( const QwtText title,
QWidget *  parent = NULL 
)
explicit

Constructor.

Parameters:
titleTitle text
parentParent widget

Member Function Documentation

void QwtPlot::applyProperties ( const QString &  )

This method is intended for manipulating the plot widget from a specific editor in the Qwt designer plugin.

Warning:
The plot editor has never been implemented.
bool QwtPlot::autoReplot ( ) const
Returns:
true if the autoReplot option is set.
bool QwtPlot::axisAutoScale ( int  axisId) const
Returns:
true if autoscaling is enabled
Parameters:
axisIdaxis index
bool QwtPlot::axisEnabled ( int  axisId) const
Returns:
true if a specified axis is enabled
Parameters:
axisIdaxis index
QFont QwtPlot::axisFont ( int  axisId) const
Returns:
the font of the scale labels for a specified axis
Parameters:
axisIdaxis index
int QwtPlot::axisMaxMajor ( int  axisId) const
Returns:
the maximum number of major ticks for a specified axis
Parameters:
axisIdaxis index sa setAxisMaxMajor()
int QwtPlot::axisMaxMinor ( int  axisId) const
Returns:
the maximum number of minor ticks for a specified axis
Parameters:
axisIdaxis index sa setAxisMaxMinor()
const QwtScaleDiv * QwtPlot::axisScaleDiv ( int  axisId) const

Return the scale division of a specified axis.

axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound() are the current limits of the axis scale.

Parameters:
axisIdaxis index
Returns:
Scale division
See also:
QwtScaleDiv, setAxisScaleDiv()
QwtScaleDiv * QwtPlot::axisScaleDiv ( int  axisId)

Return the scale division of a specified axis.

axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound() are the current limits of the axis scale.

Parameters:
axisIdaxis index
Returns:
Scale division
See also:
QwtScaleDiv, setAxisScaleDiv()
const QwtScaleDraw * QwtPlot::axisScaleDraw ( int  axisId) const
Returns:
the scale draw of a specified axis
Parameters:
axisIdaxis index
Returns:
specified scaleDraw for axis, or NULL if axis is invalid.
See also:
QwtScaleDraw
QwtScaleDraw * QwtPlot::axisScaleDraw ( int  axisId)
Returns:
the scale draw of a specified axis
Parameters:
axisIdaxis index
Returns:
specified scaleDraw for axis, or NULL if axis is invalid.
See also:
QwtScaleDraw
QwtScaleEngine * QwtPlot::axisScaleEngine ( int  axisId)
Parameters:
axisIdaxis index
Returns:
Scale engine for a specific axis
const QwtScaleEngine * QwtPlot::axisScaleEngine ( int  axisId) const
Parameters:
axisIdaxis index
Returns:
Scale engine for a specific axis
double QwtPlot::axisStepSize ( int  axisId) const

Return the step size parameter, that has been set in setAxisScale. This doesn't need to be the step size of the current scale.

Parameters:
axisIdaxis index
Returns:
step size parameter value
See also:
setAxisScale()
QwtText QwtPlot::axisTitle ( int  axisId) const
Returns:
the title of a specified axis
Parameters:
axisIdaxis index
bool QwtPlot::axisValid ( int  axisId)
staticprotected
Returns:
true if the specified axis exists, otherwise false
Parameters:
axisIdaxis index
const QwtScaleWidget * QwtPlot::axisWidget ( int  axisId) const
Returns:
specified axis, or NULL if axisId is invalid.
Parameters:
axisIdaxis index
QwtScaleWidget * QwtPlot::axisWidget ( int  axisId)
Returns:
specified axis, or NULL if axisId is invalid.
Parameters:
axisIdaxis index
QwtPlotCanvas * QwtPlot::canvas ( )
Returns:
the plot's canvas
const QwtPlotCanvas * QwtPlot::canvas ( ) const
Returns:
the plot's canvas
const QColor & QwtPlot::canvasBackground ( ) const

Nothing else than: canvas()->palette().color( QPalette::Normal, QColorGroup::Background);

Returns:
the background color of the plotting area.
int QwtPlot::canvasLineWidth ( ) const

Nothing else than: canvas()->lineWidth(), left for compatibility only.

Returns:
the border width of the plotting area
QwtScaleMap QwtPlot::canvasMap ( int  axisId) const
virtual
Parameters:
axisIdAxis
Returns:
Map for the axis on the canvas. With this map pixel coordinates can translated to plot coordinates and vice versa.
See also:
QwtScaleMap, transform(), invTransform()
void QwtPlot::clear ( )
virtualslot

Remove all curves and markers

Deprecated:
Use QwtPlotDeict::detachItems instead
void QwtPlot::drawCanvas ( QPainter *  painter)
virtual

Redraw the canvas.

Parameters:
painterPainter used for drawing
Warning:
drawCanvas calls drawItems what is also used for printing. Applications that like to add individual plot items better overload drawItems()
See also:
drawItems()
void QwtPlot::drawItems ( QPainter *  painter,
const QRect &  rect,
const QwtScaleMap  map[axisCnt],
const QwtPlotPrintFilter pfilter 
) const
protectedvirtual

Redraw the canvas items.

Parameters:
painterPainter used for drawing
rectBounding rectangle where to paint
mapQwtPlot::axisCnt maps, mapping between plot and paint device coordinates
pfilterPlot print filter
void QwtPlot::enableAxis ( int  axisId,
bool  tf = true 
)

Enable or disable a specified axis.

When an axis is disabled, this only means that it is not visible on the screen. Curves, markers and can be attached to disabled axes, and transformation of screen coordinates into values works as normal.

Only xBottom and yLeft are enabled by default.

Parameters:
axisIdaxis index
tftrue (enabled) or false (disabled)
QString QwtPlot::grabProperties ( ) const

This method is intended for manipulating the plot widget from a specific editor in the Qwt designer plugin.

Warning:
The plot editor has never been implemented.
void QwtPlot::insertLegend ( QwtLegend legend,
QwtPlot::LegendPosition  pos = QwtPlot::RightLegend,
double  ratio = -1.0 
)

Insert a legend.

If the position legend is QwtPlot::LeftLegend or QwtPlot::RightLegend the legend will be organized in one column from top to down. Otherwise the legend items will be placed in a table with a best fit number of columns from left to right.

If pos != QwtPlot::ExternalLegend the plot widget will become parent of the legend. It will be deleted when the plot is deleted, or another legend is set with insertLegend().

Parameters:
legendLegend
posThe legend's position. For top/left position the number of colums will be limited to 1, otherwise it will be set to unlimited.
ratioRatio between legend and the bounding rect of title, canvas and axes. The legend will be shrinked if it would need more space than the given ratio. The ratio is limited to ]0.0 .. 1.0]. In case of <= 0.0 it will be reset to the default ratio. The default vertical/horizontal ratio is 0.33/0.5.
See also:
legend(), QwtPlotLayout::legendPosition(), QwtPlotLayout::setLegendPosition()
double QwtPlot::invTransform ( int  axisId,
int  pos 
) const

Transform the x or y coordinate of a position in the drawing region into a value.

Parameters:
axisIdaxis index
posposition
Warning:
The position can be an x or a y coordinate, depending on the specified axis.
QwtLegend * QwtPlot::legend ( )
Returns:
the plot's legend
See also:
insertLegend()
const QwtLegend * QwtPlot::legend ( ) const
Returns:
the plot's legend
See also:
insertLegend()
void QwtPlot::legendChecked ( QwtPlotItem plotItem,
bool  on 
)
signal

A signal which is emitted when the user has clicked on a legend item, which is in QwtLegend::CheckableItem mode

Parameters:
plotItemCorresponding plot item of the selected legend item
onTrue when the legen item is checked
Note:
clicks are disabled as default
See also:
QwtLegend::setItemMode(), QwtLegend::itemMode()
void QwtPlot::legendClicked ( QwtPlotItem plotItem)
signal

A signal which is emitted when the user has clicked on a legend item, which is in QwtLegend::ClickableItem mode.

Parameters:
plotItemCorresponding plot item of the selected legend item
Note:
clicks are disabled as default
See also:
QwtLegend::setItemMode(), QwtLegend::itemMode()
void QwtPlot::legendItemChecked ( bool  on)
protectedvirtualslot

Called internally when the legend has been checked Emits a legendClicked() signal.

void QwtPlot::legendItemClicked ( )
protectedvirtualslot

Called internally when the legend has been clicked on. Emits a legendClicked() signal.

int QwtPlot::margin ( ) const
QwtPlotLayout * QwtPlot::plotLayout ( )
Returns:
the plot's title
const QwtPlotLayout * QwtPlot::plotLayout ( ) const
Returns:
the plot's titel label.
void QwtPlot::print ( QPaintDevice &  paintDev,
const QwtPlotPrintFilter pfilter = QwtPlotPrintFilter() 
) const

Print the plot to a QPaintDevice (QPrinter) This function prints the contents of a QwtPlot instance to QPaintDevice object. The size is derived from its device metrics.

Parameters:
paintDevdevice to paint on, often a printer
pfilterprint filter
See also:
QwtPlotPrintFilter
void QwtPlot::print ( QPainter *  painter,
const QRect &  plotRect,
const QwtPlotPrintFilter pfilter = QwtPlotPrintFilter() 
) const
virtual

Paint the plot into a given rectangle. Paint the contents of a QwtPlot instance into a given rectangle.

Parameters:
painterPainter
plotRectBounding rectangle
pfilterPrint filter
See also:
QwtPlotPrintFilter
void QwtPlot::printCanvas ( QPainter *  painter,
const QRect &  boundingRect,
const QRect &  canvasRect,
const QwtScaleMap  map[axisCnt],
const QwtPlotPrintFilter pfilter 
) const
protectedvirtual

Print the canvas into a given rectangle.

Parameters:
painterPainter
mapMaps mapping between plot and paint device coordinates
boundingRectBounding rectangle
canvasRectCanvas rectangle
pfilterPrint filter
See also:
QwtPlotPrintFilter
void QwtPlot::printLegend ( QPainter *  painter,
const QRect &  rect 
) const
protectedvirtual

Print the legend into a given rectangle.

Parameters:
painterPainter
rectBounding rectangle
void QwtPlot::printLegendItem ( QPainter *  painter,
const QWidget *  w,
const QRect &  rect 
) const
protectedvirtual

Print the legend item into a given rectangle.

Parameters:
painterPainter
wWidget representing a legend item
rectBounding rectangle
void QwtPlot::printScale ( QPainter *  painter,
int  axisId,
int  startDist,
int  endDist,
int  baseDist,
const QRect &  rect 
) const
protectedvirtual

Paint a scale into a given rectangle. Paint the scale into a given rectangle.

Parameters:
painterPainter
axisIdAxis
startDistStart border distance
endDistEnd border distance
baseDistBase distance
rectBounding rectangle
void QwtPlot::printTitle ( QPainter *  painter,
const QRect &  rect 
) const
protectedvirtual

Print the title into a given rectangle.

Parameters:
painterPainter
rectBounding rectangle
void QwtPlot::replot ( )
virtualslot

Redraw the plot.

If the autoReplot option is not set (which is the default) or if any curves are attached to raw data, the plot has to be refreshed explicitly in order to make changes visible.

See also:
setAutoReplot()
Warning:
Calls canvas()->repaint, take care of infinite recursions
void QwtPlot::resizeEvent ( QResizeEvent *  e)
protectedvirtual

Resize and update internal layout

Parameters:
eResize event
void QwtPlot::setAutoReplot ( bool  tf = true)

Set or reset the autoReplot option.

If the autoReplot option is set, the plot will be updated implicitly by manipulating member functions. Since this may be time-consuming, it is recommended to leave this option switched off and call replot() explicitly if necessary.

The autoReplot option is set to false by default, which means that the user has to call replot() in order to make changes visible.

Parameters:
tftrue or false. Defaults to true.
See also:
replot()
void QwtPlot::setAxisAutoScale ( int  axisId)

Enable autoscaling for a specified axis.

This member function is used to switch back to autoscaling mode after a fixed scale has been set. Autoscaling is enabled by default.

Parameters:
axisIdaxis index
See also:
setAxisScale(), setAxisScaleDiv()
void QwtPlot::setAxisFont ( int  axisId,
const QFont &  f 
)

Change the font of an axis.

Parameters:
axisIdaxis index
ffont
Warning:
This function changes the font of the tick labels, not of the axis title.
void QwtPlot::setAxisLabelAlignment ( int  axisId,
Qt::Alignment  alignment 
)

Change the alignment of the tick labels

Parameters:
axisIdaxis index
alignmentOr'd Qt::AlignmentFlags <see qnamespace.h>
See also:
QwtScaleDraw::setLabelAlignment()
void QwtPlot::setAxisLabelRotation ( int  axisId,
double  rotation 
)

Rotate all tick labels

Parameters:
axisIdaxis index
rotationAngle in degrees. When changing the label rotation, the label alignment might be adjusted too.
See also:
QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment()
void QwtPlot::setAxisMaxMajor ( int  axisId,
int  maxMajor 
)

Set the maximum number of major scale intervals for a specified axis

Parameters:
axisIdaxis index
maxMajormaximum number of major steps
See also:
axisMaxMajor()
void QwtPlot::setAxisMaxMinor ( int  axisId,
int  maxMinor 
)

Set the maximum number of minor scale intervals for a specified axis

Parameters:
axisIdaxis index
maxMinormaximum number of minor steps
See also:
axisMaxMinor()
void QwtPlot::setAxisScale ( int  axisId,
double  min,
double  max,
double  stepSize = 0 
)

Disable autoscaling and specify a fixed scale for a selected axis.

Parameters:
axisIdaxis index
min
maxminimum and maximum of the scale
stepSizeMajor step size. If step == 0, the step size is calculated automatically using the maxMajor setting.
See also:
setAxisMaxMajor(), setAxisAutoScale()
void QwtPlot::setAxisScaleDiv ( int  axisId,
const QwtScaleDiv scaleDiv 
)

Disable autoscaling and specify a fixed scale for a selected axis.

Parameters:
axisIdaxis index
scaleDivScale division
See also:
setAxisScale(), setAxisAutoScale()
void QwtPlot::setAxisScaleDraw ( int  axisId,
QwtScaleDraw scaleDraw 
)

Set a scale draw.

Parameters:
axisIdaxis index
scaleDrawobject responsible for drawing scales.

By passing scaleDraw it is possible to extend QwtScaleDraw functionality and let it take place in QwtPlot. Please note that scaleDraw has to be created with new and will be deleted by the corresponding QwtScale member ( like a child object ).

See also:
QwtScaleDraw, QwtScaleWidget
Warning:
The attributes of scaleDraw will be overwritten by those of the previous QwtScaleDraw.
void QwtPlot::setAxisScaleEngine ( int  axisId,
QwtScaleEngine scaleEngine 
)

Change the scale engine for an axis

Parameters:
axisIdaxis index
scaleEngineScale engine
See also:
axisScaleEngine()
void QwtPlot::setAxisTitle ( int  axisId,
const QString &  title 
)

Change the title of a specified axis.

Parameters:
axisIdaxis index
titleaxis title
void QwtPlot::setAxisTitle ( int  axisId,
const QwtText title 
)

Change the title of a specified axis.

Parameters:
axisIdaxis index
titleaxis title
void QwtPlot::setCanvasBackground ( const QColor &  c)

Change the background of the plotting area.

Sets c to QColorGroup::Background of all colorgroups of the palette of the canvas. Using canvas()->setPalette() is a more powerful way to set these colors.

Parameters:
cnew background color
void QwtPlot::setCanvasLineWidth ( int  w)

Change the border width of the plotting area Nothing else than canvas()->setLineWidth(w), left for compatibility only.

Parameters:
wnew border width
void QwtPlot::setMargin ( int  margin)

Change the margin of the plot. The margin is the space around all components.

Parameters:
marginnew margin
See also:
QwtPlotLayout::setMargin(), margin(), plotLayout()
void QwtPlot::setTitle ( const QString &  title)

Change the plot's title

Parameters:
titleNew title
void QwtPlot::setTitle ( const QwtText title)

Change the plot's title

Parameters:
titleNew title
QSize QwtPlot::sizeHint ( ) const
virtual

Return sizeHint

See also:
minimumSizeHint()
QwtText QwtPlot::title ( ) const
Returns:
the plot's title
QwtTextLabel * QwtPlot::titleLabel ( )
Returns:
the plot's titel label.
const QwtTextLabel * QwtPlot::titleLabel ( ) const
Returns:
the plot's titel label.
int QwtPlot::transform ( int  axisId,
double  value 
) const

Transform a value into a coordinate in the plotting region.

Parameters:
axisIdaxis index
valuevalue
Returns:
X or y coordinate in the plotting region corresponding to the value.
void QwtPlot::updateLayout ( )
virtual

Adjust plot content to its current size.

See also:
resizeEvent()
void QwtPlot::updateTabOrder ( )
protectedvirtual

Update the focus tab order

The order is changed so that the canvas will be in front of the first legend item, or behind the last legend item - depending on the position of the legend.