@@ -1,66 +1,64 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chart.h" |
|
21 | #include "chart.h" | |
22 | #include <QAxis> |
|
22 | #include <QAxis> | |
23 | #include <QSplineSeries> |
|
23 | #include <QSplineSeries> | |
24 | #include <QTime> |
|
24 | #include <QTime> | |
25 |
|
25 | |||
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) |
|
26 | Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |
27 | :QChart(parent, wFlags), |
|
27 | :QChart(parent, wFlags), | |
28 | m_step(1), |
|
28 | m_step(1), | |
29 | m_x(0), |
|
29 | m_x(0), | |
30 | m_y(1) |
|
30 | m_y(1) | |
31 | { |
|
31 | { | |
32 | qsrand((uint) QTime::currentTime().msec()); |
|
32 | qsrand((uint) QTime::currentTime().msec()); | |
33 |
|
33 | |||
34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); | |
35 | m_timer.setInterval(1000); |
|
35 | m_timer.setInterval(1000); | |
36 |
|
36 | |||
37 | m_series = new QSplineSeries(this); |
|
37 | m_series = new QSplineSeries(this); | |
38 | QPen green(Qt::red); |
|
38 | QPen green(Qt::red); | |
39 | green.setWidth(3); |
|
39 | green.setWidth(3); | |
40 | m_series->setPen(green); |
|
40 | m_series->setPen(green); | |
41 | m_series->append(m_x, m_y); |
|
41 | m_series->append(m_x, m_y); | |
42 |
|
42 | |||
43 | addSeries(m_series); |
|
43 | addSeries(m_series); | |
44 |
|
44 | |||
45 | axisY()->setRange(-5, 5); |
|
45 | axisY()->setRange(-5, 5); | |
46 | axisX()->setRange(-9, 1); |
|
46 | axisX()->setRange(-9, 1); | |
47 | axisX()->setTicksCount(11); |
|
47 | axisX()->setTicksCount(11); | |
48 |
|
48 | |||
49 | m_timer.start(); |
|
49 | m_timer.start(); | |
50 | } |
|
50 | } | |
51 |
|
51 | |||
52 | Chart::~Chart() |
|
52 | Chart::~Chart() | |
53 | { |
|
53 | { | |
54 |
|
54 | |||
55 | } |
|
55 | } | |
56 |
|
56 | |||
57 | void Chart::handleTimeout() |
|
57 | void Chart::handleTimeout() | |
58 | { |
|
58 | { | |
59 | m_x += m_step; |
|
59 | m_x += m_step; | |
60 | qreal y = m_y; |
|
|||
61 | m_y = qrand() % 5 - 2.5; |
|
60 | m_y = qrand() % 5 - 2.5; | |
62 | m_series->append(m_x, m_y); |
|
61 | m_series->append(m_x, m_y); | |
63 | if (m_x >= 10) |
|
|||
64 | m_series->remove(m_x - 10,y); |
|
|||
65 | scrollRight(); |
|
62 | scrollRight(); | |
|
63 | if(m_x==100) m_timer.stop(); | |||
66 | } |
|
64 | } |
General Comments 0
You need to be logged in to leave comments.
Login now