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