diff --git a/examples/ekgchart/chart.cpp b/examples/dynamicspline/chart.cpp similarity index 78% rename from examples/ekgchart/chart.cpp rename to examples/dynamicspline/chart.cpp index 9a1267c..5d8cc28 100644 --- a/examples/ekgchart/chart.cpp +++ b/examples/dynamicspline/chart.cpp @@ -29,30 +29,23 @@ Chart::Chart(QGraphicsItem *parent, Qt::WindowFlags wFlags) m_x(0), m_y(1) { - QTime now = QTime::currentTime(); - qsrand((uint)now.msec()); + qsrand((uint) QTime::currentTime().msec()); QObject::connect(&m_timer, SIGNAL(timeout()), this, SLOT(handleTimeout())); m_timer.setInterval(1000); - m_series0 = new QLineSeries(this); - QPen blue(Qt::blue); - blue.setWidth(3); - m_series0->setPen(blue); - - m_series1 = new QSplineSeries(this); + m_series = new QSplineSeries(this); QPen green(Qt::red); green.setWidth(3); - m_series1->setPen(green); + m_series->setPen(green); + m_series->append(m_x, m_y); - m_series0->append(m_x, m_y); - m_series1->append(m_x, m_y); + addSeries(m_series); - addSeries(m_series0); - addSeries(m_series1); axisY()->setRange(-5, 5); axisX()->setRange(-9, 1); axisX()->setTicksCount(11); + m_timer.start(); } @@ -65,11 +58,8 @@ void Chart::handleTimeout() { m_x += m_step; m_y = qrand() % 5 - 2.5; - m_series0->append(m_x, m_y); - m_series1->append(m_x, m_y); - if (m_x >= 10) { - m_series0->remove(m_x - 10); - m_series1->remove(m_x - 10); - } + m_series->append(m_x, m_y); + if (m_x >= 10) + m_series->remove(m_x - 10); scrollRight(); } diff --git a/examples/ekgchart/chart.h b/examples/dynamicspline/chart.h similarity index 95% rename from examples/ekgchart/chart.h rename to examples/dynamicspline/chart.h index 54533bc..7611dfa 100644 --- a/examples/ekgchart/chart.h +++ b/examples/dynamicspline/chart.h @@ -26,7 +26,6 @@ QTCOMMERCIALCHART_BEGIN_NAMESPACE class QSplineSeries; -class QLineSeries; QTCOMMERCIALCHART_END_NAMESPACE QTCOMMERCIALCHART_USE_NAMESPACE @@ -44,8 +43,7 @@ public slots: private: QTimer m_timer; - QLineSeries* m_series0; - QSplineSeries* m_series1; + QSplineSeries* m_series; QStringList m_titles; qreal m_step; qreal m_x; diff --git a/examples/ekgchart/ekgchart.pro b/examples/dynamicspline/dynamicspline.pro similarity index 83% rename from examples/ekgchart/ekgchart.pro rename to examples/dynamicspline/dynamicspline.pro index cf38a8e..68ca88d 100644 --- a/examples/ekgchart/ekgchart.pro +++ b/examples/dynamicspline/dynamicspline.pro @@ -1,6 +1,6 @@ !include( ../examples.pri ) { error( "Couldn't find the examples.pri file!" ) } -TARGET = ekgchart +TARGET = dynamicspline HEADERS += chart.h -SOURCES += main.cpp chart.cpp \ No newline at end of file +SOURCES += main.cpp chart.cpp diff --git a/examples/ekgchart/main.cpp b/examples/dynamicspline/main.cpp similarity index 97% rename from examples/ekgchart/main.cpp rename to examples/dynamicspline/main.cpp index 29a5d0c..bea00b3 100644 --- a/examples/ekgchart/main.cpp +++ b/examples/dynamicspline/main.cpp @@ -30,7 +30,7 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); QMainWindow window; Chart *chart = new Chart; - chart->setTitle("Simple EKG chart"); + chart->setTitle("Dynamic spline chart"); chart->setAnimationOptions(QChart::AllAnimations); QChartView chartView(chart); chartView.setRenderHint(QPainter::Antialiasing); diff --git a/examples/examples.pro b/examples/examples.pro index ed20c16..6a2d59c 100644 --- a/examples/examples.pro +++ b/examples/examples.pro @@ -3,7 +3,7 @@ SUBDIRS += \ areachart \ barchart \ customchart \ - ekgchart \ + dynamicspline \ linechart \ percentbarchart \ piechart \