~ubuntu-branches/ubuntu/oneiric/qwt/oneiric-proposed

« back to all changes in this revision

Viewing changes to qwt-5.1.1/src/qwt_plot_curve.h

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2008-05-26 10:26:31 UTC
  • mfrom: (1.1.3 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080526102631-bp95mfccnrb957nx
Tags: 5.1.1-1
New upstream release.

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_CURVE_H
 
11
#define QWT_PLOT_CURVE_H
 
12
 
 
13
#include <qpen.h>
 
14
#include <qstring.h>
 
15
#include "qwt_global.h"
 
16
#include "qwt_plot_item.h"
 
17
#include "qwt_text.h"
 
18
#include "qwt_polygon.h"
 
19
#include "qwt_data.h"
 
20
 
 
21
class QPainter;
 
22
class QwtScaleMap;
 
23
class QwtSymbol;
 
24
class QwtCurveFitter;
 
25
 
 
26
/*!
 
27
  \brief A class which draws curves
 
28
 
 
29
  This class can be used to display data as a curve in the  x-y plane.
 
30
  It supports different display styles, spline interpolation and symbols.
 
31
 
 
32
  \par Usage
 
33
  <dl><dt>A. Assign curve properties</dt>
 
34
  <dd>When a curve is created, it is configured to draw black solid lines
 
35
  with QwtPlotCurve::Lines and no symbols. You can change this by calling 
 
36
  setPen(), setStyle() and setSymbol().</dd>
 
37
  <dt>B. Assign or change data.</dt>
 
38
  <dd>Data can be set in two ways:<ul>
 
39
  <li>setData() is overloaded to initialize the x and y data by
 
40
  copying from different data structures with different kind of copy semantics.
 
41
  <li>setRawData() only stores the pointers and size information
 
42
  and is provided for backwards compatibility.  This function is less safe (you
 
43
  must not delete the data while they are attached), but has been more
 
44
  efficient, and has been more convenient for dynamically changing data.
 
45
  Use of setData() in combination with a problem-specific subclass
 
46
  of QwtData is always preferrable.</ul></dd>
 
47
  <dt>C. Draw</dt>
 
48
  <dd>draw() maps the data into pixel coordinates and paints them.
 
49
  </dd></dl>
 
50
 
 
51
  \par Example:
 
52
  see examples/curvdemo
 
53
 
 
54
  \sa QwtData, QwtSymbol, QwtScaleMap
 
55
*/
 
56
class QWT_EXPORT QwtPlotCurve: public QwtPlotItem
 
57
{
 
58
public:
 
59
    enum CurveType
 
60
    {
 
61
        Yfx,
 
62
        Xfy
 
63
    };
 
64
 
 
65
    /*! 
 
66
        Curve styles. 
 
67
        \sa setStyle
 
68
    */
 
69
    enum CurveStyle
 
70
    {
 
71
        NoCurve,
 
72
 
 
73
        Lines,
 
74
        Sticks,
 
75
        Steps,
 
76
        Dots,
 
77
 
 
78
        UserCurve = 100
 
79
    };
 
80
 
 
81
    /*! 
 
82
        Curve attributes. 
 
83
        \sa setCurveAttribute, testCurveAttribute
 
84
    */
 
85
    enum CurveAttribute
 
86
    {
 
87
        Inverted = 1,
 
88
        Fitted = 2
 
89
    };
 
90
 
 
91
    /*! 
 
92
        Paint attributes 
 
93
        \sa setPaintAttribute, testPaintAttribute
 
94
    */
 
95
    enum PaintAttribute
 
96
    {
 
97
        PaintFiltered = 1,
 
98
        ClipPolygons = 2
 
99
    };
 
100
 
 
101
    explicit QwtPlotCurve();
 
102
    explicit QwtPlotCurve(const QwtText &title);
 
103
    explicit QwtPlotCurve(const QString &title);
 
104
 
 
105
    virtual ~QwtPlotCurve();
 
106
 
 
107
    virtual int rtti() const;
 
108
 
 
109
    void setCurveType(CurveType);
 
110
    CurveType curveType() const;
 
111
 
 
112
    void setPaintAttribute(PaintAttribute, bool on = true);
 
113
    bool testPaintAttribute(PaintAttribute) const;
 
114
 
 
115
    void setRawData(const double *x, const double *y, int size);
 
116
    void setData(const double *xData, const double *yData, int size);
 
117
    void setData(const QwtArray<double> &xData, const QwtArray<double> &yData);
 
118
#if QT_VERSION < 0x040000
 
119
    void setData(const QwtArray<QwtDoublePoint> &data);
 
120
#else
 
121
    void setData(const QPolygonF &data);
 
122
#endif
 
123
    void setData(const QwtData &data);
 
124
    
 
125
    int closestPoint(const QPoint &pos, double *dist = NULL) const;
 
126
 
 
127
    QwtData &data();
 
128
    const QwtData &data() const;
 
129
 
 
130
    int dataSize() const;
 
131
    inline double x(int i) const;
 
132
    inline double y(int i) const;
 
133
 
 
134
    virtual QwtDoubleRect boundingRect() const;
 
135
 
 
136
    //! boundingRect().left()
 
137
    inline double minXValue() const { return boundingRect().left(); }
 
138
    //! boundingRect().right()
 
139
    inline double maxXValue() const { return boundingRect().right(); }
 
140
    //! boundingRect().top()
 
141
    inline double minYValue() const { return boundingRect().top(); }
 
142
    //! boundingRect().bottom()
 
143
    inline double maxYValue() const { return boundingRect().bottom(); }
 
144
 
 
145
    void setCurveAttribute(CurveAttribute, bool on = true);
 
146
    bool testCurveAttribute(CurveAttribute) const;
 
147
 
 
148
    void setPen(const QPen &);
 
149
    const QPen &pen() const;
 
150
 
 
151
    void setBrush(const QBrush &);
 
152
    const QBrush &brush() const;
 
153
 
 
154
    void setBaseline(double ref);
 
155
    double baseline() const;
 
156
 
 
157
    void setStyle(CurveStyle style);
 
158
    CurveStyle style() const;
 
159
 
 
160
    void setSymbol(const QwtSymbol &s);
 
161
    const QwtSymbol& symbol() const;
 
162
 
 
163
    void setCurveFitter(QwtCurveFitter *);
 
164
    QwtCurveFitter *curveFitter() const;
 
165
 
 
166
    virtual void draw(QPainter *p, 
 
167
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
168
        const QRect &) const;
 
169
 
 
170
    virtual void draw(QPainter *p, 
 
171
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
172
        int from, int to) const;
 
173
 
 
174
    void draw(int from, int to) const;
 
175
 
 
176
    virtual void updateLegend(QwtLegend *) const;
 
177
 
 
178
protected:
 
179
 
 
180
    void init();
 
181
 
 
182
    virtual void drawCurve(QPainter *p, int style,
 
183
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
184
        int from, int to) const;
 
185
 
 
186
    virtual void drawSymbols(QPainter *p, const QwtSymbol &,
 
187
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
188
        int from, int to) const;
 
189
 
 
190
    void drawLines(QPainter *p,
 
191
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
192
        int from, int to) const;
 
193
    void drawSticks(QPainter *p,
 
194
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
195
        int from, int to) const;
 
196
    void drawDots(QPainter *p,
 
197
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
198
        int from, int to) const;
 
199
    void drawSteps(QPainter *p,
 
200
        const QwtScaleMap &xMap, const QwtScaleMap &yMap,
 
201
        int from, int to) const;
 
202
 
 
203
    void fillCurve(QPainter *,
 
204
        const QwtScaleMap &, const QwtScaleMap &,
 
205
        QwtPolygon &) const;
 
206
    void closePolyline(const QwtScaleMap &, const QwtScaleMap &,
 
207
        QwtPolygon &) const;
 
208
 
 
209
private:
 
210
    QwtData *d_xy;
 
211
 
 
212
    class PrivateData;
 
213
    PrivateData *d_data;
 
214
};
 
215
 
 
216
//! \return the the curve data
 
217
inline QwtData &QwtPlotCurve::data()
 
218
{
 
219
    return *d_xy;
 
220
}
 
221
 
 
222
//! \return the the curve data
 
223
inline const QwtData &QwtPlotCurve::data() const
 
224
{
 
225
    return *d_xy;
 
226
}
 
227
 
 
228
/*!
 
229
    \param i index
 
230
    \return x-value at position i
 
231
*/
 
232
inline double QwtPlotCurve::x(int i) const 
 
233
 
234
    return d_xy->x(i); 
 
235
}
 
236
 
 
237
/*!
 
238
    \param i index
 
239
    \return y-value at position i
 
240
*/
 
241
inline double QwtPlotCurve::y(int i) const 
 
242
 
243
    return d_xy->y(i); 
 
244
}
 
245
 
 
246
#endif