@@ -1,447 +1,464 | |||||
1 | /**************************************************************************** |
|
1 | /**************************************************************************** | |
2 | ** |
|
2 | ** | |
3 | ** Copyright (C) 2012 Digia Plc |
|
3 | ** Copyright (C) 2012 Digia Plc | |
4 | ** All rights reserved. |
|
4 | ** All rights reserved. | |
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
5 | ** For any questions to Digia, please use contact form at http://qt.digia.com | |
6 | ** |
|
6 | ** | |
7 | ** This file is part of the Qt Commercial Charts Add-on. |
|
7 | ** This file is part of the Qt Commercial Charts Add-on. | |
8 | ** |
|
8 | ** | |
9 | ** $QT_BEGIN_LICENSE$ |
|
9 | ** $QT_BEGIN_LICENSE$ | |
10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
10 | ** Licensees holding valid Qt Commercial licenses may use this file in | |
11 | ** accordance with the Qt Commercial License Agreement provided with the |
|
11 | ** accordance with the Qt Commercial License Agreement provided with the | |
12 | ** Software or, alternatively, in accordance with the terms contained in |
|
12 | ** Software or, alternatively, in accordance with the terms contained in | |
13 | ** a written agreement between you and Digia. |
|
13 | ** a written agreement between you and Digia. | |
14 | ** |
|
14 | ** | |
15 | ** If you have questions regarding the use of this file, please use |
|
15 | ** If you have questions regarding the use of this file, please use | |
16 | ** contact form at http://qt.digia.com |
|
16 | ** contact form at http://qt.digia.com | |
17 | ** $QT_END_LICENSE$ |
|
17 | ** $QT_END_LICENSE$ | |
18 | ** |
|
18 | ** | |
19 | ****************************************************************************/ |
|
19 | ****************************************************************************/ | |
20 |
|
20 | |||
21 | #include "chartdataset_p.h" |
|
21 | #include "chartdataset_p.h" | |
22 | #include "qchart.h" |
|
22 | #include "qchart.h" | |
23 | #include "qvaluesaxis.h" |
|
23 | #include "qvaluesaxis.h" | |
24 | #include "qbarcategoriesaxis.h" |
|
24 | #include "qbarcategoriesaxis.h" | |
25 | #include "qvaluesaxis_p.h" |
|
25 | #include "qvaluesaxis_p.h" | |
26 | #include "qabstractseries_p.h" |
|
26 | #include "qabstractseries_p.h" | |
27 | #include "qabstractbarseries.h" |
|
27 | #include "qabstractbarseries.h" | |
28 | #include "qstackedbarseries.h" |
|
28 | #include "qstackedbarseries.h" | |
29 | #include "qpercentbarseries.h" |
|
29 | #include "qpercentbarseries.h" | |
30 | #include "qpieseries.h" |
|
30 | #include "qpieseries.h" | |
31 |
|
31 | |||
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
32 | QTCOMMERCIALCHART_BEGIN_NAMESPACE | |
33 |
|
33 | |||
34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), |
|
34 | ChartDataSet::ChartDataSet(QChart *parent):QObject(parent), | |
35 | m_domainIndex(0) |
|
35 | m_domainIndex(0) | |
36 | { |
|
36 | { | |
37 |
|
37 | |||
38 | } |
|
38 | } | |
39 |
|
39 | |||
40 | ChartDataSet::~ChartDataSet() |
|
40 | ChartDataSet::~ChartDataSet() | |
41 | { |
|
41 | { | |
42 | removeAllSeries(); |
|
42 | removeAllSeries(); | |
43 | } |
|
43 | } | |
44 |
|
44 | |||
45 | void ChartDataSet::addSeries(QAbstractSeries* series) |
|
45 | void ChartDataSet::addSeries(QAbstractSeries* series) | |
46 | { |
|
46 | { | |
47 | Domain* domain = m_seriesDomainMap.value(series); |
|
47 | Domain* domain = m_seriesDomainMap.value(series); | |
48 |
|
48 | |||
49 | if(domain) { |
|
49 | if(domain) { | |
50 | qWarning() << "Can not add series. Series already on the chart"; |
|
50 | qWarning() << "Can not add series. Series already on the chart"; | |
51 | return; |
|
51 | return; | |
52 | } |
|
52 | } | |
53 |
|
53 | |||
54 | series->setParent(this); // take ownership |
|
54 | series->setParent(this); // take ownership | |
55 |
|
55 | |||
56 | domain = new Domain(series); |
|
56 | domain = new Domain(series); | |
57 |
|
57 | |||
58 | m_seriesDomainMap.insert(series,domain); |
|
58 | m_seriesDomainMap.insert(series,domain); | |
59 |
|
59 | |||
60 | series->d_ptr->scaleDomain(*domain); |
|
60 | series->d_ptr->scaleDomain(*domain); | |
61 |
|
61 | |||
62 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
62 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
63 |
|
63 | |||
64 | int key=0; |
|
64 | int key=0; | |
65 | while (i.hasNext()) { |
|
65 | while (i.hasNext()) { | |
66 | i.next(); |
|
66 | i.next(); | |
67 | if(i.key()!=key) { |
|
67 | if(i.key()!=key) { | |
68 | break; |
|
68 | break; | |
69 | } |
|
69 | } | |
70 | key++; |
|
70 | key++; | |
71 | } |
|
71 | } | |
72 |
|
72 | |||
73 | m_indexSeriesMap.insert(key,series); |
|
73 | m_indexSeriesMap.insert(key,series); | |
74 |
|
74 | |||
75 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); |
|
75 | series->d_ptr->m_chart = qobject_cast<QChart*>(parent()); | |
76 | series->d_ptr->m_dataset = this; |
|
76 | series->d_ptr->m_dataset = this; | |
77 |
|
77 | |||
78 | emit seriesAdded(series,domain); |
|
78 | emit seriesAdded(series,domain); | |
79 |
|
79 | |||
80 | } |
|
80 | } | |
81 |
|
81 | |||
82 | void ChartDataSet::createDefaultAxes() |
|
82 | void ChartDataSet::createDefaultAxes() | |
83 | { |
|
83 | { | |
84 |
|
84 | |||
85 | if(m_seriesDomainMap.isEmpty()) return; |
|
85 | if(m_seriesDomainMap.isEmpty()) return; | |
86 |
|
86 | |||
87 | QAbstractAxis::AxisTypes typeX(0); |
|
87 | QAbstractAxis::AxisTypes typeX(0); | |
88 | QAbstractAxis::AxisTypes typeY(0); |
|
88 | QAbstractAxis::AxisTypes typeY(0); | |
89 |
|
89 | |||
90 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
90 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
91 | while (i.hasNext()) { |
|
91 | while (i.hasNext()) { | |
92 | i.next(); |
|
92 | i.next(); | |
93 | removeAxes(i.key()); |
|
93 | removeAxes(i.key()); | |
94 | } |
|
94 | } | |
95 |
|
95 | |||
96 | i.toFront(); |
|
96 | i.toFront(); | |
97 |
|
97 | |||
98 | while (i.hasNext()) { |
|
98 | while (i.hasNext()) { | |
99 | i.next(); |
|
99 | i.next(); | |
100 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
100 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
101 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
101 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
102 | if(axisX) typeX&=axisX->type(); |
|
102 | if(axisX) typeX&=axisX->type(); | |
103 | else typeX|=i.key()->d_ptr->defaultAxisXType(); |
|
103 | else typeX|=i.key()->d_ptr->defaultAxisXType(); | |
104 | if(axisY) typeY&=axisY->type(); |
|
104 | if(axisY) typeY&=axisY->type(); | |
105 | else typeY|=i.key()->d_ptr->defaultAxisYType(); |
|
105 | else typeY|=i.key()->d_ptr->defaultAxisYType(); | |
106 | } |
|
106 | } | |
107 |
|
107 | |||
108 |
|
108 | |||
109 | if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
109 | if(typeX.testFlag(QAbstractAxis::AxisTypeValues) && typeX.testFlag(QAbstractAxis::AxisTypeCategories)) | |
110 | { |
|
110 | { | |
111 | i.toFront(); |
|
111 | i.toFront(); | |
112 | while (i.hasNext()) { |
|
112 | while (i.hasNext()) { | |
113 | i.next(); |
|
113 | i.next(); | |
114 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType()); |
|
114 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisXType()); | |
115 | if(!axis) continue; |
|
115 | if(!axis) continue; | |
116 | i.key()->d_ptr->initializeAxisX(axis); |
|
116 | i.key()->d_ptr->initializeAxisX(axis); | |
117 | addAxisX(axis,i.key()); |
|
117 | addAxisX(axis,i.key()); | |
118 | emit axisAdded(axis,i.value()); |
|
118 | emit axisAdded(axis,i.value()); | |
119 | } |
|
119 | } | |
120 |
|
120 | |||
121 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ |
|
121 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |
122 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX))); |
|
122 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeX))); | |
123 | i.toFront(); |
|
123 | i.toFront(); | |
124 | while (i.hasNext()) { |
|
124 | while (i.hasNext()) { | |
125 | i.next(); |
|
125 | i.next(); | |
126 | i.key()->d_ptr->initializeAxisX(axis); |
|
126 | i.key()->d_ptr->initializeAxisX(axis); | |
127 | addAxisX(axis,i.key()); |
|
127 | addAxisX(axis,i.key()); | |
128 | } |
|
128 | } | |
129 | emit axisAdded(axis,i.value()); |
|
129 | emit axisAdded(axis,i.value()); | |
130 |
|
130 | |||
131 | } |
|
131 | } | |
132 |
|
132 | |||
133 | if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories)) |
|
133 | if(typeY.testFlag(QAbstractAxis::AxisTypeValues) && typeY.testFlag(QAbstractAxis::AxisTypeCategories)) | |
134 | { |
|
134 | { | |
135 | i.toFront(); |
|
135 | i.toFront(); | |
136 | while (i.hasNext()) { |
|
136 | while (i.hasNext()) { | |
137 | i.next(); |
|
137 | i.next(); | |
138 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType()); |
|
138 | QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisYType()); | |
139 | i.key()->d_ptr->initializeAxisY(axis); |
|
139 | i.key()->d_ptr->initializeAxisY(axis); | |
140 | addAxisY(axis,i.key()); |
|
140 | addAxisY(axis,i.key()); | |
141 | emit axisAdded(axis,i.value()); |
|
141 | emit axisAdded(axis,i.value()); | |
142 | } |
|
142 | } | |
143 |
|
143 | |||
144 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ |
|
144 | }else if(!typeY.testFlag(QAbstractAxis::AxisTypeNoAxis)){ | |
145 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY))); |
|
145 | QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(typeY))); | |
146 | i.toFront(); |
|
146 | i.toFront(); | |
147 | while (i.hasNext()) { |
|
147 | while (i.hasNext()) { | |
148 | i.next(); |
|
148 | i.next(); | |
149 | i.key()->d_ptr->initializeAxisY(axis); |
|
149 | i.key()->d_ptr->initializeAxisY(axis); | |
150 | addAxisY(axis,i.key()); |
|
150 | addAxisY(axis,i.key()); | |
151 | } |
|
151 | } | |
152 | emit axisAdded(axis,i.value()); |
|
152 | emit axisAdded(axis,i.value()); | |
153 |
|
153 | |||
154 | } |
|
154 | } | |
155 | } |
|
155 | } | |
156 |
|
156 | |||
157 |
|
157 | |||
158 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type) |
|
158 | QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type) | |
159 | { |
|
159 | { | |
160 | QAbstractAxis* axis =0; |
|
160 | QAbstractAxis* axis =0; | |
161 |
|
161 | |||
162 | switch(type) { |
|
162 | switch(type) { | |
163 | case QAbstractAxis::AxisTypeValues: |
|
163 | case QAbstractAxis::AxisTypeValues: | |
164 | axis = new QValuesAxis(this); |
|
164 | axis = new QValuesAxis(this); | |
165 | break; |
|
165 | break; | |
166 | case QAbstractAxis::AxisTypeCategories: |
|
166 | case QAbstractAxis::AxisTypeCategories: | |
167 | axis = new QBarCategoriesAxis(this); |
|
167 | axis = new QBarCategoriesAxis(this); | |
168 | break; |
|
168 | break; | |
169 | default: |
|
169 | default: | |
170 | axis = 0; |
|
170 | axis = 0; | |
171 | break; |
|
171 | break; | |
172 | } |
|
172 | } | |
173 |
|
173 | |||
174 | return axis; |
|
174 | return axis; | |
175 | } |
|
175 | } | |
176 |
|
176 | |||
177 | void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) { |
|
177 | void ChartDataSet::addAxisX(QAbstractAxis* axis,QAbstractSeries* series) { | |
178 | Domain* domain = m_seriesDomainMap.value(series); |
|
178 | Domain* domain = m_seriesDomainMap.value(series); | |
179 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
179 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
180 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
180 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
181 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
181 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
182 | m_seriesAxisXMap.insert(series,axis); |
|
182 | m_seriesAxisXMap.insert(series,axis); | |
183 | } |
|
183 | } | |
184 |
|
184 | |||
185 | void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) { |
|
185 | void ChartDataSet::addAxisY(QAbstractAxis* axis,QAbstractSeries* series) { | |
186 | Domain* domain = m_seriesDomainMap.value(series); |
|
186 | Domain* domain = m_seriesDomainMap.value(series); | |
187 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
187 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
188 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
188 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
189 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
189 | axis->d_ptr->m_orientation=Qt::Vertical; | |
190 | m_seriesAxisYMap.insert(series,axis); |
|
190 | m_seriesAxisYMap.insert(series,axis); | |
191 | } |
|
191 | } | |
192 |
|
192 | |||
193 | void ChartDataSet::removeSeries(QAbstractSeries* series) |
|
193 | void ChartDataSet::removeSeries(QAbstractSeries* series) | |
194 | { |
|
194 | { | |
195 | Domain* domain = m_seriesDomainMap.take(series); |
|
195 | Domain* domain = m_seriesDomainMap.take(series); | |
196 |
|
196 | |||
197 | if(!domain) { |
|
197 | if(!domain) { | |
198 | qWarning()<<"Can not remove series. Series not found on the chart."; |
|
198 | qWarning()<<"Can not remove series. Series not found on the chart."; | |
199 | } |
|
199 | } | |
200 |
|
200 | |||
201 | emit seriesRemoved(series); |
|
201 | emit seriesRemoved(series); | |
202 |
|
202 | |||
203 | delete domain; |
|
203 | delete domain; | |
204 | domain = 0; |
|
204 | domain = 0; | |
205 |
|
205 | |||
206 | int key = seriesIndex(series); |
|
206 | int key = seriesIndex(series); | |
207 | Q_ASSERT(key!=-1); |
|
207 | Q_ASSERT(key!=-1); | |
208 |
|
208 | |||
209 | m_indexSeriesMap.remove(key); |
|
209 | m_indexSeriesMap.remove(key); | |
210 |
|
210 | |||
211 | series->setParent(0); |
|
211 | series->setParent(0); | |
212 | series->d_ptr->m_chart = 0; |
|
212 | series->d_ptr->m_chart = 0; | |
213 | series->d_ptr->m_dataset = 0; |
|
213 | series->d_ptr->m_dataset = 0; | |
214 |
|
214 | |||
215 | removeAxes(series); |
|
215 | removeAxes(series); | |
216 | } |
|
216 | } | |
217 |
|
217 | |||
218 | void ChartDataSet::removeAxes(QAbstractSeries* series) |
|
218 | void ChartDataSet::removeAxes(QAbstractSeries* series) | |
219 | { |
|
219 | { | |
220 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); |
|
220 | QAbstractAxis* axisX = m_seriesAxisXMap.take(series); | |
221 |
|
221 | |||
222 | if(axisX) { |
|
222 | if(axisX) { | |
223 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
223 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
224 | int x = axesX.indexOf(axisX); |
|
224 | int x = axesX.indexOf(axisX); | |
225 |
|
225 | |||
226 | if(x==-1) { |
|
226 | if(x==-1) { | |
227 | emit axisRemoved(axisX); |
|
227 | emit axisRemoved(axisX); | |
228 | axisX->deleteLater(); |
|
228 | axisX->deleteLater(); | |
229 | } |
|
229 | } | |
230 | } |
|
230 | } | |
231 |
|
231 | |||
232 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); |
|
232 | QAbstractAxis* axisY = m_seriesAxisYMap.take(series); | |
233 |
|
233 | |||
234 | if(axisY) { |
|
234 | if(axisY) { | |
235 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
235 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
236 |
|
236 | |||
237 | int y = axesY.indexOf(axisY); |
|
237 | int y = axesY.indexOf(axisY); | |
238 |
|
238 | |||
239 | if(y==-1) { |
|
239 | if(y==-1) { | |
240 | emit axisRemoved(axisY); |
|
240 | emit axisRemoved(axisY); | |
241 | axisY->deleteLater(); |
|
241 | axisY->deleteLater(); | |
242 | } |
|
242 | } | |
243 | } |
|
243 | } | |
244 | } |
|
244 | } | |
245 |
|
245 | |||
246 | void ChartDataSet::removeAllSeries() |
|
246 | void ChartDataSet::removeAllSeries() | |
247 | { |
|
247 | { | |
248 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); |
|
248 | QList<QAbstractSeries*> series = m_seriesDomainMap.keys(); | |
249 | foreach(QAbstractSeries *s , series) { |
|
249 | foreach(QAbstractSeries *s , series) { | |
250 | removeSeries(s); |
|
250 | removeSeries(s); | |
251 | } |
|
251 | } | |
252 |
|
252 | |||
253 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
253 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
254 | Q_ASSERT(m_seriesAxisXMap.count()==0); |
|
254 | Q_ASSERT(m_seriesAxisXMap.count()==0); | |
255 | Q_ASSERT(m_seriesDomainMap.count()==0); |
|
255 | Q_ASSERT(m_seriesDomainMap.count()==0); | |
256 |
|
256 | |||
257 | qDeleteAll(series); |
|
257 | qDeleteAll(series); | |
258 | } |
|
258 | } | |
259 |
|
259 | |||
260 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) |
|
260 | void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size) | |
261 | { |
|
261 | { | |
262 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
262 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
263 |
|
263 | |||
264 | blockAxisSignals(true); |
|
264 | blockAxisSignals(true); | |
265 |
|
265 | |||
266 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
266 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
267 |
|
267 | |||
268 | while (i.hasNext()) { |
|
268 | while (i.hasNext()) { | |
269 | i.next(); |
|
269 | i.next(); | |
270 | i.value()->zoomIn(rect,size); |
|
270 | i.value()->zoomIn(rect,size); | |
271 | } |
|
271 | } | |
272 |
|
272 | |||
273 | blockAxisSignals(false); |
|
273 | blockAxisSignals(false); | |
274 |
|
274 | |||
275 | } |
|
275 | } | |
276 |
|
276 | |||
277 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) |
|
277 | void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size) | |
278 | { |
|
278 | { | |
279 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates |
|
279 | //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates | |
280 |
|
280 | |||
281 | blockAxisSignals(true); |
|
281 | blockAxisSignals(true); | |
282 |
|
282 | |||
283 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
283 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
284 |
|
284 | |||
285 | while (i.hasNext()) { |
|
285 | while (i.hasNext()) { | |
286 | i.next(); |
|
286 | i.next(); | |
287 | i.value()->zoomOut(rect,size); |
|
287 | i.value()->zoomOut(rect,size); | |
288 | } |
|
288 | } | |
289 |
|
289 | |||
290 | blockAxisSignals(false); |
|
290 | blockAxisSignals(false); | |
291 | } |
|
291 | } | |
292 |
|
292 | |||
293 | void ChartDataSet::blockAxisSignals(bool enabled) |
|
293 | void ChartDataSet::blockAxisSignals(bool enabled) | |
294 | { |
|
294 | { | |
295 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
295 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
296 |
|
296 | |||
297 | while (i.hasNext()) { |
|
297 | while (i.hasNext()) { | |
298 | i.next(); |
|
298 | i.next(); | |
299 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); |
|
299 | QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key()); | |
300 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); |
|
300 | QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key()); | |
301 | if(axisX) axisX->blockSignals(enabled); |
|
301 | if(axisX) axisX->blockSignals(enabled); | |
302 | if(axisY) axisY->blockSignals(enabled); |
|
302 | if(axisY) axisY->blockSignals(enabled); | |
303 | } |
|
303 | } | |
304 | } |
|
304 | } | |
305 |
|
305 | |||
306 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) |
|
306 | int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type) | |
307 | { |
|
307 | { | |
308 | int count=0; |
|
308 | int count=0; | |
309 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
309 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
310 | while (i.hasNext()) { |
|
310 | while (i.hasNext()) { | |
311 | i.next(); |
|
311 | i.next(); | |
312 | if(i.key()->type()==type) count++; |
|
312 | if(i.key()->type()==type) count++; | |
313 | } |
|
313 | } | |
314 | return count; |
|
314 | return count; | |
315 | } |
|
315 | } | |
316 |
|
316 | |||
317 | int ChartDataSet::seriesIndex(QAbstractSeries *series) |
|
317 | int ChartDataSet::seriesIndex(QAbstractSeries *series) | |
318 | { |
|
318 | { | |
319 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); |
|
319 | QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap); | |
320 | while (i.hasNext()) { |
|
320 | while (i.hasNext()) { | |
321 | i.next(); |
|
321 | i.next(); | |
322 | if (i.value() == series) |
|
322 | if (i.value() == series) | |
323 | return i.key(); |
|
323 | return i.key(); | |
324 | } |
|
324 | } | |
325 | return -1; |
|
325 | return -1; | |
326 | } |
|
326 | } | |
327 |
|
327 | |||
328 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const |
|
328 | QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const | |
329 | { |
|
329 | { | |
330 | if(series == 0) return m_seriesAxisXMap.begin().value(); |
|
330 | if(series == 0) { | |
|
331 | ||||
|
332 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap); | |||
|
333 | ||||
|
334 | while (i.hasNext()) { | |||
|
335 | i.next(); | |||
|
336 | if(i.value()->isVisible()) return i.value(); | |||
|
337 | } | |||
|
338 | return 0; | |||
|
339 | } | |||
331 | return m_seriesAxisXMap.value(series); |
|
340 | return m_seriesAxisXMap.value(series); | |
332 | } |
|
341 | } | |
333 |
|
342 | |||
334 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const |
|
343 | QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const | |
335 | { |
|
344 | { | |
336 | if(series == 0) return m_seriesAxisYMap.begin().value(); |
|
345 | if(series == 0) { | |
|
346 | QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap); | |||
|
347 | ||||
|
348 | while (i.hasNext()) { | |||
|
349 | i.next(); | |||
|
350 | if(i.value()->isVisible()) return i.value(); | |||
|
351 | } | |||
|
352 | return 0; | |||
|
353 | } | |||
337 | return m_seriesAxisYMap.value(series); |
|
354 | return m_seriesAxisYMap.value(series); | |
338 | } |
|
355 | } | |
339 |
|
356 | |||
340 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) |
|
357 | void ChartDataSet::setAxisX(QAbstractSeries *series, QAbstractAxis *axis) | |
341 | { |
|
358 | { | |
342 | Q_ASSERT(axis); |
|
359 | Q_ASSERT(axis); | |
343 | Domain* domain = m_seriesDomainMap.value(series); |
|
360 | Domain* domain = m_seriesDomainMap.value(series); | |
344 |
|
361 | |||
345 | if(!domain) { |
|
362 | if(!domain) { | |
346 | qWarning() << "Series not found on the chart."; |
|
363 | qWarning() << "Series not found on the chart."; | |
347 | return; |
|
364 | return; | |
348 | } |
|
365 | } | |
349 |
|
366 | |||
350 | if(axis->d_ptr->m_orientation==Qt::Vertical) { |
|
367 | if(axis->d_ptr->m_orientation==Qt::Vertical) { | |
351 | qWarning()<<"Axis already defined as axis Y"; |
|
368 | qWarning()<<"Axis already defined as axis Y"; | |
352 | return; |
|
369 | return; | |
353 | } |
|
370 | } | |
354 |
|
371 | |||
355 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); |
|
372 | QAbstractAxis *oldAxis = m_seriesAxisXMap.take(series); | |
356 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); |
|
373 | QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values(); | |
357 |
|
374 | |||
358 | if(oldAxis) { |
|
375 | if(oldAxis) { | |
359 |
|
376 | |||
360 | int x = axesX.indexOf(oldAxis); |
|
377 | int x = axesX.indexOf(oldAxis); | |
361 | if(x==-1) { |
|
378 | if(x==-1) { | |
362 | emit axisRemoved(oldAxis); |
|
379 | emit axisRemoved(oldAxis); | |
363 | oldAxis->deleteLater(); |
|
380 | oldAxis->deleteLater(); | |
364 | } |
|
381 | } | |
365 | } |
|
382 | } | |
366 |
|
383 | |||
367 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); |
|
384 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisXChanged(qreal,qreal,int,bool))); | |
368 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
385 | QObject::connect(domain,SIGNAL(rangeXChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
369 |
|
386 | |||
370 | int x = axesX.indexOf(axis); |
|
387 | int x = axesX.indexOf(axis); | |
371 | if(x==-1) { |
|
388 | if(x==-1) { | |
372 | axis->d_ptr->m_orientation=Qt::Horizontal; |
|
389 | axis->d_ptr->m_orientation=Qt::Horizontal; | |
373 | emit axisAdded(axis,domain); |
|
390 | emit axisAdded(axis,domain); | |
374 | } |
|
391 | } | |
375 |
|
392 | |||
376 | m_seriesAxisXMap.insert(series,axis); |
|
393 | m_seriesAxisXMap.insert(series,axis); | |
377 | axis->d_ptr->emitRange(); |
|
394 | axis->d_ptr->emitRange(); | |
378 | } |
|
395 | } | |
379 |
|
396 | |||
380 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) |
|
397 | void ChartDataSet::setAxisY(QAbstractSeries *series, QAbstractAxis *axis) | |
381 | { |
|
398 | { | |
382 | Q_ASSERT(axis); |
|
399 | Q_ASSERT(axis); | |
383 | Domain* domain = m_seriesDomainMap.value(series); |
|
400 | Domain* domain = m_seriesDomainMap.value(series); | |
384 |
|
401 | |||
385 | if(!domain) { |
|
402 | if(!domain) { | |
386 | qWarning() << "Series not found on the chart."; |
|
403 | qWarning() << "Series not found on the chart."; | |
387 | return; |
|
404 | return; | |
388 | } |
|
405 | } | |
389 |
|
406 | |||
390 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { |
|
407 | if(axis->d_ptr->m_orientation==Qt::Horizontal) { | |
391 | qWarning()<<"Axis already defined as axis X"; |
|
408 | qWarning()<<"Axis already defined as axis X"; | |
392 | return; |
|
409 | return; | |
393 | } |
|
410 | } | |
394 |
|
411 | |||
395 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); |
|
412 | QAbstractAxis *oldAxis = m_seriesAxisYMap.take(series); | |
396 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); |
|
413 | QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values(); | |
397 |
|
414 | |||
398 | if(oldAxis) { |
|
415 | if(oldAxis) { | |
399 | int y = axesY.indexOf(oldAxis); |
|
416 | int y = axesY.indexOf(oldAxis); | |
400 | if(y==-1) { |
|
417 | if(y==-1) { | |
401 | emit axisRemoved(oldAxis); |
|
418 | emit axisRemoved(oldAxis); | |
402 | oldAxis->deleteLater(); |
|
419 | oldAxis->deleteLater(); | |
403 | } |
|
420 | } | |
404 | } |
|
421 | } | |
405 |
|
422 | |||
406 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); |
|
423 | QObject::connect(axis->d_ptr.data(),SIGNAL(changed(qreal,qreal,int,bool)),domain,SLOT(handleAxisYChanged(qreal,qreal,int,bool))); | |
407 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); |
|
424 | QObject::connect(domain,SIGNAL(rangeYChanged(qreal,qreal,int)),axis->d_ptr.data(),SLOT(handleAxisRangeChanged(qreal,qreal,int))); | |
408 |
|
425 | |||
409 | int y = axesY.indexOf(axis); |
|
426 | int y = axesY.indexOf(axis); | |
410 | if(y==-1) { |
|
427 | if(y==-1) { | |
411 | axis->d_ptr->m_orientation=Qt::Vertical; |
|
428 | axis->d_ptr->m_orientation=Qt::Vertical; | |
412 | emit axisAdded(axis,domain); |
|
429 | emit axisAdded(axis,domain); | |
413 | } |
|
430 | } | |
414 |
|
431 | |||
415 | m_seriesAxisYMap.insert(series,axis); |
|
432 | m_seriesAxisYMap.insert(series,axis); | |
416 | axis->d_ptr->emitRange(); |
|
433 | axis->d_ptr->emitRange(); | |
417 | } |
|
434 | } | |
418 |
|
435 | |||
419 | Domain* ChartDataSet::domain(QAbstractSeries *series) const |
|
436 | Domain* ChartDataSet::domain(QAbstractSeries *series) const | |
420 | { |
|
437 | { | |
421 | return m_seriesDomainMap.value(series); |
|
438 | return m_seriesDomainMap.value(series); | |
422 | } |
|
439 | } | |
423 |
|
440 | |||
424 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) |
|
441 | void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size) | |
425 | { |
|
442 | { | |
426 | blockAxisSignals(true); |
|
443 | blockAxisSignals(true); | |
427 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); |
|
444 | QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap); | |
428 | while (i.hasNext()) { |
|
445 | while (i.hasNext()) { | |
429 | i.next(); |
|
446 | i.next(); | |
430 | i.value()->move(dx,dy,size); |
|
447 | i.value()->move(dx,dy,size); | |
431 | } |
|
448 | } | |
432 | blockAxisSignals(false); |
|
449 | blockAxisSignals(false); | |
433 | } |
|
450 | } | |
434 |
|
451 | |||
435 | QList<QAbstractSeries*> ChartDataSet::series() const |
|
452 | QList<QAbstractSeries*> ChartDataSet::series() const | |
436 | { |
|
453 | { | |
437 | return m_seriesAxisXMap.keys(); |
|
454 | return m_seriesAxisXMap.keys(); | |
438 | } |
|
455 | } | |
439 |
|
456 | |||
440 | void ChartDataSet::updateSeries(QAbstractSeries *series) |
|
457 | void ChartDataSet::updateSeries(QAbstractSeries *series) | |
441 | { |
|
458 | { | |
442 | emit seriesUpdated(series); |
|
459 | emit seriesUpdated(series); | |
443 | } |
|
460 | } | |
444 |
|
461 | |||
445 | #include "moc_chartdataset_p.cpp" |
|
462 | #include "moc_chartdataset_p.cpp" | |
446 |
|
463 | |||
447 | QTCOMMERCIALCHART_END_NAMESPACE |
|
464 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now