Scroll to navigation

QwtPlot(3) Qwt User's Guide QwtPlot(3)

NAME

QwtPlot -
A 2-D plotting widget.
 

SYNOPSIS

#include <qwt_plot.h>
Inherits QwtPlotDict.

Public Types


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

Public Slots


virtual void replot ()
 
void autoRefresh ()
 

Signals


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

Public Member Functions


QwtPlot (QWidget *=NULL)
 
QwtPlot (const QwtText &title, QWidget *p=NULL)
 
virtual ~QwtPlot ()
 
void applyProperties (const QString &)
 
QString grabProperties () const
 
void setAutoReplot (bool tf=true)
 
bool autoReplot () const
 
QwtPlotLayout * plotLayout ()
 
const QwtPlotLayout * plotLayout () const
 
void setTitle (const QString &)
 
void setTitle (const QwtText &t)
 
QwtText title () const
 
QwtTextLabel * titleLabel ()
 
const QwtTextLabel * titleLabel () const
 
QwtPlotCanvas * canvas ()
 
const QwtPlotCanvas * canvas () const
 
void setCanvasBackground (const QBrush &)
 
QBrush canvasBackground () const
 
void setCanvasLineWidth (int w)
 
int canvasLineWidth () const
 
virtual QwtScaleMap canvasMap (int axisId) const
 
double invTransform (int axisId, int pos) const
 
double transform (int axisId, double value) const
 
QwtScaleEngine * axisScaleEngine (int axisId)
 
const QwtScaleEngine * axisScaleEngine (int axisId) const
 
void setAxisScaleEngine (int axisId, QwtScaleEngine *)
 
void setAxisAutoScale (int axisId, bool on=true)
 
bool axisAutoScale (int axisId) const
 
void enableAxis (int axisId, bool tf=true)
 
bool axisEnabled (int axisId) const
 
void setAxisFont (int axisId, const QFont &f)
 
QFont axisFont (int axisId) const
 
void setAxisScale (int axisId, double min, double max, double step=0)
 
void setAxisScaleDiv (int axisId, const QwtScaleDiv &)
 
void setAxisScaleDraw (int axisId, QwtScaleDraw *)
 
double axisStepSize (int axisId) const
 
QwtInterval axisInterval (int axisId) const
 
const QwtScaleDiv * axisScaleDiv (int axisId) const
 
QwtScaleDiv * axisScaleDiv (int axisId)
 
const QwtScaleDraw * axisScaleDraw (int axisId) const
 
QwtScaleDraw * axisScaleDraw (int axisId)
 
const QwtScaleWidget * axisWidget (int axisId) const
 
QwtScaleWidget * axisWidget (int axisId)
 
void setAxisLabelAlignment (int axisId, Qt::Alignment)
 
void setAxisLabelRotation (int axisId, double rotation)
 
void setAxisTitle (int axisId, const QString &)
 
void setAxisTitle (int axisId, const QwtText &)
 
QwtText axisTitle (int axisId) const
 
void setAxisMaxMinor (int axisId, int maxMinor)
 
int axisMaxMinor (int axisId) const
 
void setAxisMaxMajor (int axisId, int maxMajor)
 
int axisMaxMajor (int axisId) const
 
void insertLegend (QwtLegend *, LegendPosition=QwtPlot::RightLegend, double ratio=-1.0)
 
QwtLegend * legend ()
 
const QwtLegend * legend () const
 
virtual QSize sizeHint () const
 
virtual QSize minimumSizeHint () const
 
virtual void updateLayout ()
 
virtual void drawCanvas (QPainter *)
 
void updateAxes ()
 
virtual bool event (QEvent *)
 
virtual void drawItems (QPainter *, const QRectF &, const QwtScaleMap maps[axisCnt]) const
 

Protected Slots


virtual void legendItemClicked ()
 
virtual void legendItemChecked (bool)
 

Protected Member Functions


virtual void updateTabOrder ()
 
virtual void resizeEvent (QResizeEvent *e)
 

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

