##// END OF EJS Templates
minor. minssing hile
Michal Klocek -
r134:bc1b888bffa3
parent child
Show More
@@ -0,0 +1,60
1 #include <QTimer>
2 #include <QTime>
3 #include <QObject>
4 #include <cmath>
5 #include <qxychartseries.h>
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
9 #define PI 3.14159265358979
10 static const int numPoints =100;
11
12 class WaveGenerator: public QObject
13 {
14 Q_OBJECT
15
16 public:
17 WaveGenerator(QXYChartSeries* series1, QXYChartSeries* series2) :
18 m_series1(series1),
19 m_series2(series2),
20 m_wave(0),
21 m_step(2*PI/numPoints)
22 {
23
24 QTime now = QTime::currentTime();
25 qsrand((uint)now.msec());
26
27 int fluctuate = 100;
28
29 for (qreal x = 0; x <= 2*PI; x+=m_step) {
30 series1->add(x, fabs(sin(x)*fluctuate));
31 series2->add(x, fabs(cos(x)*fluctuate));
32 }
33
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(update()));
35 m_timer.setInterval(5000);
36 m_timer.start();
37
38 };
39
40 public slots:
41 void update()
42 {
43 int fluctuate;
44
45 for (qreal i = 0, x = 0; x <= 2*PI; x+=m_step, i++) {
46 fluctuate = qrand() % 100;
47 m_series1->set(i, x, fabs(sin(x)*fluctuate));
48 fluctuate = qrand() % 100;
49 m_series2->set(i, x, fabs(cos(x)*fluctuate));
50 }
51
52 }
53
54 private:
55 QXYChartSeries* m_series1;
56 QXYChartSeries* m_series2;
57 int m_wave;
58 qreal m_step;
59 QTimer m_timer;
60 };
General Comments 0
You need to be logged in to leave comments. Login now