@@ -18,20 +18,21 | |||||
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "chart |
|
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) | |
26 | m_step(1), |
|
27 | :QChart(parent, wFlags), | |
27 | m_x(0), |
|
28 | m_step(1), | |
28 | m_y(1) |
|
29 | m_x(0), | |
|
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); | |
36 |
|
37 | |||
37 | m_series0 = new QLineSeries(this); |
|
38 | m_series0 = new QLineSeries(this); | |
@@ -39,39 +40,36 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); | |
46 | m_series1->setPen(green); |
|
46 | m_series1->setPen(green); | |
47 |
|
47 | |||
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); | |
55 | axisX()->setRange(-9,1); |
|
54 | axisX()->setRange(-9, 1); | |
56 | axisX()->setTicksCount(11); |
|
55 | axisX()->setTicksCount(11); | |
57 | m_timer.start(); |
|
56 | m_timer.start(); | |
58 | } |
|
57 | } | |
59 |
|
58 | |||
60 |
Chart |
|
59 | Chart::~Chart() | |
61 | { |
|
60 | { | |
62 |
|
61 | |||
63 | } |
|
62 | } | |
64 |
|
63 | |||
65 |
void Chart |
|
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 | { |
|
71 | m_series0->remove(m_x - 10); | |
73 |
m_series |
|
72 | m_series1->remove(m_x - 10); | |
74 | m_series1->remove(m_x-10); |
|
|||
75 | } |
|
73 | } | |
76 | scrollRight(); |
|
74 | scrollRight(); | |
77 | } |
|
75 | } |
@@ -18,13 +18,12 | |||||
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#ifndef CHART |
|
21 | #ifndef CHART_H_ | |
22 |
#define CHART |
|
22 | #define CHART_H_ | |
23 |
|
23 | |||
24 |
#include <QChart |
|
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 Chart |
|
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 ~Chart |
|
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 /* CHART |
|
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 += chart |
|
5 | HEADERS += chart.h | |
6 |
SOURCES += main.cpp chart |
|
6 | SOURCES += main.cpp chart.cpp No newline at end of file |
@@ -18,17 +18,22 | |||||
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 |
#include "chart |
|
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(); |
General Comments 0
You need to be logged in to leave comments.
Login now