enum QwtPlot::Axis

Axis index.
Enumerator:
yLeft
Y axis left of the canvas.
yRight
Y axis right of the canvas.
xBottom
X axis below the canvas.
xTop
X axis above the canvas.
axisCnt
Number of axes.

enum QwtPlot::LegendPosition Position of the legend, relative to the canvas.

See also:
insertLegend()
Note:
In case of ExternalLegend, the legend is not handled by QwtPlotRenderer
 
Enumerator:
LeftLegend
The legend will be left from the QwtPlot::yLeft axis.
RightLegend
The legend will be right from the QwtPlot::yRight axis.
BottomLegend
The legend will be below QwtPlot::xBottom axis.
TopLegend
The legend will be between QwtPlot::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 type can be used to have a legend in an external window ( or on the canvas ).

Constructor & Destructor Documentation

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

Constructor. Parameters:
parent Parent widget
 

QwtPlot::QwtPlot (const QwtText &title, QWidget *parent = NULL) [explicit]

Constructor. Parameters:
title Title text
 
parent Parent widget
 

QwtPlot::~QwtPlot () [virtual]

Destructor.

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.
 

void QwtPlot::autoRefresh () [slot]

Replots the plot if autoReplot() is true.

bool QwtPlot::autoReplot () const Returns:

true if the autoReplot option is set.
See also:
setAutoReplot()
 

bool QwtPlot::axisAutoScale (intaxisId) const Returns:

true if autoscaling is enabled
Parameters:
axisId axis index
 

bool QwtPlot::axisEnabled (intaxisId) const Returns:

true if a specified axis is enabled
Parameters:
axisId axis index
 

QFont QwtPlot::axisFont (intaxisId) const Returns:

the font of the scale labels for a specified axis
Parameters:
axisId axis index
 

QwtInterval QwtPlot::axisInterval (intaxisId) const

Return the current interval of the specified axis. This is only a convenience function for axisScaleDiv( axisId )->interval();
Parameters:
axisId axis index
Returns:
Scale interval
See also:
QwtScaleDiv, axisScaleDiv()
 

int QwtPlot::axisMaxMajor (intaxisId) const Returns:

the maximum number of major ticks for a specified axis
Parameters:
axisId axis index
See also:
setAxisMaxMajor()
 

int QwtPlot::axisMaxMinor (intaxisId) const Returns:

the maximum number of minor ticks for a specified axis
Parameters:
axisId axis index
See also:
setAxisMaxMinor()
 

const QwtScaleDiv * QwtPlot::axisScaleDiv (intaxisId) const

Return the scale division of a specified axis. axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound() are the current limits of the axis scale.
Parameters:
axisId axis index
Returns:
Scale division
See also:
QwtScaleDiv, setAxisScaleDiv()
 

QwtScaleDiv * QwtPlot::axisScaleDiv (intaxisId)

Return the scale division of a specified axis. axisScaleDiv(axisId)->lowerBound(), axisScaleDiv(axisId)->upperBound() are the current limits of the axis scale.
Parameters:
axisId axis index
Returns:
Scale division
See also:
QwtScaleDiv, setAxisScaleDiv()
 

const QwtScaleDraw * QwtPlot::axisScaleDraw (intaxisId) const Returns:

the scale draw of a specified axis
Parameters:
axisId axis index
Returns:
specified scaleDraw for axis, or NULL if axis is invalid.
See also:
QwtScaleDraw
 

QwtScaleDraw * QwtPlot::axisScaleDraw (intaxisId) Returns:

the scale draw of a specified axis
Parameters:
axisId axis index
Returns:
specified scaleDraw for axis, or NULL if axis is invalid.
See also:
QwtScaleDraw
 

QwtScaleEngine * QwtPlot::axisScaleEngine (intaxisId) Parameters:

axisId axis index
Returns:
Scale engine for a specific axis
 

const QwtScaleEngine * QwtPlot::axisScaleEngine (intaxisId) const Parameters:

