##// END OF EJS Templates
minor. remove debug info
Michal Klocek -
r299:be7277669d04
parent child
Show More
@@ -1,284 +1,282
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 //series
6 //series
7 #include "qbarchartseries.h"
7 #include "qbarchartseries.h"
8 #include "qstackedbarchartseries.h"
8 #include "qstackedbarchartseries.h"
9 #include "qpercentbarchartseries.h"
9 #include "qpercentbarchartseries.h"
10 #include "qlinechartseries.h"
10 #include "qlinechartseries.h"
11 #include "qpieseries.h"
11 #include "qpieseries.h"
12 #include "qscatterseries.h"
12 #include "qscatterseries.h"
13 //items
13 //items
14 #include "axisitem_p.h"
14 #include "axisitem_p.h"
15 #include "axisanimationitem_p.h"
15 #include "axisanimationitem_p.h"
16 #include "barpresenter.h"
16 #include "barpresenter.h"
17 #include "stackedbarpresenter.h"
17 #include "stackedbarpresenter.h"
18 #include "linechartitem_p.h"
18 #include "linechartitem_p.h"
19 #include "percentbarpresenter.h"
19 #include "percentbarpresenter.h"
20 #include "linechartanimationitem_p.h"
20 #include "linechartanimationitem_p.h"
21 #include "piepresenter.h"
21 #include "piepresenter.h"
22 #include "scatterpresenter_p.h"
22 #include "scatterpresenter_p.h"
23
23
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
24 QTCOMMERCIALCHART_BEGIN_NAMESPACE
25
25
26 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
26 ChartPresenter::ChartPresenter(QChart* chart,ChartDataSet* dataset):QObject(chart),
27 m_chart(chart),
27 m_chart(chart),
28 m_dataset(dataset),
28 m_dataset(dataset),
29 m_chartTheme(0),
29 m_chartTheme(0),
30 m_marginSize(0),
30 m_marginSize(0),
31 m_rect(QRectF(QPoint(0,0),m_chart->size())),
31 m_rect(QRectF(QPoint(0,0),m_chart->size())),
32 m_options(0)
32 m_options(0)
33 {
33 {
34 createConnections();
34 createConnections();
35 setChartTheme(QChart::ChartThemeDefault);
35 setChartTheme(QChart::ChartThemeDefault);
36
36
37 }
37 }
38
38
39 ChartPresenter::~ChartPresenter()
39 ChartPresenter::~ChartPresenter()
40 {
40 {
41 }
41 }
42
42
43 void ChartPresenter::createConnections()
43 void ChartPresenter::createConnections()
44 {
44 {
45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
45 QObject::connect(m_chart,SIGNAL(geometryChanged()),this,SLOT(handleGeometryChanged()));
46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
46 QObject::connect(m_dataset,SIGNAL(seriesAdded(QChartSeries*)),this,SLOT(handleSeriesAdded(QChartSeries*)));
47 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*)));
47 QObject::connect(m_dataset,SIGNAL(seriesRemoved(QChartSeries*)),this,SLOT(handleSeriesRemoved(QChartSeries*)));
48 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
48 QObject::connect(m_dataset,SIGNAL(axisAdded(QChartAxis*)),this,SLOT(handleAxisAdded(QChartAxis*)));
49 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
49 QObject::connect(m_dataset,SIGNAL(axisRemoved(QChartAxis*)),this,SLOT(handleAxisRemoved(QChartAxis*)));
50 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&)));
50 QObject::connect(m_dataset,SIGNAL(seriesDomainChanged(QChartSeries*,const Domain&)),this,SLOT(handleSeriesDomainChanged(QChartSeries*,const Domain&)));
51 QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&)));
51 QObject::connect(m_dataset,SIGNAL(axisLabelsChanged(QChartAxis*,const QStringList&)),this,SLOT(handleAxisLabelsChanged(QChartAxis*,const QStringList&)));
52 }
52 }
53
53
54
54
55 QRectF ChartPresenter::geometry() const
55 QRectF ChartPresenter::geometry() const
56 {
56 {
57 return m_rect;
57 return m_rect;
58 }
58 }
59
59
60 void ChartPresenter::handleGeometryChanged()
60 void ChartPresenter::handleGeometryChanged()
61 {
61 {
62 m_rect = QRectF(QPoint(0,0),m_chart->size());
62 m_rect = QRectF(QPoint(0,0),m_chart->size());
63 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
63 m_rect.adjust(m_marginSize,m_marginSize, -m_marginSize, -m_marginSize);
64 Q_ASSERT(m_rect.isValid());
64 Q_ASSERT(m_rect.isValid());
65 emit geometryChanged(m_rect);
65 emit geometryChanged(m_rect);
66 }
66 }
67
67
68 int ChartPresenter::margin() const
68 int ChartPresenter::margin() const
69 {
69 {
70 return m_marginSize;
70 return m_marginSize;
71 }
71 }
72
72
73 void ChartPresenter::setMargin(int margin)
73 void ChartPresenter::setMargin(int margin)
74 {
74 {
75 m_marginSize = margin;
75 m_marginSize = margin;
76 }
76 }
77
77
78 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
78 void ChartPresenter::handleAxisAdded(QChartAxis* axis)
79 {
79 {
80
80
81 AxisItem* item ;
81 AxisItem* item ;
82
82
83 if(!m_options.testFlag(QChart::GridAxisAnimations))
83 if(!m_options.testFlag(QChart::GridAxisAnimations))
84 {
84 {
85 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
85 item = new AxisItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
86 qDebug()<<"kuku1";
87 }else{
86 }else{
88 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
87 item = new AxisAnimationItem(axis==m_dataset->axisX()?AxisItem::X_AXIS : AxisItem::Y_AXIS,m_chart);
89 qDebug()<<"kuku2";
90 }
88 }
91
89
92 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
90 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
93 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
91 QObject::connect(axis,SIGNAL(update(QChartAxis*)),item,SLOT(handleAxisUpdate(QChartAxis*)));
94
92
95 item->handleAxisUpdate(axis);
93 item->handleAxisUpdate(axis);
96 item->handleGeometryChanged(m_rect);
94 item->handleGeometryChanged(m_rect);
97 m_chartTheme->decorate(axis,item);
95 m_chartTheme->decorate(axis,item);
98 m_axisItems.insert(axis,item);
96 m_axisItems.insert(axis,item);
99 }
97 }
100
98
101 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
99 void ChartPresenter::handleAxisRemoved(QChartAxis* axis)
102 {
100 {
103 AxisItem* item = m_axisItems.take(axis);
101 AxisItem* item = m_axisItems.take(axis);
104 Q_ASSERT(item);
102 Q_ASSERT(item);
105 delete item;
103 delete item;
106 }
104 }
107
105
108
106
109 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
107 void ChartPresenter::handleSeriesAdded(QChartSeries* series)
110 {
108 {
111 switch(series->type())
109 switch(series->type())
112 {
110 {
113 case QChartSeries::SeriesTypeLine: {
111 case QChartSeries::SeriesTypeLine: {
114 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
112 QLineChartSeries* lineSeries = static_cast<QLineChartSeries*>(series);
115 LineChartItem* item;
113 LineChartItem* item;
116 if(m_options.testFlag(QChart::SeriesAnimations)){
114 if(m_options.testFlag(QChart::SeriesAnimations)){
117 item = new LineChartAnimationItem(this,lineSeries,m_chart);
115 item = new LineChartAnimationItem(this,lineSeries,m_chart);
118 }else{
116 }else{
119 item = new LineChartItem(this,lineSeries,m_chart);
117 item = new LineChartItem(this,lineSeries,m_chart);
120 }
118 }
121 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
119 m_chartTheme->decorate(item,lineSeries,m_chartItems.count());
122 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
120 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
123 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
121 QObject::connect(lineSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
124 m_chartItems.insert(series,item);
122 m_chartItems.insert(series,item);
125 break;
123 break;
126 }
124 }
127
125
128 case QChartSeries::SeriesTypeBar: {
126 case QChartSeries::SeriesTypeBar: {
129 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
127 QBarChartSeries* barSeries = static_cast<QBarChartSeries*>(series);
130 BarPresenter* item = new BarPresenter(barSeries,m_chart);
128 BarPresenter* item = new BarPresenter(barSeries,m_chart);
131 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
129 m_chartTheme->decorate(item,barSeries,m_chartItems.count());
132 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
130 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
133 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
131 QObject::connect(barSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
134 m_chartItems.insert(series,item);
132 m_chartItems.insert(series,item);
135 // m_axisXItem->setVisible(false);
133 // m_axisXItem->setVisible(false);
136 break;
134 break;
137 }
135 }
138
136
139 case QChartSeries::SeriesTypeStackedBar: {
137 case QChartSeries::SeriesTypeStackedBar: {
140
138
141 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
139 QStackedBarChartSeries* stackedBarSeries = static_cast<QStackedBarChartSeries*>(series);
142 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
140 StackedBarPresenter* item = new StackedBarPresenter(stackedBarSeries,m_chart);
143 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
141 m_chartTheme->decorate(item,stackedBarSeries,m_chartItems.count());
144 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
142 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
145 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
143 QObject::connect(stackedBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
146 m_chartItems.insert(series,item);
144 m_chartItems.insert(series,item);
147 break;
145 break;
148 }
146 }
149
147
150 case QChartSeries::SeriesTypePercentBar: {
148 case QChartSeries::SeriesTypePercentBar: {
151
149
152 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
150 QPercentBarChartSeries* percentBarSeries = static_cast<QPercentBarChartSeries*>(series);
153 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
151 PercentBarPresenter* item = new PercentBarPresenter(percentBarSeries,m_chart);
154 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
152 m_chartTheme->decorate(item,percentBarSeries ,m_chartItems.count());
155 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
153 QObject::connect(this,SIGNAL(geometryChanged(const QRectF&)),item,SLOT(handleGeometryChanged(const QRectF&)));
156 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
154 QObject::connect(percentBarSeries,SIGNAL(changed(int)),item,SLOT(handleModelChanged(int)));
157 m_chartItems.insert(series,item);
155 m_chartItems.insert(series,item);
158 break;
156 break;
159 }
157 }
160 case QChartSeries::SeriesTypeScatter: {
158 case QChartSeries::SeriesTypeScatter: {
161 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
159 QScatterSeries *scatterSeries = qobject_cast<QScatterSeries *>(series);
162 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
160 ScatterPresenter *scatterPresenter = new ScatterPresenter(scatterSeries, m_chart);
163 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
161 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)),
164 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
162 scatterPresenter, SLOT(handleGeometryChanged(const QRectF&)));
165 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
163 m_chartTheme->decorate(scatterPresenter, scatterSeries, m_chartItems.count());
166 m_chartItems.insert(scatterSeries, scatterPresenter);
164 m_chartItems.insert(scatterSeries, scatterPresenter);
167 break;
165 break;
168 }
166 }
169 case QChartSeries::SeriesTypePie: {
167 case QChartSeries::SeriesTypePie: {
170 QPieSeries *s = qobject_cast<QPieSeries *>(series);
168 QPieSeries *s = qobject_cast<QPieSeries *>(series);
171 PiePresenter* pie = new PiePresenter(m_chart, s);
169 PiePresenter* pie = new PiePresenter(m_chart, s);
172 m_chartTheme->decorate(pie, s, m_chartItems.count());
170 m_chartTheme->decorate(pie, s, m_chartItems.count());
173 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
171 QObject::connect(this, SIGNAL(geometryChanged(const QRectF&)), pie, SLOT(handleGeometryChanged(const QRectF&)));
174
172
175 // Hide all from background when there is only piechart
173 // Hide all from background when there is only piechart
176 // TODO: refactor this ugly code... should be one setting for this
174 // TODO: refactor this ugly code... should be one setting for this
177 if (m_chartItems.count() == 0) {
175 if (m_chartItems.count() == 0) {
178 m_chart->axisX()->setAxisVisible(false);
176 m_chart->axisX()->setAxisVisible(false);
179 m_chart->axisY()->setAxisVisible(false);
177 m_chart->axisY()->setAxisVisible(false);
180 m_chart->axisX()->setGridVisible(false);
178 m_chart->axisX()->setGridVisible(false);
181 m_chart->axisY()->setGridVisible(false);
179 m_chart->axisY()->setGridVisible(false);
182 m_chart->axisX()->setLabelsVisible(false);
180 m_chart->axisX()->setLabelsVisible(false);
183 m_chart->axisY()->setLabelsVisible(false);
181 m_chart->axisY()->setLabelsVisible(false);
184 m_chart->axisX()->setShadesVisible(false);
182 m_chart->axisX()->setShadesVisible(false);
185 m_chart->axisY()->setShadesVisible(false);
183 m_chart->axisY()->setShadesVisible(false);
186 m_chart->setChartBackgroundBrush(Qt::transparent);
184 m_chart->setChartBackgroundBrush(Qt::transparent);
187 }
185 }
188
186
189 m_chartItems.insert(series, pie);
187 m_chartItems.insert(series, pie);
190 break;
188 break;
191 }
189 }
192 default: {
190 default: {
193 qDebug()<< "Series type" << series->type() << "not implemented.";
191 qDebug()<< "Series type" << series->type() << "not implemented.";
194 break;
192 break;
195 }
193 }
196 }
194 }
197
195
198 if(m_rect.isValid()) emit geometryChanged(m_rect);
196 if(m_rect.isValid()) emit geometryChanged(m_rect);
199 }
197 }
200
198
201 void ChartPresenter::handleSeriesRemoved(QChartSeries* series)
199 void ChartPresenter::handleSeriesRemoved(QChartSeries* series)
202 {
200 {
203 ChartItem* item = m_chartItems.take(series);
201 ChartItem* item = m_chartItems.take(series);
204 delete item;
202 delete item;
205 }
203 }
206
204
207 void ChartPresenter::handleSeriesChanged(QChartSeries* series)
205 void ChartPresenter::handleSeriesChanged(QChartSeries* series)
208 {
206 {
209 //TODO:
207 //TODO:
210 }
208 }
211
209
212 void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain)
210 void ChartPresenter::handleSeriesDomainChanged(QChartSeries* series, const Domain& domain)
213 {
211 {
214 m_chartItems.value(series)->handleDomainChanged(domain);
212 m_chartItems.value(series)->handleDomainChanged(domain);
215 }
213 }
216
214
217 void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels)
215 void ChartPresenter::handleAxisLabelsChanged(QChartAxis* axis,const QStringList& labels)
218 {
216 {
219 m_axisItems.value(axis)->handleLabelsChanged(axis,labels);
217 m_axisItems.value(axis)->handleLabelsChanged(axis,labels);
220 }
218 }
221
219
222 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
220 void ChartPresenter::setChartTheme(QChart::ChartTheme theme)
223 {
221 {
224 delete m_chartTheme;
222 delete m_chartTheme;
225
223
226 m_chartTheme = ChartTheme::createTheme(theme);
224 m_chartTheme = ChartTheme::createTheme(theme);
227
225
228 m_chartTheme->decorate(m_chart);
226 m_chartTheme->decorate(m_chart);
229 QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
227 QMapIterator<QChartSeries*,ChartItem*> i(m_chartItems);
230
228
231 int index=0;
229 int index=0;
232 while (i.hasNext()) {
230 while (i.hasNext()) {
233 i.next();
231 i.next();
234 index++;
232 index++;
235 m_chartTheme->decorate(i.value(),i.key(),index);
233 m_chartTheme->decorate(i.value(),i.key(),index);
236 }
234 }
237
235
238 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
236 QMapIterator<QChartAxis*,AxisItem*> j(m_axisItems);
239 while (j.hasNext()) {
237 while (j.hasNext()) {
240 j.next();
238 j.next();
241 m_chartTheme->decorate(j.key(),j.value());
239 m_chartTheme->decorate(j.key(),j.value());
242 }
240 }
243 }
241 }
244
242
245 QChart::ChartTheme ChartPresenter::chartTheme()
243 QChart::ChartTheme ChartPresenter::chartTheme()
246 {
244 {
247 return m_chartTheme->id();
245 return m_chartTheme->id();
248 }
246 }
249
247
250 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
248 void ChartPresenter::setAnimationOptions(QChart::AnimationOptions options)
251 {
249 {
252 if(m_options!=options) {
250 if(m_options!=options) {
253
251
254 m_options=options;
252 m_options=options;
255
253
256 //recreate elements
254 //recreate elements
257
255
258 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
256 QList<QChartAxis*> axisList = m_axisItems.uniqueKeys();
259 QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys();
257 QList<QChartSeries*> seriesList = m_chartItems.uniqueKeys();
260
258
261 foreach(QChartAxis* axis, axisList) {
259 foreach(QChartAxis* axis, axisList) {
262 handleAxisRemoved(axis);
260 handleAxisRemoved(axis);
263 handleAxisAdded(axis);
261 handleAxisAdded(axis);
264 }
262 }
265 foreach(QChartSeries* series, seriesList) {
263 foreach(QChartSeries* series, seriesList) {
266 handleSeriesRemoved(series);
264 handleSeriesRemoved(series);
267 handleSeriesAdded(series);
265 handleSeriesAdded(series);
268 }
266 }
269
267
270 //now reintialize view data
268 //now reintialize view data
271 //TODO: make it more nice
269 //TODO: make it more nice
272 m_dataset->setDomain(m_dataset->domainIndex());
270 m_dataset->setDomain(m_dataset->domainIndex());
273 }
271 }
274 }
272 }
275
273
276 QChart::AnimationOptions ChartPresenter::animationOptions() const
274 QChart::AnimationOptions ChartPresenter::animationOptions() const
277 {
275 {
278 return m_options;
276 return m_options;
279 }
277 }
280
278
281
279
282 #include "moc_chartpresenter_p.cpp"
280 #include "moc_chartpresenter_p.cpp"
283
281
284 QTCOMMERCIALCHART_END_NAMESPACE
282 QTCOMMERCIALCHART_END_NAMESPACE
General Comments 0
You need to be logged in to leave comments. Login now