@@ -29,30 +29,23 Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) | |||
|
29 | 29 | m_x(0), |
|
30 | 30 | m_y(1) |
|
31 | 31 | { |
|
32 |
|
|
|
33 | qsrand((uint)now.msec()); | |
|
32 | qsrand((uint) QTime::currentTime().msec()); | |
|
34 | 33 | |
|
35 | 34 | QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); |
|
36 | 35 | m_timer.setInterval(1000); |
|
37 | 36 | |
|
38 |
m_series |
|
|
39 | QPen blue(Qt::blue); | |
|
40 | blue.setWidth(3); | |
|
41 | m_series0->setPen(blue); | |
|
42 | ||
|
43 | m_series1 = new QSplineSeries(this); | |
|
37 | m_series = new QSplineSeries(this); | |
|
44 | 38 | QPen green(Qt::red); |
|
45 | 39 | green.setWidth(3); |
|
46 |
m_series |
|
|
40 | m_series->setPen(green); | |
|
41 | m_series->append(m_x, m_y); | |
|
47 | 42 | |
|
48 | m_series0->append(m_x, m_y); | |
|
49 | m_series1->append(m_x, m_y); | |
|
43 | addSeries(m_series); | |
|
50 | 44 | |
|
51 | addSeries(m_series0); | |
|
52 | addSeries(m_series1); | |
|
53 | 45 | axisY()->setRange(-5, 5); |
|
54 | 46 | axisX()->setRange(-9, 1); |
|
55 | 47 | axisX()->setTicksCount(11); |
|
48 | ||
|
56 | 49 | m_timer.start(); |
|
57 | 50 | } |
|
58 | 51 | |
@@ -65,11 +58,8 void Chart::handleTimeout() | |||
|
65 | 58 | { |
|
66 | 59 | m_x += m_step; |
|
67 | 60 | m_y = qrand() % 5 - 2.5; |
|
68 |
m_series |
|
|
69 | m_series1->append(m_x, m_y); | |
|
70 | if (m_x >= 10) { | |
|
71 | m_series0->remove(m_x - 10); | |
|
72 | m_series1->remove(m_x - 10); | |
|
73 | } | |
|
61 | m_series->append(m_x, m_y); | |
|
62 | if (m_x >= 10) | |
|
63 | m_series->remove(m_x - 10); | |
|
74 | 64 | scrollRight(); |
|
75 | 65 | } |
@@ -26,7 +26,6 | |||
|
26 | 26 | |
|
27 | 27 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
28 | 28 | class QSplineSeries; |
|
29 | class QLineSeries; | |
|
30 | 29 | QTCOMMERCIALCHART_END_NAMESPACE |
|
31 | 30 | |
|
32 | 31 | QTCOMMERCIALCHART_USE_NAMESPACE |
@@ -44,8 +43,7 public slots: | |||
|
44 | 43 | |
|
45 | 44 | private: |
|
46 | 45 | QTimer m_timer; |
|
47 |
Q |
|
|
48 | QSplineSeries* m_series1; | |
|
46 | QSplineSeries* m_series; | |
|
49 | 47 | QStringList m_titles; |
|
50 | 48 | qreal m_step; |
|
51 | 49 | qreal m_x; |
@@ -1,6 +1,6 | |||
|
1 | 1 | !include( ../examples.pri ) { |
|
2 | 2 | error( "Couldn't find the examples.pri file!" ) |
|
3 | 3 | } |
|
4 | TARGET = ekgchart | |
|
4 | TARGET = dynamicspline | |
|
5 | 5 | HEADERS += chart.h |
|
6 | SOURCES += main.cpp chart.cpp No newline at end of file | |
|
6 | SOURCES += main.cpp chart.cpp |
@@ -30,7 +30,7 int main(int argc, char *argv[]) | |||
|
30 | 30 | QApplication a(argc, argv); |
|
31 | 31 | QMainWindow window; |
|
32 | 32 | Chart *chart = new Chart; |
|
33 |
chart->setTitle(" |
|
|
33 | chart->setTitle("Dynamic spline chart"); | |
|
34 | 34 | chart->setAnimationOptions(QChart::AllAnimations); |
|
35 | 35 | QChartView chartView(chart); |
|
36 | 36 | chartView.setRenderHint(QPainter::Antialiasing); |
General Comments 0
You need to be logged in to leave comments.
Login now