##// END OF EJS Templates
Presenter chart updated
Marek Rosa -
r1581:59746c604f2c
parent child
Show More
@@ -32,7 +32,7
32 32
33 33 \snippet ../examples/presenterchart/chartview.cpp 3
34 34
35 In \c handleTimeout() slot we change currently displayed chart by removing previous series and adding next series from the \c m_series list. We also set proper title.
35 In \c handleTimeout() slot we change currently displayed chart by removing previous series and adding next series from the \c m_series list. We also set proper title and create the axes for the chart.
36 36
37 37 \snippet ../examples/presenterchart/chartview.cpp 4
38 38 */
@@ -25,15 +25,17
25 25 #include <QAreaSeries>
26 26 #include <QTime>
27 27
28 ChartView::ChartView(QChart* chart,QWidget* parent):QChartView(chart,parent),
29 m_index(-1),m_chart(chart)
28 ChartView::ChartView(QChart* chart,QWidget* parent):
29 QChartView(chart,parent),
30 m_index(-1),
31 m_chart(chart)
30 32 {
31 33 m_chart->setTitle("Charts presenter");
32 34 m_chart->setDropShadowEnabled(false);
33 35 QObject::connect(&m_timer,SIGNAL(timeout()),this,SLOT(handleTimeout()));
34 36 m_timer.setInterval(3000);
35 37
36 //![1]
38 //![1]
37 39 QLineSeries* series0 = new QLineSeries();
38 40 series0->setName("line");
39 41
@@ -45,9 +47,9 m_index(-1),m_chart(chart)
45 47
46 48 QAreaSeries* series3 = new QAreaSeries(series0);
47 49 series3->setName("area");
48 //![1]
50 //![1]
49 51
50 //![2]
52 //![2]
51 53 int numPoints = 10;
52 54
53 55 for (int x = 0; x <= numPoints; ++x) {
@@ -56,9 +58,9 m_index(-1),m_chart(chart)
56 58 series1->append(x,y);
57 59 series2->append(x,y);
58 60 }
59 //![2]
61 //![2]
60 62
61 //![3]
63 //![3]
62 64 m_series<<series0;
63 65 m_titles<< m_chart->title()+": LineChart";
64 66 m_series<<series1;
@@ -67,7 +69,7 m_index(-1),m_chart(chart)
67 69 m_titles<< m_chart->title()+": SplineChart";
68 70 m_series<<series3;
69 71 m_titles<< m_chart->title()+": AreaChart";
70 //![3]
72 //![3]
71 73
72 74 m_timer.start();
73 75 handleTimeout();
@@ -75,7 +77,7 m_index(-1),m_chart(chart)
75 77
76 78 ChartView::~ChartView()
77 79 {
78 if(m_series.size()==0) return;
80 if(m_series.size() == 0) return;
79 81 m_chart->removeSeries(m_series.at(m_index));
80 82 m_series.removeLast(); //remove QAreaSeries instance since they will be deleted when QLineSeries instance is gone
81 83 qDeleteAll(m_series);
@@ -84,12 +86,13 ChartView::~ChartView()
84 86 //![4]
85 87 void ChartView::handleTimeout()
86 88 {
87 if(m_series.size()==0) return;
88 if(m_index>=0)
89 m_chart->removeSeries(m_series.at(m_index));
89 if(m_series.size() == 0) return;
90 if(m_index >= 0)
91 m_chart->removeSeries(m_series.at(m_index));
90 92 m_index++;
91 m_index=m_index%m_series.size();
93 m_index = m_index % m_series.size();
92 94 m_chart->addSeries(m_series.at(m_index));
93 95 m_chart->setTitle(m_titles.at(m_index));
96 m_chart->createDefaultAxes();
94 97 }
95 98 //![4]
General Comments 0
You need to be logged in to leave comments. Login now