##// END OF EJS Templates
Make ekgchart compile
Jani Honkonen -
r840:58901e478159
parent child
Show More
@@ -18,18 +18,19
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartview.h"
21 #include "chart.h"
22 #include <QChartAxis>
22 #include <QSplineSeries>
23 #include <QSplineSeries>
23 #include <QTime>
24 #include <QTime>
24
25
25 ChartView::ChartView(QWidget* parent):QChartView(parent),
26 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags)
27 :QChart(parent, wFlags),
26 m_step(1),
28 m_step(1),
27 m_x(0),
29 m_x(0),
28 m_y(1)
30 m_y(1)
29 {
31 {
30 QTime now = QTime::currentTime();
32 QTime now = QTime::currentTime();
31 qsrand((uint)now.msec());
33 qsrand((uint)now.msec());
32 setChartTitle("Three random line charts");
33
34
34 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
35 QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout()));
35 m_timer.setInterval(1000);
36 m_timer.setInterval(1000);
@@ -39,7 +40,6 m_y(1)
39 blue.setWidth(3);
40 blue.setWidth(3);
40 m_series0->setPen(blue);
41 m_series0->setPen(blue);
41
42
42
43 m_series1 = new QSplineSeries(this);
43 m_series1 = new QSplineSeries(this);
44 QPen green(Qt::red);
44 QPen green(Qt::red);
45 green.setWidth(3);
45 green.setWidth(3);
@@ -48,7 +48,6 m_y(1)
48 m_series0->append(m_x,m_y);
48 m_series0->append(m_x, m_y);
49 m_series1->append(m_x,m_y);
49 m_series1->append(m_x, m_y);
50
50
51 setChartTitle("Simple EKG chart");
52 addSeries(m_series0);
51 addSeries(m_series0);
53 addSeries(m_series1);
52 addSeries(m_series1);
54 axisY()->setRange(-5,5);
53 axisY()->setRange(-5, 5);
@@ -57,19 +56,18 m_y(1)
57 m_timer.start();
56 m_timer.start();
58 }
57 }
59
58
60 ChartView::~ChartView()
59 Chart::~Chart()
61 {
60 {
62
61
63 }
62 }
64
63
65 void ChartView::handleTimeout()
64 void Chart::handleTimeout()
66 {
65 {
67 m_x+=m_step;
66 m_x += m_step;
68 m_y = qrand() % 5 - 2.5;
67 m_y = qrand() % 5 - 2.5;
69 m_series0->append(m_x,m_y);
68 m_series0->append(m_x, m_y);
70 m_series1->append(m_x,m_y);
69 m_series1->append(m_x, m_y);
71 if(m_x>=10)
70 if (m_x >= 10) {
72 {
73 m_series0->remove(m_x-10);
71 m_series0->remove(m_x - 10);
74 m_series1->remove(m_x-10);
72 m_series1->remove(m_x - 10);
75 }
73 }
@@ -18,13 +18,12
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #ifndef CHARTVIEW_H_
21 #ifndef CHART_H_
22 #define CHARTVIEW_H_
22 #define CHART_H_
23
23
24 #include <QChartView>
24 #include <QChart>
25 #include <QTimer>
25 #include <QTimer>
26
26
27
28 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 class QSplineSeries;
28 class QSplineSeries;
30 class QLineSeries;
29 class QLineSeries;
@@ -33,12 +32,12 QTCOMMERCIALCHART_END_NAMESPACE
33 QTCOMMERCIALCHART_USE_NAMESPACE
32 QTCOMMERCIALCHART_USE_NAMESPACE
34
33
35 //![1]
34 //![1]
36 class ChartView: public QChartView
35 class Chart: public QChart
37 {
36 {
38 Q_OBJECT
37 Q_OBJECT
39 public:
38 public:
40 ChartView(QWidget* parent = 0);
39 Chart(QGraphicsItem *parent = 0, Qt::WindowFlags wFlags = 0);
41 virtual ~ChartView();
40 virtual ~Chart();
42
41
43 public slots:
42 public slots:
44 void handleTimeout();
43 void handleTimeout();
@@ -54,4 +53,4 private:
54 };
53 };
55 //![1]
54 //![1]
56
55
57 #endif /* CHARTVIEW_H_ */
56 #endif /* CHART_H_ */
@@ -2,5 +2,5
2 error( "Couldn't find the examples.pri file!" )
2 error( "Couldn't find the examples.pri file!" )
3 }
3 }
4 TARGET = ekgchart
4 TARGET = ekgchart
5 HEADERS += chartview.h
5 HEADERS += chart.h
6 SOURCES += main.cpp chartview.cpp No newline at end of file
6 SOURCES += main.cpp chart.cpp No newline at end of file
@@ -18,17 +18,22
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartview.h"
21 #include "chart.h"
22 #include <QChartView>
22 #include <QApplication>
23 #include <QApplication>
23 #include <QMainWindow>
24 #include <QMainWindow>
24
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
25 int main(int argc, char *argv[])
28 int main(int argc, char *argv[])
26 {
29 {
27 QApplication a(argc, argv);
30 QApplication a(argc, argv);
28 QMainWindow window;
31 QMainWindow window;
29 ChartView chartView(&window);
32 Chart *chart = new Chart;
33 chart->setTitle("Simple EKG chart");
34 chart->setAnimationOptions(QChart::AllAnimations);
35 QChartView chartView(chart);
30 chartView.setRenderHint(QPainter::Antialiasing);
36 chartView.setRenderHint(QPainter::Antialiasing);
31 chartView.setAnimationOptions(QChart::AllAnimations);
32 window.setCentralWidget(&chartView);
37 window.setCentralWidget(&chartView);
33 window.resize(400, 300);
38 window.resize(400, 300);
34 window.show();
39 window.show();
@@ -5,7 +5,7 SUBDIRS += \
5 #chartview \
5 #chartview \
6 customchart \
6 customchart \
7 #dynamiclinechart \
7 #dynamiclinechart \
8 #ekgchart \
8 ekgchart \
9 linechart \
9 linechart \
10 #multichart \
10 #multichart \
11 percentbarchart \
11 percentbarchart \
General Comments 0
You need to be logged in to leave comments. Login now