1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
3
* Copyright (C) 1997 Josef Wilgen
4
* Copyright (C) 2002 Uwe Rathmann
6
* This library is free software; you can redistribute it and/or
7
* modify it under the terms of the Qwt License, Version 1.0
8
*****************************************************************************/
14
#include "qwt_global.h"
15
#include "qwt_array.h"
17
#include "qwt_plot_dict.h"
18
#include "qwt_scale_map.h"
19
#include "qwt_plot_printfilter.h"
29
class QwtPlotPrintFilter;
32
\brief A 2-D plotting widget
34
QwtPlot is a widget for plotting two-dimensional graphs.
35
An unlimited number of plot items can be displayed on
36
its canvas. Plot items might be curves (QwtPlotCurve), markers
37
(QwtPlotMarker), the grid (QwtPlotGrid), or anything else derived
39
A plot can have up to four axes, with each plot item attached to an x- and
40
a y axis. The scales at the axes can be explicitely set (QwtScaleDiv), or
41
are calculated from the plot items, using algorithms (QwtScaleEngine) which
42
can be configured separately for each axis.
47
The following example shows (schematically) the most simple
48
way to use QwtPlot. By default, only the left and bottom axes are
49
visible and their scales are computed automatically.
52
#include <qwt_plot_curve.h>
55
double x[100], y1[100], y2[100]; // x and y values
57
myPlot = new QwtPlot("Two Curves", parent);
60
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
61
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
63
getSomeValues(x, y1, y2);
65
// copy the data into the curves
66
curve1->setData(x, y1, 100);
67
curve2->setData(x, y2, 100);
69
curve1->attach(myPlot);
70
curve2->attach(myPlot);
72
// finally, refresh the plot
77
class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
79
friend class QwtPlotCanvas;
82
Q_PROPERTY( QString propertiesDocument
83
READ grabProperties WRITE applyProperties )
98
\brief Position of the legend, relative to the canvas.
100
ExternalLegend means that only the content of the legend
101
will be handled by QwtPlot, but not its geometry.
102
This might be interesting if an application wants to
103
have a legend in an external window.
115
explicit QwtPlot(QWidget * = NULL);
116
explicit QwtPlot(const QwtText &title, QWidget *p = NULL);
117
#if QT_VERSION < 0x040000
118
explicit QwtPlot(QWidget *, const char* name);
123
void applyProperties(const QString &);
124
QString grabProperties() const;
126
void setAutoReplot(bool tf = true);
127
bool autoReplot() const;
129
void print(QPaintDevice &p,
130
const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
131
virtual void print(QPainter *, const QRect &rect,
132
const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
136
QwtPlotLayout *plotLayout();
137
const QwtPlotLayout *plotLayout() const;
139
void setMargin(int margin);
144
void setTitle(const QString &);
145
void setTitle(const QwtText &t);
146
QwtText title() const;
148
QwtTextLabel *titleLabel();
149
const QwtTextLabel *titleLabel() const;
153
QwtPlotCanvas *canvas();
154
const QwtPlotCanvas *canvas() const;
156
void setCanvasBackground (const QColor &c);
157
const QColor& canvasBackground() const;
159
void setCanvasLineWidth(int w);
160
int canvasLineWidth() const;
162
virtual QwtScaleMap canvasMap(int axisId) const;
164
double invTransform(int axisId, int pos) const;
165
int transform(int axisId, double value) const;
169
QwtScaleEngine *axisScaleEngine(int axisId);
170
const QwtScaleEngine *axisScaleEngine(int axisId) const;
171
void setAxisScaleEngine(int axisId, QwtScaleEngine *);
173
void setAxisAutoScale(int axisId);
174
bool axisAutoScale(int axisId) const;
176
void enableAxis(int axisId, bool tf = true);
177
bool axisEnabled(int axisId) const;
179
void setAxisFont(int axisId, const QFont &f);
180
QFont axisFont(int axisId) const;
182
void setAxisScale(int axisId, double min, double max, double step = 0);
183
void setAxisScaleDiv(int axisId, const QwtScaleDiv &);
184
void setAxisScaleDraw(int axisId, QwtScaleDraw *);
186
const QwtScaleDiv *axisScaleDiv(int axisId) const;
187
QwtScaleDiv *axisScaleDiv(int axisId);
189
const QwtScaleDraw *axisScaleDraw(int axisId) const;
190
QwtScaleDraw *axisScaleDraw(int axisId);
192
const QwtScaleWidget *axisWidget(int axisId) const;
193
QwtScaleWidget *axisWidget(int axisId);
195
#if QT_VERSION < 0x040000
196
void setAxisLabelAlignment(int axisId, int);
198
void setAxisLabelAlignment(int axisId, Qt::Alignment);
200
void setAxisLabelRotation(int axisId, double rotation);
202
void setAxisTitle(int axisId, const QString &);
203
void setAxisTitle(int axisId, const QwtText &);
204
QwtText axisTitle(int axisId) const;
206
void setAxisMaxMinor(int axisId, int maxMinor);
207
int axisMaxMajor(int axisId) const;
208
void setAxisMaxMajor(int axisId, int maxMajor);
209
int axisMaxMinor(int axisId) const;
213
void insertLegend(QwtLegend *, LegendPosition = QwtPlot::RightLegend,
214
double ratio = -1.0);
217
const QwtLegend *legend() const;
221
virtual void polish();
222
virtual QSize sizeHint() const;
223
virtual QSize minimumSizeHint() const;
225
virtual void updateLayout();
227
virtual bool event(QEvent *);
231
A signal which is emitted when the user has clicked on
232
a legend item, which is in QwtLegend::ClickableItem mode.
234
\param plotItem Corresponding plot item of the
237
\note clicks are disabled as default
238
\sa QwtLegend::setItemMode, QwtLegend::itemMode
240
void legendClicked(QwtPlotItem *plotItem);
243
A signal which is emitted when the user has clicked on
244
a legend item, which is in QwtLegend::CheckableItem mode
246
\param plotItem Corresponding plot item of the
248
\param on True when the legen item is checked
250
\note clicks are disabled as default
251
\sa QwtLegend::setItemMode, QwtLegend::itemMode
254
void legendChecked(QwtPlotItem *plotItem, bool on);
259
virtual void replot();
263
virtual void legendItemClicked();
264
virtual void legendItemChecked(bool);
267
static bool axisValid(int axisId);
269
virtual void drawCanvas(QPainter *);
270
virtual void drawItems(QPainter *, const QRect &,
271
const QwtScaleMap maps[axisCnt],
272
const QwtPlotPrintFilter &) const;
274
virtual void updateTabOrder();
278
virtual void resizeEvent(QResizeEvent *e);
280
virtual void printLegendItem(QPainter *,
281
const QWidget *, const QRect &) const;
283
virtual void printTitle(QPainter *, const QRect &) const;
284
virtual void printScale(QPainter *, int axisId, int startDist, int endDist,
285
int baseDist, const QRect &) const;
286
virtual void printCanvas(QPainter *, const QRect &,
287
const QwtScaleMap maps[axisCnt], const QwtPlotPrintFilter &) const;
288
virtual void printLegend(QPainter *, const QRect &) const;
292
void deleteAxesData();
293
void updateScaleDiv();
295
void initPlot(const QwtText &title);
298
AxisData *d_axisData[axisCnt];