axisId axis index
Returns:
Scale engine for a specific axis
 

double QwtPlot::axisStepSize (intaxisId) 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:
axisId axis index
Returns:
step size parameter value
See also:
setAxisScale()
 

QwtText QwtPlot::axisTitle (intaxisId) const Returns:

the title of a specified axis
Parameters:
axisId axis index
 

bool QwtPlot::axisValid (intaxisId) [static, protected] Returns:

true if the specified axis exists, otherwise false
Parameters:
axisId axis index
 

const QwtScaleWidget * QwtPlot::axisWidget (intaxisId) const Returns:

specified axis, or NULL if axisId is invalid.
Parameters:
axisId axis index
 

QwtScaleWidget * QwtPlot::axisWidget (intaxisId) Returns:

specified axis, or NULL if axisId is invalid.
Parameters:
axisId axis index
 

const QwtPlotCanvas * QwtPlot::canvas () const Returns:

the plot's canvas
 

QwtPlotCanvas * QwtPlot::canvas () Returns:

the plot's canvas
 

QBrush QwtPlot::canvasBackground () const Nothing else than: canvas()->palette().brush( QPalette::Normal, QPalette::Window);

Returns:
Background brush of the plotting area.
See also:
setCanvasBackground()
 

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

Returns:
the border width of the plotting area
 

QwtScaleMap QwtPlot::canvasMap (intaxisId) const [virtual] Parameters:

axisId Axis
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::drawCanvas (QPainter *painter) [virtual] Redraw the canvas.

Parameters:
painter Painter 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 QRectF &canvasRect, const QwtScaleMapmap[axisCnt]) const [virtual] Redraw the canvas items.

Parameters:
painter Painter used for drawing
 
canvasRect Bounding rectangle where to paint
 
map QwtPlot::axisCnt maps, mapping between plot and paint device coordinates
 

void QwtPlot::enableAxis (intaxisId, booltf = 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:
axisId axis index
 
tf true (enabled) or false (disabled)
 

bool QwtPlot::event (QEvent *event) [virtual]

Adds handling of layout requests. Parameters:
event Event
 

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::LegendPositionpos = QwtPlot::RightLegend, doubleratio = -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:
legend Legend
 
pos The legend's position. For top/left position the number of colums will be limited to 1, otherwise it will be set to unlimited.
 
ratio Ratio 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 (intaxisId, intpos) const Transform the x or y coordinate of a position in the drawing region into a value.

Parameters:
axisId axis index
 
pos position
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, boolon) [signal] A signal which is emitted when the user has clicked on a legend item, which is in QwtLegend::CheckableItem mode

Parameters:
plotItem Corresponding plot item of the selected legend item
 
on True 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:
plotItem Corresponding plot item of the selected legend item
Note:
clicks are disabled as default
See also:
QwtLegend::setItemMode(), QwtLegend::itemMode()
 

void QwtPlot::legendItemChecked (boolon) [protected, virtual, slot] Called internally when the legend has been checked Emits a legendClicked() signal.

void QwtPlot::legendItemClicked () [protected, virtual, slot] Called internally when the legend has been clicked on. Emits a legendClicked() signal.

QSize QwtPlot::minimumSizeHint () const [virtual]

Return a minimum size hint.

const QwtPlotLayout * QwtPlot::plotLayout () const Returns:

the plot's titel label.
 

QwtPlotLayout * QwtPlot::plotLayout () Returns:

the plot's title
 

void QwtPlot::replot () [virtual, slot]

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) [protected, virtual] Resize and update internal layout

Parameters:
e Resize event
 

