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