##// END OF EJS Templates
Bugfix: chartarea animation added functionl call insted of removed removed -> dangling pointer
Michal Klocek -
r648:8203d50669bc
parent child
Show More
@@ -1,392 +1,392
1 #include "qchart.h"
1 #include "qchart.h"
2 #include "qchartaxis.h"
2 #include "qchartaxis.h"
3 #include "chartpresenter_p.h"
3 #include "chartpresenter_p.h"
4 #include "chartdataset_p.h"
4 #include "chartdataset_p.h"
5 #include "charttheme_p.h"
5 #include "charttheme_p.h"
6 #include "chartanimator_p.h"
6 #include "chartanimator_p.h"
7 //series
7 //series
8 #include "qbarseries.h"
8 #include "qbarseries.h"
9 #include "qstackedbarseries.h"
9 #include "qstackedbarseries.h"
10 #include "qpercentbarseries.h"
10 #include "qpercentbarseries.h"
11 #include "qlineseries.h"
11 #include "qlineseries.h"
12 #include "qareaseries.h"
12 #include "qareaseries.h"
13 #include "qpieseries.h"
13 #include "qpieseries.h"
14 #include "qscatterseries.h"
14 #include "qscatterseries.h"
15 #include "qsplineseries.h"
15 #include "qsplineseries.h"
16 //items
16 //items
17 #include "axisitem_p.h"
17 #include "axisitem_p.h"
18 #include "areachartitem_p.h"
18 #include "areachartitem_p.h"
19 #include "barpresenter_p.h"
19 #include "barpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
20 #include "stackedbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
21 #include "percentbarpresenter_p.h"
22 #include "linechartitem_p.h"
22 #include "linechartitem_p.h"
23 #include "piechartitem_p.h"
23 #include "piechartitem_p.h"
24 #include "scatterchartitem_p.h"
24 #include "scatterchartitem_p.h"
25 #include "splinechartitem_p.h"
25 #include "splinechartitem_p.h"
26
26
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
27 QTCOMMERCIALCHART_BEGIN_NAMESPACE
28
28
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
29 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
30 m_chart(chart),
30 m_chart(chart),
31 m_animator(0),
31 m_animator(0),
32 m_dataset(dataset),
32 m_dataset(dataset),
33 m_chartTheme(0),
33 m_chartTheme(0),
34 m_zoomIndex(0),
34 m_zoomIndex(0),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
35 m_rect(QRectF(QPoint(0,0),m_chart->size())),
36 m_options(QChart::NoAnimation),
36 m_options(QChart::NoAnimation),
37 m_themeForce(false)
37 m_themeForce(false)
38 {
38 {
39 createConnections();
39 createConnections();
40 setChartTheme(QChart::ChartThemeDefault,false);
40 setChartTheme(QChart::ChartThemeDefault,false);
41 }
41 }
42
42
43 ChartPresenter::~ChartPresenter()
43 ChartPresenter::~ChartPresenter()
44 {
44 {
45 delete m_chartTheme;
45 delete m_chartTheme;
46 }
46 }
47
47
48 void ChartPresenter::createConnections()
48 void ChartPresenter::createConnections()
49 {
49 {
50 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
50 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
51 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
51 QObject::connect(m_dataset,SIGNAL(seriesAdded(QSeries*,Domain*)),this,SLOT(handleSeriesAdded(QSeries*,Domain*)));
52 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
52 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QSeries*)),this,SLOT(handleSeriesRemoved(QSeries*)));
53 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
53 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*,Domain*)),this,SLOT(handleAxisAdded(QChartAxis*,Domain*)));
54 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
54 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
55 }
55 }
56
56
57
57
58 QRectF ChartPresenter::geometry() const
58 QRectF ChartPresenter::geometry() const
59 {
59 {
60 return m_rect;
60 return m_rect;
61 }
61 }
62
62
63 void ChartPresenter::handleGeometryChanged()
63 void ChartPresenter::handleGeometryChanged()
64 {
64 {
65 QRectF rect(QPoint(0,0),m_chart->size());
65 QRectF rect(QPoint(0,0),m_chart->size());
66 rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding());
66 rect.adjust(m_chart->padding(),m_chart->padding(), -m_chart->padding(), -m_chart->padding());
67
67
68 //rewrite zoom stack
68 //rewrite zoom stack
69 for(int i=0;i<m_zoomStack.count();i++){
69 for(int i=0;i<m_zoomStack.count();i++){
70 QRectF r = m_zoomStack[i];
70 QRectF r = m_zoomStack[i];
71 qreal w = rect.width()/m_rect.width();
71 qreal w = rect.width()/m_rect.width();
72 qreal h = rect.height()/m_rect.height();
72 qreal h = rect.height()/m_rect.height();
73 QPointF tl = r.topLeft();
73 QPointF tl = r.topLeft();
74 tl.setX(tl.x()*w);
74 tl.setX(tl.x()*w);
75 tl.setY(tl.y()*h);
75 tl.setY(tl.y()*h);
76 QPointF br = r.bottomRight();
76 QPointF br = r.bottomRight();
77 br.setX(br.x()*w);
77 br.setX(br.x()*w);
78 br.setY(br.y()*h);
78 br.setY(br.y()*h);
79 r.setTopLeft(tl);
79 r.setTopLeft(tl);
80 r.setBottomRight(br);
80 r.setBottomRight(br);
81 m_zoomStack[i]=r;
81 m_zoomStack[i]=r;
82 }
82 }
83
83
84 m_rect = rect;
84 m_rect = rect;
85 Q_ASSERT(m_rect.isValid());
85 Q_ASSERT(m_rect.isValid());
86 emit geometryChanged(m_rect);
86 emit geometryChanged(m_rect);
87 }
87 }
88
88
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
89 void ChartPresenter::handleAxisAdded(QChartAxis* axis,Domain* domain)
90 {
90 {
91 AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
91 AxisItem* item = new AxisItem(axis,this,axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
92
92
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
93 if(m_options.testFlag(QChart::GridAxisAnimations)){
94 m_animator->addAnimation(item);
94 m_animator->addAnimation(item);
95 }
95 }
96
96
97 if(axis==m_dataset->axisX()){
97 if(axis==m_dataset->axisX()){
98 m_chartTheme->decorate(axis,true,m_themeForce);
98 m_chartTheme->decorate(axis,true,m_themeForce);
99 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
99 QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
100 //initialize
100 //initialize
101 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
101 item->handleRangeChanged(domain->minX(),domain->maxX(),domain->tickXCount());
102
102
103 }
103 }
104 else{
104 else{
105 m_chartTheme->decorate(axis,false,m_themeForce);
105 m_chartTheme->decorate(axis,false,m_themeForce);
106 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
106 QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),item,SLOT(handleRangeChanged(qreal,qreal,int)));
107 //initialize
107 //initialize
108 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
108 item->handleRangeChanged(domain->minY(),domain->maxY(),domain->tickYCount());
109 }
109 }
110
110
111 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
111 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
112 //initialize
112 //initialize
113 item->handleGeometryChanged(m_rect);
113 item->handleGeometryChanged(m_rect);
114 m_axisItems.insert(axis, item);
114 m_axisItems.insert(axis, item);
115 }
115 }
116
116
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
117 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
118 {
118 {
119 AxisItem* item = m_axisItems.take(axis);
119 AxisItem* item = m_axisItems.take(axis);
120 Q_ASSERT(item);
120 Q_ASSERT(item);
121 if(m_animator) m_animator->removeAnimation(item);
121 if(m_animator) m_animator->removeAnimation(item);
122 delete item;
122 delete item;
123 }
123 }
124
124
125
125
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
126 void ChartPresenter::handleSeriesAdded(QSeries* series,Domain* domain)
127 {
127 {
128 ChartItem *item = 0 ;
128 ChartItem *item = 0 ;
129
129
130 switch(series->type())
130 switch(series->type())
131 {
131 {
132 case QSeries::SeriesTypeLine: {
132 case QSeries::SeriesTypeLine: {
133
133
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
134 QLineSeries* lineSeries = static_cast<QLineSeries*>(series);
135 LineChartItem* line = new LineChartItem(lineSeries,m_chart);
135 LineChartItem* line = new LineChartItem(lineSeries,m_chart);
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
136 if(m_options.testFlag(QChart::SeriesAnimations)) {
137 m_animator->addAnimation(line);
137 m_animator->addAnimation(line);
138 }
138 }
139 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
139 m_chartTheme->decorate(lineSeries, m_dataset->seriesIndex(series),m_themeForce);
140 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
140 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),line,SLOT(handleGeometryChanged(const QRectF&)));
141 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
141 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),line,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
142 item = line;
142 item = line;
143 break;
143 break;
144 }
144 }
145
145
146 case QSeries::SeriesTypeArea: {
146 case QSeries::SeriesTypeArea: {
147
147
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
148 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
149 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
149 AreaChartItem* area = new AreaChartItem(areaSeries,m_chart);
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
150 if(m_options.testFlag(QChart::SeriesAnimations)) {
151 m_animator->addAnimation(area->upperLineItem());
151 m_animator->addAnimation(area->upperLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
152 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
153 }
153 }
154 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
154 m_chartTheme->decorate(areaSeries, m_dataset->seriesIndex(series),m_themeForce);
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),area,SLOT(handleGeometryChanged(const QRectF&)));
156 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
156 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),area,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
157 item=area;
157 item=area;
158 break;
158 break;
159 }
159 }
160
160
161 case QSeries::SeriesTypeBar: {
161 case QSeries::SeriesTypeBar: {
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
162 QBarSeries* barSeries = static_cast<QBarSeries*>(series);
163 BarPresenter* bar = new BarPresenter(barSeries,m_chart);
163 BarPresenter* bar = new BarPresenter(barSeries,m_chart);
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
164 if(m_options.testFlag(QChart::SeriesAnimations)) {
165 // m_animator->addAnimation(bar);
165 // m_animator->addAnimation(bar);
166 }
166 }
167 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
167 m_chartTheme->decorate(barSeries, m_dataset->seriesIndex(barSeries),m_themeForce);
168 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
168 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
169 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
169 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
170 item=bar;
170 item=bar;
171 break;
171 break;
172 }
172 }
173
173
174 case QSeries::SeriesTypeStackedBar: {
174 case QSeries::SeriesTypeStackedBar: {
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
175 QStackedBarSeries* stackedBarSeries = static_cast<QStackedBarSeries*>(series);
176 StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart);
176 StackedBarPresenter* bar = new StackedBarPresenter(stackedBarSeries,m_chart);
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
177 if(m_options.testFlag(QChart::SeriesAnimations)) {
178 // m_animator->addAnimation(bar);
178 // m_animator->addAnimation(bar);
179 }
179 }
180 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
180 m_chartTheme->decorate(stackedBarSeries, m_dataset->seriesIndex(stackedBarSeries),m_themeForce);
181 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
181 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
182 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
182 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
183 item=bar;
183 item=bar;
184 break;
184 break;
185 }
185 }
186
186
187 case QSeries::SeriesTypePercentBar: {
187 case QSeries::SeriesTypePercentBar: {
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
188 QPercentBarSeries* percentBarSeries = static_cast<QPercentBarSeries*>(series);
189 PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart);
189 PercentBarPresenter* bar = new PercentBarPresenter(percentBarSeries,m_chart);
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
190 if(m_options.testFlag(QChart::SeriesAnimations)) {
191 // m_animator->addAnimation(bar);
191 // m_animator->addAnimation(bar);
192 }
192 }
193 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
193 m_chartTheme->decorate(percentBarSeries, m_dataset->seriesIndex(percentBarSeries),m_themeForce);
194 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
194 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),bar,SLOT(handleGeometryChanged(const QRectF&)));
195 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
195 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),bar,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
196 item=bar;
196 item=bar;
197 break;
197 break;
198 }
198 }
199
199
200 case QSeries::SeriesTypeScatter: {
200 case QSeries::SeriesTypeScatter: {
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
201 QScatterSeries *scatterSeries = static_cast<QScatterSeries *>(series);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart);
202 ScatterChartItem *scatter = new ScatterChartItem(scatterSeries, m_chart);
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
203 if(m_options.testFlag(QChart::SeriesAnimations)) {
204 m_animator->addAnimation(scatter);
204 m_animator->addAnimation(scatter);
205 }
205 }
206 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
206 m_chartTheme->decorate(scatterSeries, m_dataset->seriesIndex(series),m_themeForce);
207 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
207 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),scatter,SLOT(handleGeometryChanged(const QRectF&)));
208 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
208 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),scatter,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
209 item = scatter;
209 item = scatter;
210 break;
210 break;
211 }
211 }
212
212
213 case QSeries::SeriesTypePie: {
213 case QSeries::SeriesTypePie: {
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
214 QPieSeries *pieSeries = static_cast<QPieSeries *>(series);
215 PieChartItem* pie = new PieChartItem(m_chart, pieSeries);
215 PieChartItem* pie = new PieChartItem(m_chart, pieSeries);
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
216 if(m_options.testFlag(QChart::SeriesAnimations)) {
217 m_animator->addAnimation(pie);
217 m_animator->addAnimation(pie);
218 }
218 }
219 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
219 m_chartTheme->decorate(pieSeries, m_dataset->seriesIndex(series),m_themeForce);
220 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
220 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),pie,SLOT(handleGeometryChanged(const QRectF&)));
221 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
221 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),pie,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
222 // Hide all from background when there is only piechart
222 // Hide all from background when there is only piechart
223 // TODO: refactor this ugly code... should be one setting for this
223 // TODO: refactor this ugly code... should be one setting for this
224 if (m_chartItems.count() == 0) {
224 if (m_chartItems.count() == 0) {
225 m_chart->axisX()->hide();
225 m_chart->axisX()->hide();
226 m_chart->axisY()->hide();
226 m_chart->axisY()->hide();
227 m_chart->setBackgroundVisible(false);
227 m_chart->setBackgroundVisible(false);
228 }
228 }
229 item=pie;
229 item=pie;
230 break;
230 break;
231 }
231 }
232
232
233 case QSeries::SeriesTypeSpline: {
233 case QSeries::SeriesTypeSpline: {
234 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
234 QSplineSeries* splineSeries = static_cast<QSplineSeries*>(series);
235 SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart);
235 SplineChartItem* spline = new SplineChartItem(splineSeries, m_chart);
236 if(m_options.testFlag(QChart::SeriesAnimations)) {
236 if(m_options.testFlag(QChart::SeriesAnimations)) {
237 m_animator->addAnimation(spline);
237 m_animator->addAnimation(spline);
238 }
238 }
239 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
239 m_chartTheme->decorate(splineSeries, m_dataset->seriesIndex(series),m_themeForce);
240 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
240 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),spline,SLOT(handleGeometryChanged(const QRectF&)));
241 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
241 QObject::connect(domain,SIGNAL(domainChanged(qreal,qreal,qreal,qreal)),spline,SLOT(handleDomainChanged(qreal,qreal,qreal,qreal)));
242 item=spline;
242 item=spline;
243 break;
243 break;
244 }
244 }
245 default: {
245 default: {
246 qDebug()<< "Series type" << series->type() << "not implemented.";
246 qDebug()<< "Series type" << series->type() << "not implemented.";
247 break;
247 break;
248 }
248 }
249 }
249 }
250
250
251 //initialize
251 //initialize
252 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
252 item->handleDomainChanged(domain->minX(),domain->maxX(),domain->minY(),domain->maxY());
253 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
253 if(m_rect.isValid()) item->handleGeometryChanged(m_rect);
254 m_chartItems.insert(series,item);
254 m_chartItems.insert(series,item);
255 zoomReset();
255 zoomReset();
256 }
256 }
257
257
258 void ChartPresenter::handleSeriesRemoved(QSeries* series)
258 void ChartPresenter::handleSeriesRemoved(QSeries* series)
259 {
259 {
260 ChartItem* item = m_chartItems.take(series);
260 ChartItem* item = m_chartItems.take(series);
261 Q_ASSERT(item);
261 Q_ASSERT(item);
262 if(m_animator) {
262 if(m_animator) {
263 //small hack to handle area animations
263 //small hack to handle area animations
264 if(series->type()==QSeries::SeriesTypeArea){
264 if(series->type()==QSeries::SeriesTypeArea){
265 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
265 QAreaSeries* areaSeries = static_cast<QAreaSeries*>(series);
266 AreaChartItem* area = static_cast<AreaChartItem*>(item);
266 AreaChartItem* area = static_cast<AreaChartItem*>(item);
267 m_animator->removeAnimation(area->upperLineItem());
267 m_animator->removeAnimation(area->upperLineItem());
268 if(areaSeries->lowerSeries()) m_animator->addAnimation(area->lowerLineItem());
268 if(areaSeries->lowerSeries()) m_animator->removeAnimation(area->lowerLineItem());
269 }else
269 }else
270 m_animator->removeAnimation(item);
270 m_animator->removeAnimation(item);
271 }
271 }
272 delete item;
272 delete item;
273 }
273 }
274
274
275 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
275 void ChartPresenter::setChartTheme(QChart::ChartTheme theme,bool force)
276 {
276 {
277 if(m_chartTheme && m_chartTheme->id() == theme) return;
277 if(m_chartTheme && m_chartTheme->id() == theme) return;
278 delete m_chartTheme;
278 delete m_chartTheme;
279 m_themeForce = force;
279 m_themeForce = force;
280 m_chartTheme = ChartTheme::createTheme(theme);
280 m_chartTheme = ChartTheme::createTheme(theme);
281 m_chartTheme->decorate(m_chart,m_themeForce);
281 m_chartTheme->decorate(m_chart,m_themeForce);
282 m_chartTheme->decorate(m_chart->legend(),m_themeForce);
282 m_chartTheme->decorate(m_chart->legend(),m_themeForce);
283 resetAllElements();
283 resetAllElements();
284 }
284 }
285
285
286 QChart::ChartTheme ChartPresenter::chartTheme()
286 QChart::ChartTheme ChartPresenter::chartTheme()
287 {
287 {
288 return m_chartTheme->id();
288 return m_chartTheme->id();
289 }
289 }
290
290
291 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
291 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
292 {
292 {
293 if(m_options!=options) {
293 if(m_options!=options) {
294
294
295 m_options=options;
295 m_options=options;
296
296
297 if(m_options!=QChart::NoAnimation && !m_animator) {
297 if(m_options!=QChart::NoAnimation && !m_animator) {
298 m_animator= new ChartAnimator(this);
298 m_animator= new ChartAnimator(this);
299
299
300 }
300 }
301 resetAllElements();
301 resetAllElements();
302 }
302 }
303
303
304 }
304 }
305
305
306 void ChartPresenter::resetAllElements()
306 void ChartPresenter::resetAllElements()
307 {
307 {
308 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
308 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
309 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
309 QList<QSeries*> seriesList = m_chartItems.uniqueKeys();
310
310
311 foreach(QChartAxis* axis, axisList) {
311 foreach(QChartAxis* axis, axisList) {
312 handleAxisRemoved(axis);
312 handleAxisRemoved(axis);
313 handleAxisAdded(axis,m_dataset->domain(axis));
313 handleAxisAdded(axis,m_dataset->domain(axis));
314 }
314 }
315 foreach(QSeries* series, seriesList) {
315 foreach(QSeries* series, seriesList) {
316 handleSeriesRemoved(series);
316 handleSeriesRemoved(series);
317 handleSeriesAdded(series,m_dataset->domain(series));
317 handleSeriesAdded(series,m_dataset->domain(series));
318 }
318 }
319 }
319 }
320
320
321 void ChartPresenter::zoomIn()
321 void ChartPresenter::zoomIn()
322 {
322 {
323 QRectF rect = geometry();
323 QRectF rect = geometry();
324 rect.setWidth(rect.width()/2);
324 rect.setWidth(rect.width()/2);
325 rect.setHeight(rect.height()/2);
325 rect.setHeight(rect.height()/2);
326 rect.moveCenter(geometry().center());
326 rect.moveCenter(geometry().center());
327 zoomIn(rect);
327 zoomIn(rect);
328 }
328 }
329
329
330 void ChartPresenter::zoomIn(const QRectF& rect)
330 void ChartPresenter::zoomIn(const QRectF& rect)
331 {
331 {
332 QRectF r = rect.normalized();
332 QRectF r = rect.normalized();
333 r.translate(-m_chart->padding(), -m_chart->padding());
333 r.translate(-m_chart->padding(), -m_chart->padding());
334 if(m_animator) {
334 if(m_animator) {
335
335
336 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
336 QPointF point(r.center().x()/geometry().width(),r.center().y()/geometry().height());
337 m_animator->setState(ChartAnimator::ZoomInState,point);
337 m_animator->setState(ChartAnimator::ZoomInState,point);
338 }
338 }
339 m_dataset->zoomInDomain(r,geometry().size());
339 m_dataset->zoomInDomain(r,geometry().size());
340 m_zoomStack<<r;
340 m_zoomStack<<r;
341 m_zoomIndex++;
341 m_zoomIndex++;
342 if(m_animator) {
342 if(m_animator) {
343 m_animator->setState(ChartAnimator::ShowState);
343 m_animator->setState(ChartAnimator::ShowState);
344 }
344 }
345 }
345 }
346
346
347 void ChartPresenter::zoomOut()
347 void ChartPresenter::zoomOut()
348 {
348 {
349 if(m_zoomIndex==0) return;
349 if(m_zoomIndex==0) return;
350 if(m_animator)
350 if(m_animator)
351 {
351 {
352 m_animator->setState(ChartAnimator::ZoomOutState);
352 m_animator->setState(ChartAnimator::ZoomOutState);
353 }
353 }
354 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
354 m_dataset->zoomOutDomain(m_zoomStack[m_zoomIndex-1],geometry().size());
355 m_zoomIndex--;
355 m_zoomIndex--;
356 m_zoomStack.resize(m_zoomIndex);
356 m_zoomStack.resize(m_zoomIndex);
357 if(m_animator){
357 if(m_animator){
358 m_animator->setState(ChartAnimator::ShowState);
358 m_animator->setState(ChartAnimator::ShowState);
359 }
359 }
360 }
360 }
361
361
362 void ChartPresenter::zoomReset()
362 void ChartPresenter::zoomReset()
363 {
363 {
364 m_zoomIndex=0;
364 m_zoomIndex=0;
365 m_zoomStack.resize(m_zoomIndex);
365 m_zoomStack.resize(m_zoomIndex);
366 }
366 }
367
367
368 void ChartPresenter::scroll(int dx,int dy)
368 void ChartPresenter::scroll(int dx,int dy)
369 {
369 {
370 if(m_animator){
370 if(m_animator){
371 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
371 if(dx<0) m_animator->setState(ChartAnimator::ScrollLeftState,QPointF());
372 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
372 if(dx>0) m_animator->setState(ChartAnimator::ScrollRightState,QPointF());
373 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
373 if(dy<0) m_animator->setState(ChartAnimator::ScrollUpState,QPointF());
374 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
374 if(dy>0) m_animator->setState(ChartAnimator::ScrollDownState,QPointF());
375 }
375 }
376
376
377 m_dataset->scrollDomain(dx,dy,geometry().size());
377 m_dataset->scrollDomain(dx,dy,geometry().size());
378
378
379 if(m_animator){
379 if(m_animator){
380 m_animator->setState(ChartAnimator::ShowState);
380 m_animator->setState(ChartAnimator::ShowState);
381 }
381 }
382 }
382 }
383
383
384 QChart::AnimationOptions ChartPresenter::animationOptions() const
384 QChart::AnimationOptions ChartPresenter::animationOptions() const
385 {
385 {
386 return m_options;
386 return m_options;
387 }
387 }
388
388
389
389
390 #include "moc_chartpresenter_p.cpp"
390 #include "moc_chartpresenter_p.cpp"
391
391
392 QTCOMMERCIALCHART_END_NAMESPACE
392 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now