~l3on/ubuntu/oneiric/qwt/fix-921430

« back to all changes in this revision

Viewing changes to qwt-5.0.2/src/qwt_plot.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2007-10-05 15:20:41 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20071005152041-qmybqh4fj9jejyo2
Tags: 5.0.2-2
* Handle nostrip build option. (Closes: #437877)
* Build libqwt5-doc package in binary-indep target. (Closes: #443110)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
 
2
 * Qwt Widget Library
 
3
 * Copyright (C) 1997   Josef Wilgen
 
4
 * Copyright (C) 2002   Uwe Rathmann
 
5
 *
 
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
 *****************************************************************************/
 
9
 
 
10
#ifndef QWT_PLOT_H
 
11
#define QWT_PLOT_H
 
12
 
 
13
#include <qframe.h>
 
14
#include "qwt_global.h"
 
15
#include "qwt_array.h"
 
16
#include "qwt_text.h"
 
17
#include "qwt_plot_dict.h"
 
18
#include "qwt_scale_map.h"
 
19
#include "qwt_plot_printfilter.h"
 
20
 
 
21
class QwtPlotLayout;
 
22
class QwtLegend;
 
23
class QwtScaleWidget;
 
24
class QwtScaleEngine;
 
25
class QwtScaleDiv;
 
26
class QwtScaleDraw;
 
27
class QwtTextLabel;
 
28
class QwtPlotCanvas;
 
29
class QwtPlotPrintFilter;
 
30
 
 
31
/*!
 
32
  \brief A 2-D plotting widget
 
33
 
 
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 
 
38
  from QwtPlotItem.
 
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. 
 
43
 
 
44
  \image html plot.png
 
45
 
 
46
  \par Example
 
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.
 
50
  \verbatim
 
51
#include <qwt_plot.h>
 
52
#include <qwt_plot_curve.h>
 
53
 
 
54
QwtPlot *myPlot;
 
55
double x[100], y1[100], y2[100];        // x and y values
 
56
 
 
57
myPlot = new QwtPlot("Two Curves", parent);
 
58
 
 
59
// add curves
 
60
QwtPlotCurve *curve1 = new QwtPlotCurve("Curve 1");
 
61
QwtPlotCurve *curve2 = new QwtPlotCurve("Curve 2");
 
62
 
 
63
getSomeValues(x, y1, y2);
 
64
 
 
65
// copy the data into the curves
 
66
curve1->setData(x, y1, 100);
 
67
curve2->setData(x, y2, 100);
 
68
 
 
69
curve1->attach(myPlot);
 
70
curve2->attach(myPlot);
 
71
 
 
72
// finally, refresh the plot
 
73
myPlot->replot();
 
74
\endverbatim
 
75
*/
 
76
 
 
77
class QWT_EXPORT QwtPlot: public QFrame, public QwtPlotDict
 
78
{
 
79
    friend class QwtPlotCanvas;
 
80
 
 
81
    Q_OBJECT
 
82
    Q_PROPERTY( QString propertiesDocument 
 
83
        READ grabProperties WRITE applyProperties )
 
84
 
 
85
public:
 
86
    //! Axis index
 
87
    enum Axis 
 
88
    { 
 
89
        yLeft, 
 
90
        yRight, 
 
91
        xBottom, 
 
92
        xTop, 
 
93
 
 
94
        axisCnt 
 
95
    };
 
96
 
 
97
    /*! 
 
98
        \brief Position of the legend, relative to the canvas.
 
99
 
 
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.
 
104
     */
 
105
    enum LegendPosition 
 
106
    {
 
107
        LeftLegend,
 
108
        RightLegend,
 
109
        BottomLegend,
 
110
        TopLegend,
 
111
        
 
112
        ExternalLegend
 
113
    };
 
114
 
 
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);
 
119
#endif
 
120
 
 
121
    virtual ~QwtPlot();
 
122
 
 
123
    void applyProperties(const QString &);
 
124
    QString grabProperties() const;
 
125
 
 
126
    void setAutoReplot(bool tf = true);
 
127
    bool autoReplot() const;
 
128
 
 
129
    void print(QPaintDevice &p,
 
130
        const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
 
131
    virtual void print(QPainter *, const QRect &rect,
 
132
        const QwtPlotPrintFilter & = QwtPlotPrintFilter()) const;
 
133
 
 
134
    // Layout
 
135
 
 
136
    QwtPlotLayout *plotLayout();
 
137
    const QwtPlotLayout *plotLayout() const;
 
138
 
 
139
    void setMargin(int margin);
 
140
    int margin() const;
 
141
 
 
142
    // Title
 
143
 
 
144
    void setTitle(const QString &);
 
145
    void setTitle(const QwtText &t);
 
146
    QwtText title() const;
 
147
 
 
148
    QwtTextLabel *titleLabel();
 
149
    const QwtTextLabel *titleLabel() const;
 
150
 
 
151
    // Canvas
 
152
 
 
153
    QwtPlotCanvas *canvas();
 
154
    const QwtPlotCanvas *canvas() const;
 
155
 
 
156
    void setCanvasBackground (const QColor &c);
 
157
    const QColor& canvasBackground() const;
 
158
 
 
159
    void setCanvasLineWidth(int w);
 
160
    int canvasLineWidth() const;
 
161
 
 
162
    virtual QwtScaleMap canvasMap(int axisId) const;
 
163
 
 
164
    double invTransform(int axisId, int pos) const;
 
165
    int transform(int axisId, double value) const;
 
166
 
 
167
    // Axes
 
168
 
 
169
    QwtScaleEngine *axisScaleEngine(int axisId);
 
170
    const QwtScaleEngine *axisScaleEngine(int axisId) const;
 
171
    void setAxisScaleEngine(int axisId, QwtScaleEngine *);
 
172
 
 
173
    void setAxisAutoScale(int axisId);
 
174
    bool axisAutoScale(int axisId) const;
 
175
 
 
176
    void enableAxis(int axisId, bool tf = true);
 
177
    bool axisEnabled(int axisId) const;
 
178
 
 
179
    void setAxisFont(int axisId, const QFont &f);
 
180
    QFont axisFont(int axisId) const;
 
181
 
 
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 *);
 
185
 
 
186
    const QwtScaleDiv *axisScaleDiv(int axisId) const;
 
187
    QwtScaleDiv *axisScaleDiv(int axisId);
 
188
 
 
189
    const QwtScaleDraw *axisScaleDraw(int axisId) const;
 
190
    QwtScaleDraw *axisScaleDraw(int axisId);
 
191
 
 
192
    const QwtScaleWidget *axisWidget(int axisId) const;
 
193
    QwtScaleWidget *axisWidget(int axisId);
 
194
 
 
195
#if QT_VERSION < 0x040000
 
196
    void setAxisLabelAlignment(int axisId, int);
 
197
#else
 
198
    void setAxisLabelAlignment(int axisId, Qt::Alignment);
 
199
#endif
 
200
    void setAxisLabelRotation(int axisId, double rotation);
 
201
 
 
202
    void setAxisTitle(int axisId, const QString &);
 
203
    void setAxisTitle(int axisId, const QwtText &);
 
204
    QwtText axisTitle(int axisId) const;
 
205
 
 
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;
 
210
 
 
211
    // Legend 
 
212
 
 
213
    void insertLegend(QwtLegend *, LegendPosition = QwtPlot::RightLegend,
 
214
        double ratio = -1.0);
 
215
 
 
216
    QwtLegend *legend();
 
217
    const QwtLegend *legend() const;
 
218
 
 
219
    // Misc
 
220
 
 
221
    virtual void polish();
 
222
    virtual QSize sizeHint() const;
 
223
    virtual QSize minimumSizeHint() const;
 
224
 
 
225
    virtual void updateLayout();
 
226
 
 
227
    virtual bool event(QEvent *);
 
228
 
 
229
signals:
 
230
    /*!
 
231
      A signal which is emitted when the user has clicked on 
 
232
      a legend item, which is in QwtLegend::ClickableItem mode. 
 
233
 
 
234
      \param plotItem Corresponding plot item of the
 
235
                 selected legend item
 
236
 
 
237
      \note clicks are disabled as default
 
238
      \sa QwtLegend::setItemMode, QwtLegend::itemMode
 
239
     */
 
240
    void legendClicked(QwtPlotItem *plotItem);
 
241
 
 
242
    /*!
 
243
      A signal which is emitted when the user has clicked on 
 
244
      a legend item, which is in QwtLegend::CheckableItem mode
 
245
 
 
246
      \param plotItem Corresponding plot item of the
 
247
                 selected legend item
 
248
      \param on True when the legen item is checked
 
249
 
 
250
      \note clicks are disabled as default
 
251
      \sa QwtLegend::setItemMode, QwtLegend::itemMode
 
252
     */
 
253
 
 
254
    void legendChecked(QwtPlotItem *plotItem, bool on);
 
255
 
 
256
public slots:
 
257
    void clear();
 
258
 
 
259
    virtual void replot();
 
260
    void autoRefresh();
 
261
 
 
262
protected slots:
 
263
    virtual void legendItemClicked();
 
264
    virtual void legendItemChecked(bool);
 
265
 
 
266
protected:
 
267
    static bool axisValid(int axisId);
 
268
 
 
269
    virtual void drawCanvas(QPainter *);
 
270
    virtual void drawItems(QPainter *, const QRect &,
 
271
        const QwtScaleMap maps[axisCnt],
 
272
        const QwtPlotPrintFilter &) const;
 
273
 
 
274
    virtual void updateTabOrder();
 
275
 
 
276
    void updateAxes();
 
277
 
 
278
    virtual void resizeEvent(QResizeEvent *e);
 
279
 
 
280
    virtual void printLegendItem(QPainter *, 
 
281
        const QWidget *, const QRect &) const;
 
282
 
 
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;
 
289
 
 
290
private:
 
291
    void initAxesData();
 
292
    void deleteAxesData();
 
293
    void updateScaleDiv();
 
294
 
 
295
    void initPlot(const QwtText &title);
 
296
 
 
297
    class AxisData;
 
298
    AxisData *d_axisData[axisCnt];
 
299
 
 
300
    class PrivateData;
 
301
    PrivateData *d_data;
 
302
};
 
303
 
 
304
#endif