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

« back to all changes in this revision

Viewing changes to qwt-5.1.2/examples/curvdemo1/curvdemo1.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fathi Boudra
  • Date: 2009-07-01 16:08:21 UTC
  • mfrom: (1.1.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20090701160821-gog44m4w7x2f4u6o
Tags: 5.2.0-1
* New upstream release.
* Add branch pull patch from svn r544.
* Bump Standards-Version to 3.8.2. No changes needed.
* Update installed manpages.
* Use qwt as base name for directory (drop version).
* Add missing warnings patch.
* Rewrite debian/rules: use dh.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#include <qapplication.h>
2
 
#include <qframe.h>
3
 
#include <qwt_scale_map.h>
4
 
#include <qwt_plot_curve.h>
5
 
#include <qwt_symbol.h>
6
 
#include <qcolor.h>
7
 
#include <qpainter.h>
8
 
#include <math.h>
9
 
 
10
 
//------------------------------------------------------------
11
 
//      curvdemo1
12
 
//
13
 
//  This example program features some of the different
14
 
//  display styles of the QwtPlotCurve class
15
 
//------------------------------------------------------------
16
 
 
17
 
 
18
 
//
19
 
//   Array Sizes
20
 
//
21
 
const int Size = 27;
22
 
#if QT_VERSION >= 0x040000
23
 
const int CurvCnt = 6;
24
 
#else
25
 
const int CurvCnt = 5;
26
 
#endif
27
 
 
28
 
//
29
 
//   Arrays holding the values
30
 
//
31
 
double xval[Size];
32
 
double yval[Size];
33
 
QwtScaleMap xMap; 
34
 
QwtScaleMap yMap;
35
 
 
36
 
class MainWin : public QFrame 
37
 
{
38
 
public:
39
 
    MainWin();
40
 
    
41
 
protected:
42
 
#if QT_VERSION >= 0x040000
43
 
    virtual void paintEvent(QPaintEvent *);
44
 
#endif
45
 
    void drawContents(QPainter *p);
46
 
 
47
 
private:
48
 
    void shiftDown(QRect &rect, int offset) const;
49
 
 
50
 
    QwtPlotCurve crv[CurvCnt];
51
 
};
52
 
 
53
 
MainWin::MainWin() 
54
 
{
55
 
    int i;
56
 
 
57
 
    xMap.setScaleInterval(-0.5, 10.5);
58
 
    yMap.setScaleInterval(-1.1, 1.1);
59
 
 
60
 
    //
61
 
    //  Frame style
62
 
    //  
63
 
    setFrameStyle(QFrame::Box|QFrame::Raised);
64
 
    setLineWidth(2);
65
 
    setMidLineWidth(3);
66
 
 
67
 
    //
68
 
    // Calculate values
69
 
    //
70
 
    for(i=0; i<Size;i++)
71
 
    {   xval[i] = double(i) * 10.0 / double(Size - 1);
72
 
        yval[i] = sin(xval[i]) * cos(2.0 * xval[i]);
73
 
    }
74
 
    
75
 
    //
76
 
    //  define curve styles
77
 
    // 
78
 
    QwtSymbol sym;
79
 
    i = 0;
80
 
 
81
 
    sym.setStyle(QwtSymbol::Cross);
82
 
    sym.setPen(QColor(Qt::black));
83
 
    sym.setSize(5);
84
 
    crv[i].setSymbol(sym);
85
 
    crv[i].setPen(QColor(Qt::darkGreen));
86
 
    crv[i].setStyle(QwtPlotCurve::Lines);
87
 
    crv[i].setCurveAttribute(QwtPlotCurve::Fitted);
88
 
    i++;
89
 
 
90
 
    sym.setStyle(QwtSymbol::Ellipse);
91
 
    sym.setPen(QColor(Qt::blue));
92
 
    sym.setBrush(QColor(Qt::yellow));
93
 
    sym.setSize(5);
94
 
    crv[i].setSymbol(sym);
95
 
    crv[i].setPen(QColor(Qt::red));
96
 
    crv[i].setStyle(QwtPlotCurve::Sticks);
97
 
    i++;
98
 
 
99
 
    crv[i].setPen(QColor(Qt::darkBlue));
100
 
    crv[i].setStyle(QwtPlotCurve::Lines);
101
 
    i++;
102
 
 
103
 
#if QT_VERSION >= 0x040000
104
 
    crv[i].setPen(QColor(Qt::darkBlue));
105
 
    crv[i].setStyle(QwtPlotCurve::Lines);
106
 
    crv[i].setRenderHint(QwtPlotItem::RenderAntialiased);
107
 
    i++;
108
 
#endif
109
 
 
110
 
 
111
 
    crv[i].setPen(QColor(Qt::darkCyan));
112
 
    crv[i].setStyle(QwtPlotCurve::Steps);
113
 
    i++;
114
 
 
115
 
    sym.setStyle(QwtSymbol::XCross);
116
 
    sym.setPen(QColor(Qt::darkMagenta));
117
 
    crv[i].setSymbol(sym);
118
 
    crv[i].setStyle(QwtPlotCurve::NoCurve);
119
 
    i++;
120
 
 
121
 
 
122
 
    //
123
 
    // attach data
124
 
    //
125
 
    for(i=0;i<CurvCnt;i++)
126
 
        crv[i].setRawData(xval,yval,Size);
127
 
}
128
 
 
129
 
void MainWin::shiftDown(QRect &rect, int offset) const
130
 
{
131
 
#if QT_VERSION < 0x040000
132
 
        rect.moveBy(0, offset);     
133
 
#else
134
 
        rect.translate(0, offset);     
135
 
#endif
136
 
}
137
 
 
138
 
#if QT_VERSION >= 0x040000
139
 
void MainWin::paintEvent(QPaintEvent *event)
140
 
{
141
 
    QFrame::paintEvent(event);
142
 
 
143
 
    QPainter painter(this);
144
 
    painter.setClipRect(contentsRect());
145
 
    drawContents(&painter);
146
 
}
147
 
#endif
148
 
 
149
 
 
150
 
//
151
 
//  REDRAW CONTENTS
152
 
//
153
 
void MainWin::drawContents(QPainter *painter)
154
 
{
155
 
    int deltay,i;
156
 
 
157
 
    QRect r = contentsRect();
158
 
 
159
 
    deltay = r.height() / CurvCnt - 1;
160
 
 
161
 
    r.setHeight(deltay);
162
 
 
163
 
    //
164
 
    //  draw curves
165
 
    //
166
 
    for (i=0;i<CurvCnt;i++)
167
 
    {
168
 
        xMap.setPaintInterval(r.left(), r.right());
169
 
        yMap.setPaintInterval(r.top(), r.bottom());
170
 
 
171
 
#if QT_VERSION >= 0x040000
172
 
        painter->setRenderHint(QPainter::Antialiasing,
173
 
            crv[i].testRenderHint(QwtPlotItem::RenderAntialiased) );
174
 
#endif
175
 
        crv[i].draw(painter, xMap, yMap, r);
176
 
 
177
 
        shiftDown(r, deltay);
178
 
    }
179
 
 
180
 
    //
181
 
    // draw titles
182
 
    //
183
 
    r = contentsRect();     // reset r
184
 
    painter->setFont(QFont("Helvetica", 8));
185
 
    
186
 
    const int alignment = Qt::AlignTop|Qt::AlignHCenter;
187
 
 
188
 
    painter->setPen(Qt::black);
189
 
 
190
 
    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
191
 
        alignment, "Style: Line/Fitted, Symbol: Cross");
192
 
    shiftDown(r, deltay);
193
 
 
194
 
    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
195
 
        alignment, "Style: Sticks, Symbol: Ellipse");
