##// END OF EJS Templates
Adds test/wavechart
Michal Klocek -
r867:ce55182e26ac
parent child
Show More
@@ -0,0 +1,24
1 #include "wavechart.h"
2 #include <QApplication>
3 #include <QMainWindow>
4 #include <QGLWidget>
5
6 int main(int argc, char *argv[])
7 {
8 QApplication a(argc, argv);
9
10 QMainWindow window;
11 QChart *chart = new QChart();
12 WaveChart *waveChart = new WaveChart(chart,&window);
13
14 waveChart->setViewport( new QGLWidget() );
15 waveChart->setRenderHint(QPainter::Antialiasing);
16 chart->setAnimationOptions(QChart::AllAnimations);
17 chart->setTitle("This is wave generator.");
18
19 window.setCentralWidget(waveChart);
20 window.resize(400, 300);
21 window.show();
22
23 return a.exec();
24 }
@@ -0,0 +1,48
1 #include "wavechart.h"
2 #include <cmath>
3
4 QTCOMMERCIALCHART_USE_NAMESPACE
5
6 #define PI 3.14159265358979
7 static const int numPoints =100;
8
9 WaveChart::WaveChart(QChart* chart, QWidget* parent) :
10 QChartView(chart, parent),
11 m_series(new QLineSeries()),
12 m_wave(0),
13 m_step(2 * PI / numPoints)
14 {
15 QPen blue(Qt::blue);
16 blue.setWidth(3);
17 m_series->setPen(blue);
18
19 QTime now = QTime::currentTime();
20 qsrand((uint) now.msec());
21
22 int fluctuate = 100;
23
24 for (qreal x = 0; x <= 2 * PI; x += m_step) {
25 m_series->append(x, fabs(sin(x) * fluctuate));
26 }
27
28 chart->addSeries(m_series);
29
30 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(update()));
31 m_timer.setInterval(5000);
32 m_timer.start();
33
34 }
35 ;
36
37 void WaveChart::update()
38 {
39
40 int fluctuate;
41
42 for (qreal i = 0, x = 0; x <= 2 * PI; x += m_step, i++) {
43 fluctuate = qrand() % 100;
44 m_series->replace(x, fabs(sin(x) * fluctuate));
45
46 }
47
48 }
@@ -0,0 +1,24
1 #include <QTimer>
2 #include <QTime>
3 #include <QObject>
4 #include <QLineSeries>
5 #include <QChartView>
6
7 QTCOMMERCIALCHART_USE_NAMESPACE
8
9 class WaveChart: public QChartView
10 {
11 Q_OBJECT
12
13 public:
14 WaveChart(QChart* chart, QWidget* parent);
15
16 private slots:
17 void update();
18
19 private:
20 QLineSeries* m_series;
21 int m_wave;
22 qreal m_step;
23 QTimer m_timer;
24 };
@@ -0,0 +1,10
1 !include( ../test.pri ) {
2 error( "Couldn't find the examples.pri file!" )
3 }
4 QT+=opengl
5 TARGET = wavechart
6 SOURCES += main.cpp wavechart.cpp
7 HEADERS += wavechart.h
8
9
10
@@ -1,6 +1,7
1 TEMPLATE = subdirs
1 TEMPLATE = subdirs
2 SUBDIRS += \
2 SUBDIRS += \
3 chartwidgettest \
3 chartwidgettest \
4 wavechart \
4 qmlchart
5 qmlchart
5
6
6 !win32:{
7 !win32:{
General Comments 0
You need to be logged in to leave comments. Login now