void QwtPlot::setAutoReplot (booltf = 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:
tf true or false. Defaults to true.
See also:
replot()
 

void QwtPlot::setAxisAutoScale (intaxisId, boolon = true)

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:
axisId axis index
 
on On/Off
See also:
setAxisScale(), setAxisScaleDiv(), updateAxes()
Note:
The autoscaling flag has no effect until updateAxes() is executed ( called by replot() ).
 

void QwtPlot::setAxisFont (intaxisId, const QFont &f)

Change the font of an axis. Parameters:
axisId axis index
 
f font
Warning:
This function changes the font of the tick labels, not of the axis title.
 

void QwtPlot::setAxisLabelAlignment (intaxisId, Qt::Alignmentalignment) Change the alignment of the tick labels

Parameters:
axisId axis index
 
alignment Or'd Qt::AlignmentFlags <see qnamespace.h>
See also:
QwtScaleDraw::setLabelAlignment()
 

void QwtPlot::setAxisLabelRotation (intaxisId, doublerotation) Rotate all tick labels

Parameters:
axisId axis index
 
rotation Angle in degrees. When changing the label rotation, the label alignment might be adjusted too.
See also:
QwtScaleDraw::setLabelRotation(), setAxisLabelAlignment()
 

void QwtPlot::setAxisMaxMajor (intaxisId, intmaxMajor) Set the maximum number of major scale intervals for a specified axis

Parameters:
axisId axis index
 
maxMajor maximum number of major steps
See also:
axisMaxMajor()
 

void QwtPlot::setAxisMaxMinor (intaxisId, intmaxMinor) Set the maximum number of minor scale intervals for a specified axis

Parameters:
axisId axis index
 
maxMinor maximum number of minor steps
See also:
axisMaxMinor()
 

void QwtPlot::setAxisScale (intaxisId, doublemin, doublemax, doublestepSize = 0)

Disable autoscaling and specify a fixed scale for a selected axis. Parameters:
axisId axis index
 
min
 
max minimum and maximum of the scale
 
stepSize Major step size. If step == 0, the step size is calculated automatically using the maxMajor setting.
See also:
setAxisMaxMajor(), setAxisAutoScale(), axisStepSize()
 

void QwtPlot::setAxisScaleDiv (intaxisId, const QwtScaleDiv &scaleDiv)

Disable autoscaling and specify a fixed scale for a selected axis. Parameters:
axisId axis index
 
scaleDiv Scale division
See also:
setAxisScale(), setAxisAutoScale()
 

void QwtPlot::setAxisScaleDraw (intaxisId, QwtScaleDraw *scaleDraw)

Set a scale draw. Parameters:
axisId axis index
 
scaleDraw object 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 (intaxisId, QwtScaleEngine *scaleEngine) Change the scale engine for an axis

Parameters:
axisId axis index
 
scaleEngine Scale engine
See also:
axisScaleEngine()
 

void QwtPlot::setAxisTitle (intaxisId, const QwtText &title)

Change the title of a specified axis. Parameters:
axisId axis index
 
title axis title
 

void QwtPlot::setAxisTitle (intaxisId, const QString &title)

Change the title of a specified axis. Parameters:
axisId axis index
 
title axis title
 

void QwtPlot::setCanvasBackground (const QBrush &brush)

Change the background of the plotting area. Sets brush to QPalette::Window of all colorgroups of the palette of the canvas. Using canvas()->setPalette() is a more powerful way to set these colors.
Parameters:
brush New background brush
See also:
canvasBackground()
 

void QwtPlot::setCanvasLineWidth (intwidth)

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

void QwtPlot::setTitle (const QString &title) Change the plot's title

Parameters:
title New title
 

void QwtPlot::setTitle (const QwtText &title) Change the plot's title

Parameters:
title New 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.
 

double QwtPlot::transform (intaxisId, doublevalue) const

Transform a value into a coordinate in the plotting region. Parameters:
axisId axis index
 
value value
Returns:
X or y coordinate in the plotting region corresponding to the value.
 

void QwtPlot::updateAxes ()

Rebuild the scales.

void QwtPlot::updateLayout () [virtual]

Adjust plot content to its current size. See also:
resizeEvent()
 

void QwtPlot::updateTabOrder () [protected, virtual] 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.
 

Author

Generated automatically by Doxygen for Qwt User's Guide from the source code.
Fri Apr 15 2011 Version 6.0.0