196
 
    shiftDown(r, deltay);
197
 
    
198
 
    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
199
 
        alignment, "Style: Lines, Symbol: None");
200
 
    shiftDown(r, deltay);
201
 
 
202
 
#if QT_VERSION >= 0x040000
203
 
    painter->drawText(0 ,r.top(),r.width(), painter->fontMetrics().height(),
204
 
        alignment, "Style: Lines, Symbol: None, Antialiased");
205
 
    shiftDown(r, deltay);
206
 
#endif
207
 
    
208
 
    
209
 
    painter->drawText(0, r.top(),r.width(), painter->fontMetrics().height(),
210
 
        alignment, "Style: Steps, Symbol: None");
211
 
    shiftDown(r, deltay);
212
 
    
213
 
    painter->drawText(0,r.top(),r.width(), painter->fontMetrics().height(),
214
 
        alignment, "Style: NoCurve, Symbol: XCross");
215
 
}
216
 
 
217
 
int main (int argc, char **argv)
218
 
{
219
 
    QApplication a(argc, argv);
220
 
 
221
 
    MainWin w;
222
 
 
223
 
#if QT_VERSION < 0x040000
224
 
    a.setMainWidget(&w);
225
 
#endif
226
 
    w.resize(300,600);
227
 
    w.show();
228
 
 
229
 
    return a.exec();
230
 
}