@@ -1,637 +1,639 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2013 Digia Plc |
|
4 | 4 | ** All rights reserved. |
|
5 | 5 | ** For any questions to Digia, please use contact form at http://qt.digia.com |
|
6 | 6 | ** |
|
7 | 7 | ** This file is part of the Qt Enterprise Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Enterprise licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Enterprise License Agreement provided with the |
|
12 | 12 | ** Software or, alternatively, in accordance with the terms contained in |
|
13 | 13 | ** a written agreement between you and Digia. |
|
14 | 14 | ** |
|
15 | 15 | ** If you have questions regarding the use of this file, please use |
|
16 | 16 | ** contact form at http://qt.digia.com |
|
17 | 17 | ** $QT_END_LICENSE$ |
|
18 | 18 | ** |
|
19 | 19 | ****************************************************************************/ |
|
20 | 20 | |
|
21 | 21 | #include "chartdataset_p.h" |
|
22 | 22 | #include "chartpresenter_p.h" |
|
23 | 23 | #include "qchart.h" |
|
24 | 24 | #include "qchart_p.h" |
|
25 | 25 | #include "qvalueaxis.h" |
|
26 | 26 | #include "qbarcategoryaxis.h" |
|
27 | 27 | #include "qvalueaxis_p.h" |
|
28 | 28 | #include "qcategoryaxis.h" |
|
29 | 29 | #include "qabstractseries_p.h" |
|
30 | 30 | #include "qabstractbarseries.h" |
|
31 | 31 | #include "qstackedbarseries.h" |
|
32 | 32 | #include "qpercentbarseries.h" |
|
33 | 33 | #include "qpieseries.h" |
|
34 | 34 | #include "chartitem_p.h" |
|
35 | 35 | #include "xydomain_p.h" |
|
36 | 36 | #include "xypolardomain_p.h" |
|
37 | 37 | #include "xlogydomain_p.h" |
|
38 | 38 | #include "logxydomain_p.h" |
|
39 | 39 | #include "logxlogydomain_p.h" |
|
40 | 40 | #include "xlogypolardomain_p.h" |
|
41 | 41 | #include "logxypolardomain_p.h" |
|
42 | 42 | #include "logxlogypolardomain_p.h" |
|
43 | 43 | |
|
44 | 44 | #ifndef QT_ON_ARM |
|
45 | 45 | #include "qdatetimeaxis.h" |
|
46 | 46 | #endif |
|
47 | 47 | |
|
48 | 48 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
49 | 49 | |
|
50 | 50 | ChartDataSet::ChartDataSet(QChart *chart) |
|
51 | 51 | : QObject(chart), |
|
52 | 52 | m_chart(chart) |
|
53 | 53 | { |
|
54 | 54 | |
|
55 | 55 | } |
|
56 | 56 | |
|
57 | 57 | ChartDataSet::~ChartDataSet() |
|
58 | 58 | { |
|
59 | 59 | deleteAllSeries(); |
|
60 | 60 | deleteAllAxes(); |
|
61 | 61 | } |
|
62 | 62 | |
|
63 | 63 | /* |
|
64 | 64 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
65 | 65 | */ |
|
66 | 66 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
67 | 67 | { |
|
68 | 68 | if (m_seriesList.contains(series)) { |
|
69 | 69 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
70 | 70 | return; |
|
71 | 71 | } |
|
72 | 72 | |
|
73 | 73 | // Ignore unsupported series added to polar chart |
|
74 | 74 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) { |
|
75 | 75 | if (!(series->type() == QAbstractSeries::SeriesTypeArea |
|
76 | 76 | || series->type() == QAbstractSeries::SeriesTypeLine |
|
77 | 77 | || series->type() == QAbstractSeries::SeriesTypeScatter |
|
78 | 78 | || series->type() == QAbstractSeries::SeriesTypeSpline)) { |
|
79 | 79 | qWarning() << QObject::tr("Can not add series. Series type is not supported by a polar chart."); |
|
80 | 80 | return; |
|
81 | 81 | } |
|
82 | 82 | series->d_ptr->setDomain(new XYPolarDomain()); |
|
83 | 83 | } else { |
|
84 | 84 | series->d_ptr->setDomain(new XYDomain()); |
|
85 | 85 | } |
|
86 | 86 | |
|
87 | 87 | series->d_ptr->initializeDomain(); |
|
88 | 88 | m_seriesList.append(series); |
|
89 | 89 | |
|
90 | 90 | series->setParent(this); // take ownership |
|
91 | 91 | series->d_ptr->m_chart = m_chart; |
|
92 | 92 | |
|
93 | 93 | emit seriesAdded(series); |
|
94 | 94 | } |
|
95 | 95 | |
|
96 | 96 | /* |
|
97 | 97 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
98 | 98 | */ |
|
99 | 99 | void ChartDataSet::addAxis(QAbstractAxis *axis, Qt::Alignment aligment) |
|
100 | 100 | { |
|
101 | 101 | if (m_axisList.contains(axis)) { |
|
102 | 102 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
103 | 103 | return; |
|
104 | 104 | } |
|
105 | 105 | |
|
106 | 106 | axis->d_ptr->setAlignment(aligment); |
|
107 | 107 | |
|
108 | 108 | if (!axis->alignment()) { |
|
109 | 109 | qWarning() << QObject::tr("No alignment specified !"); |
|
110 | 110 | return; |
|
111 | 111 | }; |
|
112 | 112 | |
|
113 | 113 | AbstractDomain *newDomain; |
|
114 | 114 | if (m_chart && m_chart->chartType() == QChart::ChartTypePolar) |
|
115 | 115 | newDomain = new XYPolarDomain(); |
|
116 | 116 | else |
|
117 | 117 | newDomain = new XYDomain(); |
|
118 | 118 | |
|
119 | 119 | QSharedPointer<AbstractDomain> domain(newDomain); |
|
120 | 120 | axis->d_ptr->initializeDomain(domain.data()); |
|
121 | 121 | |
|
122 | 122 | axis->setParent(this); |
|
123 | 123 | axis->d_ptr->m_chart = m_chart; |
|
124 | 124 | m_axisList.append(axis); |
|
125 | 125 | |
|
126 | 126 | emit axisAdded(axis); |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | /* |
|
130 | 130 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
131 | 131 | */ |
|
132 | 132 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
133 | 133 | { |
|
134 | 134 | |
|
135 | 135 | if (! m_seriesList.contains(series)) { |
|
136 | 136 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
137 | 137 | return; |
|
138 | 138 | } |
|
139 | 139 | |
|
140 | 140 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
141 | 141 | |
|
142 | 142 | foreach(QAbstractAxis* axis, axes) { |
|
143 | 143 | detachAxis(series,axis); |
|
144 | 144 | } |
|
145 | 145 | |
|
146 | 146 | emit seriesRemoved(series); |
|
147 | 147 | m_seriesList.removeAll(series); |
|
148 | 148 | |
|
149 | 149 | // Reset domain to default |
|
150 | 150 | series->d_ptr->setDomain(new XYDomain()); |
|
151 | 151 | series->setParent(0); |
|
152 | 152 | series->d_ptr->m_chart = 0; |
|
153 | 153 | } |
|
154 | 154 | |
|
155 | 155 | /* |
|
156 | 156 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
157 | 157 | */ |
|
158 | 158 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
159 | 159 | { |
|
160 | 160 | if (! m_axisList.contains(axis)) { |
|
161 | 161 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
162 | 162 | return; |
|
163 | 163 | } |
|
164 | 164 | |
|
165 | 165 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
166 | 166 | |
|
167 | 167 | foreach(QAbstractSeries* s, series) { |
|
168 | 168 | detachAxis(s,axis); |
|
169 | 169 | } |
|
170 | 170 | |
|
171 | 171 | emit axisRemoved(axis); |
|
172 | 172 | m_axisList.removeAll(axis); |
|
173 | 173 | |
|
174 | 174 | axis->setParent(0); |
|
175 | 175 | axis->d_ptr->m_chart = 0; |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | /* |
|
179 | 179 | * This method attaches axis to series, return true if success. |
|
180 | 180 | */ |
|
181 | 181 | bool ChartDataSet::attachAxis(QAbstractSeries *series,QAbstractAxis *axis) |
|
182 | 182 | { |
|
183 | Q_ASSERT(series); | |
|
184 | 183 | Q_ASSERT(axis); |
|
185 | 184 | |
|
185 | if (!series) | |
|
186 | return false; | |
|
187 | ||
|
186 | 188 | QList<QAbstractSeries *> attachedSeriesList = axis->d_ptr->m_series; |
|
187 | 189 | QList<QAbstractAxis *> attachedAxisList = series->d_ptr->m_axes; |
|
188 | 190 | |
|
189 | 191 | if (!m_seriesList.contains(series)) { |
|
190 | 192 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
191 | 193 | return false; |
|
192 | 194 | } |
|
193 | 195 | |
|
194 | 196 | if (axis && !m_axisList.contains(axis)) { |
|
195 | 197 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
196 | 198 | return false; |
|
197 | 199 | } |
|
198 | 200 | |
|
199 | 201 | if (attachedAxisList.contains(axis)) { |
|
200 | 202 | qWarning() << QObject::tr("Axis already attached to series."); |
|
201 | 203 | return false; |
|
202 | 204 | } |
|
203 | 205 | |
|
204 | 206 | if (attachedSeriesList.contains(series)) { |
|
205 | 207 | qWarning() << QObject::tr("Axis already attached to series."); |
|
206 | 208 | return false; |
|
207 | 209 | } |
|
208 | 210 | |
|
209 | 211 | AbstractDomain *domain = series->d_ptr->domain(); |
|
210 | 212 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); |
|
211 | 213 | |
|
212 | 214 | if (type == AbstractDomain::UndefinedDomain) return false; |
|
213 | 215 | |
|
214 | 216 | if (domain->type() != type) { |
|
215 | 217 | AbstractDomain *old = domain; |
|
216 | 218 | domain = createDomain(type); |
|
217 | 219 | domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY()); |
|
218 | 220 | // Initialize domain size to old domain size, as it won't get updated |
|
219 | 221 | // unless geometry changes. |
|
220 | 222 | domain->setSize(old->size()); |
|
221 | 223 | } |
|
222 | 224 | |
|
223 | 225 | if (!domain) |
|
224 | 226 | return false; |
|
225 | 227 | |
|
226 | 228 | if (!domain->attachAxis(axis)) |
|
227 | 229 | return false; |
|
228 | 230 | |
|
229 | 231 | QList<AbstractDomain *> blockedDomains; |
|
230 | 232 | domain->blockRangeSignals(true); |
|
231 | 233 | blockedDomains << domain; |
|
232 | 234 | |
|
233 | 235 | if (domain != series->d_ptr->domain()) { |
|
234 | 236 | foreach (QAbstractAxis *axis, series->d_ptr->m_axes) { |
|
235 | 237 | series->d_ptr->domain()->detachAxis(axis); |
|
236 | 238 | domain->attachAxis(axis); |
|
237 | 239 | foreach (QAbstractSeries *otherSeries, axis->d_ptr->m_series) { |
|
238 | 240 | if (otherSeries != series && otherSeries->d_ptr->domain()) { |
|
239 | 241 | if (!otherSeries->d_ptr->domain()->rangeSignalsBlocked()) { |
|
240 | 242 | otherSeries->d_ptr->domain()->blockRangeSignals(true); |
|
241 | 243 | blockedDomains << otherSeries->d_ptr->domain(); |
|
242 | 244 | } |
|
243 | 245 | } |
|
244 | 246 | } |
|
245 | 247 | } |
|
246 | 248 | series->d_ptr->setDomain(domain); |
|
247 | 249 | series->d_ptr->initializeDomain(); |
|
248 | 250 | } |
|
249 | 251 | |
|
250 | 252 | series->d_ptr->m_axes<<axis; |
|
251 | 253 | axis->d_ptr->m_series<<series; |
|
252 | 254 | |
|
253 | 255 | series->d_ptr->initializeAxes(); |
|
254 | 256 | axis->d_ptr->initializeDomain(domain); |
|
255 | 257 | |
|
256 | 258 | foreach (AbstractDomain *blockedDomain, blockedDomains) |
|
257 | 259 | blockedDomain->blockRangeSignals(false); |
|
258 | 260 | |
|
259 | 261 | return true; |
|
260 | 262 | } |
|
261 | 263 | |
|
262 | 264 | /* |
|
263 | 265 | * This method detaches axis to series, return true if success. |
|
264 | 266 | */ |
|
265 | 267 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
266 | 268 | { |
|
267 | 269 | Q_ASSERT(series); |
|
268 | 270 | Q_ASSERT(axis); |
|
269 | 271 | |
|
270 | 272 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
271 | 273 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
272 | 274 | AbstractDomain* domain = series->d_ptr->domain(); |
|
273 | 275 | |
|
274 | 276 | if (!m_seriesList.contains(series)) { |
|
275 | 277 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
276 | 278 | return false; |
|
277 | 279 | } |
|
278 | 280 | |
|
279 | 281 | if (axis && !m_axisList.contains(axis)) { |
|
280 | 282 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
281 | 283 | return false; |
|
282 | 284 | } |
|
283 | 285 | |
|
284 | 286 | if (!attachedAxisList.contains(axis)) { |
|
285 | 287 | qWarning() << QObject::tr("Axis not attached to series."); |
|
286 | 288 | return false; |
|
287 | 289 | } |
|
288 | 290 | |
|
289 | 291 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
290 | 292 | |
|
291 | 293 | domain->detachAxis(axis); |
|
292 | 294 | series->d_ptr->m_axes.removeAll(axis); |
|
293 | 295 | axis->d_ptr->m_series.removeAll(series); |
|
294 | 296 | |
|
295 | 297 | return true; |
|
296 | 298 | } |
|
297 | 299 | |
|
298 | 300 | void ChartDataSet::createDefaultAxes() |
|
299 | 301 | { |
|
300 | 302 | if (m_seriesList.isEmpty()) |
|
301 | 303 | return; |
|
302 | 304 | |
|
303 | 305 | QAbstractAxis::AxisTypes typeX(0); |
|
304 | 306 | QAbstractAxis::AxisTypes typeY(0); |
|
305 | 307 | |
|
306 | 308 | // Remove possibly existing axes |
|
307 | 309 | deleteAllAxes(); |
|
308 | 310 | |
|
309 | 311 | Q_ASSERT(m_axisList.isEmpty()); |
|
310 | 312 | |
|
311 | 313 | // Select the required axis x and axis y types based on the types of the current series |
|
312 | 314 | foreach(QAbstractSeries* s, m_seriesList) { |
|
313 | 315 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
314 | 316 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
315 | 317 | } |
|
316 | 318 | |
|
317 | 319 | // Create the axes of the types selected |
|
318 | 320 | // As long as AxisType enum balues are sequential a check to see if there are series of |
|
319 | 321 | // different types is needed. In such cases AxisTypeNoAxis is used to create separate axes |
|
320 | 322 | // for the types. |
|
321 | 323 | if (typeX != QAbstractAxis::AxisTypeNoAxis) { |
|
322 | 324 | if (typeX != m_seriesList.first()->d_ptr->defaultAxisType(Qt::Horizontal)) |
|
323 | 325 | typeX = QAbstractAxis::AxisTypeNoAxis; |
|
324 | 326 | createAxes(typeX, Qt::Horizontal); |
|
325 | 327 | } |
|
326 | 328 | |
|
327 | 329 | if (typeY != QAbstractAxis::AxisTypeNoAxis) { |
|
328 | 330 | if (typeY != m_seriesList.first()->d_ptr->defaultAxisType(Qt::Vertical)) |
|
329 | 331 | typeY = QAbstractAxis::AxisTypeNoAxis; |
|
330 | 332 | createAxes(typeY, Qt::Vertical); |
|
331 | 333 | } |
|
332 | 334 | |
|
333 | 335 | } |
|
334 | 336 | |
|
335 | 337 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
336 | 338 | { |
|
337 | 339 | QAbstractAxis *axis = 0; |
|
338 | 340 | //decide what axis should be created |
|
339 | 341 | |
|
340 | 342 | switch (type) { |
|
341 | 343 | case QAbstractAxis::AxisTypeValue: |
|
342 | 344 | axis = new QValueAxis(this); |
|
343 | 345 | break; |
|
344 | 346 | case QAbstractAxis::AxisTypeBarCategory: |
|
345 | 347 | axis = new QBarCategoryAxis(this); |
|
346 | 348 | break; |
|
347 | 349 | case QAbstractAxis::AxisTypeCategory: |
|
348 | 350 | axis = new QCategoryAxis(this); |
|
349 | 351 | break; |
|
350 | 352 | #ifndef Q_WS_QWS |
|
351 | 353 | case QAbstractAxis::AxisTypeDateTime: |
|
352 | 354 | axis = new QDateTimeAxis(this); |
|
353 | 355 | break; |
|
354 | 356 | #endif |
|
355 | 357 | default: |
|
356 | 358 | axis = 0; |
|
357 | 359 | break; |
|
358 | 360 | } |
|
359 | 361 | |
|
360 | 362 | if (axis) { |
|
361 | 363 | //create one axis for all |
|
362 | 364 | |
|
363 | 365 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
364 | 366 | qreal min = 0; |
|
365 | 367 | qreal max = 0; |
|
366 | 368 | findMinMaxForSeries(m_seriesList,orientation,min,max); |
|
367 | 369 | foreach(QAbstractSeries *s, m_seriesList) { |
|
368 | 370 | attachAxis(s,axis); |
|
369 | 371 | } |
|
370 | 372 | axis->setRange(min,max); |
|
371 | 373 | } |
|
372 | 374 | else if (type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
373 | 375 | //create separate axis |
|
374 | 376 | foreach(QAbstractSeries *s, m_seriesList) { |
|
375 | 377 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
376 | 378 | if(axis) { |
|
377 | 379 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
378 | 380 | attachAxis(s,axis); |
|
379 | 381 | } |
|
380 | 382 | } |
|
381 | 383 | } |
|
382 | 384 | } |
|
383 | 385 | |
|
384 | 386 | void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max) |
|
385 | 387 | { |
|
386 | 388 | Q_ASSERT(!series.isEmpty()); |
|
387 | 389 | |
|
388 | 390 | AbstractDomain *domain = series.first()->d_ptr->domain(); |
|
389 | 391 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); |
|
390 | 392 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); |
|
391 | 393 | |
|
392 | 394 | for (int i = 1; i< series.size(); i++) { |
|
393 | 395 | AbstractDomain *domain = series[i]->d_ptr->domain(); |
|
394 | 396 | min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min); |
|
395 | 397 | max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max); |
|
396 | 398 | } |
|
397 | 399 | if (min == max) { |
|
398 | 400 | min -= 0.5; |
|
399 | 401 | max += 0.5; |
|
400 | 402 | } |
|
401 | 403 | } |
|
402 | 404 | |
|
403 | 405 | void ChartDataSet::deleteAllSeries() |
|
404 | 406 | { |
|
405 | 407 | foreach (QAbstractSeries *s , m_seriesList){ |
|
406 | 408 | removeSeries(s); |
|
407 | 409 | s->deleteLater(); |
|
408 | 410 | } |
|
409 | 411 | Q_ASSERT(m_seriesList.count() == 0); |
|
410 | 412 | } |
|
411 | 413 | |
|
412 | 414 | void ChartDataSet::deleteAllAxes() |
|
413 | 415 | { |
|
414 | 416 | foreach (QAbstractAxis *a , m_axisList){ |
|
415 | 417 | removeAxis(a); |
|
416 | 418 | a->deleteLater(); |
|
417 | 419 | } |
|
418 | 420 | Q_ASSERT(m_axisList.count() == 0); |
|
419 | 421 | } |
|
420 | 422 | |
|
421 | 423 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
422 | 424 | { |
|
423 | 425 | QList<AbstractDomain*> domains; |
|
424 | 426 | foreach(QAbstractSeries *s, m_seriesList) { |
|
425 | 427 | AbstractDomain* domain = s->d_ptr->domain(); |
|
426 | 428 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
427 | 429 | domains<<domain; |
|
428 | 430 | } |
|
429 | 431 | |
|
430 | 432 | foreach(AbstractDomain *domain, domains) |
|
431 | 433 | domain->zoomIn(rect); |
|
432 | 434 | |
|
433 | 435 | foreach(AbstractDomain *domain, domains) |
|
434 | 436 | domain->blockRangeSignals(false); |
|
435 | 437 | } |
|
436 | 438 | |
|
437 | 439 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
438 | 440 | { |
|
439 | 441 | QList<AbstractDomain*> domains; |
|
440 | 442 | foreach(QAbstractSeries *s, m_seriesList) { |
|
441 | 443 | AbstractDomain* domain = s->d_ptr->domain(); |
|
442 | 444 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
443 | 445 | domains<<domain; |
|
444 | 446 | } |
|
445 | 447 | |
|
446 | 448 | foreach(AbstractDomain *domain, domains) |
|
447 | 449 | domain->zoomOut(rect); |
|
448 | 450 | |
|
449 | 451 | foreach(AbstractDomain *domain, domains) |
|
450 | 452 | domain->blockRangeSignals(false); |
|
451 | 453 | } |
|
452 | 454 | |
|
453 | 455 | void ChartDataSet::zoomResetDomain() |
|
454 | 456 | { |
|
455 | 457 | QList<AbstractDomain*> domains; |
|
456 | 458 | foreach (QAbstractSeries *s, m_seriesList) { |
|
457 | 459 | AbstractDomain *domain = s->d_ptr->domain(); |
|
458 | 460 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
459 | 461 | domains << domain; |
|
460 | 462 | } |
|
461 | 463 | |
|
462 | 464 | foreach (AbstractDomain *domain, domains) |
|
463 | 465 | domain->zoomReset(); |
|
464 | 466 | |
|
465 | 467 | foreach (AbstractDomain *domain, domains) |
|
466 | 468 | domain->blockRangeSignals(false); |
|
467 | 469 | } |
|
468 | 470 | |
|
469 | 471 | bool ChartDataSet::isZoomedDomain() |
|
470 | 472 | { |
|
471 | 473 | foreach (QAbstractSeries *s, m_seriesList) { |
|
472 | 474 | if (s->d_ptr->domain()->isZoomed()) |
|
473 | 475 | return true; |
|
474 | 476 | } |
|
475 | 477 | return false; |
|
476 | 478 | } |
|
477 | 479 | |
|
478 | 480 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
479 | 481 | { |
|
480 | 482 | QList<AbstractDomain*> domains; |
|
481 | 483 | foreach(QAbstractSeries *s, m_seriesList) { |
|
482 | 484 | AbstractDomain* domain = s->d_ptr->domain(); |
|
483 | 485 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
484 | 486 | domains<<domain; |
|
485 | 487 | } |
|
486 | 488 | |
|
487 | 489 | foreach(AbstractDomain *domain, domains) |
|
488 | 490 | domain->move(dx, dy); |
|
489 | 491 | |
|
490 | 492 | foreach(AbstractDomain *domain, domains) |
|
491 | 493 | domain->blockRangeSignals(false); |
|
492 | 494 | } |
|
493 | 495 | |
|
494 | 496 | QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
495 | 497 | { |
|
496 | 498 | QPointF point; |
|
497 | 499 | if (series == 0 && !m_seriesList.isEmpty()) |
|
498 | 500 | series = m_seriesList.first(); |
|
499 | 501 | |
|
500 | 502 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
501 | 503 | return point; |
|
502 | 504 | |
|
503 | 505 | if (series && m_seriesList.contains(series)) |
|
504 | 506 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); |
|
505 | 507 | return point; |
|
506 | 508 | } |
|
507 | 509 | |
|
508 | 510 | QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
509 | 511 | { |
|
510 | 512 | QPointF point = m_chart->plotArea().topLeft(); |
|
511 | 513 | if (series == 0 && !m_seriesList.isEmpty()) |
|
512 | 514 | series = m_seriesList.first(); |
|
513 | 515 | |
|
514 | 516 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
515 | 517 | return QPoint(0, 0); |
|
516 | 518 | |
|
517 | 519 | bool ok; |
|
518 | 520 | if (series && m_seriesList.contains(series)) |
|
519 | 521 | point += series->d_ptr->m_domain->calculateGeometryPoint(value, ok); |
|
520 | 522 | return point; |
|
521 | 523 | } |
|
522 | 524 | |
|
523 | 525 | QList<QAbstractAxis *> ChartDataSet::axes() const |
|
524 | 526 | { |
|
525 | 527 | return m_axisList; |
|
526 | 528 | } |
|
527 | 529 | |
|
528 | 530 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
529 | 531 | { |
|
530 | 532 | return m_seriesList; |
|
531 | 533 | } |
|
532 | 534 | |
|
533 | 535 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis *> axes) |
|
534 | 536 | { |
|
535 | 537 | enum Type { |
|
536 | 538 | Undefined = 0, |
|
537 | 539 | LogType = 0x1, |
|
538 | 540 | ValueType = 0x2 |
|
539 | 541 | }; |
|
540 | 542 | |
|
541 | 543 | int horizontal(Undefined); |
|
542 | 544 | int vertical(Undefined); |
|
543 | 545 | |
|
544 | 546 | // Assume cartesian chart type, unless chart is set |
|
545 | 547 | QChart::ChartType chartType(QChart::ChartTypeCartesian); |
|
546 | 548 | if (m_chart) |
|
547 | 549 | chartType = m_chart->chartType(); |
|
548 | 550 | |
|
549 | 551 | foreach (QAbstractAxis *axis, axes) |
|
550 | 552 | { |
|
551 | 553 | switch (axis->type()) { |
|
552 | 554 | case QAbstractAxis::AxisTypeLogValue: |
|
553 | 555 | if (axis->orientation() == Qt::Horizontal) |
|
554 | 556 | horizontal |= LogType; |
|
555 | 557 | if (axis->orientation() == Qt::Vertical) |
|
556 | 558 | vertical |= LogType; |
|
557 | 559 | break; |
|
558 | 560 | case QAbstractAxis::AxisTypeValue: |
|
559 | 561 | case QAbstractAxis::AxisTypeBarCategory: |
|
560 | 562 | case QAbstractAxis::AxisTypeCategory: |
|
561 | 563 | case QAbstractAxis::AxisTypeDateTime: |
|
562 | 564 | if (axis->orientation() == Qt::Horizontal) |
|
563 | 565 | horizontal |= ValueType; |
|
564 | 566 | if (axis->orientation() == Qt::Vertical) |
|
565 | 567 | vertical |= ValueType; |
|
566 | 568 | break; |
|
567 | 569 | default: |
|
568 | 570 | qWarning() << "Undefined type"; |
|
569 | 571 | break; |
|
570 | 572 | } |
|
571 | 573 | } |
|
572 | 574 | |
|
573 | 575 | if (vertical == Undefined) |
|
574 | 576 | vertical = ValueType; |
|
575 | 577 | if (horizontal == Undefined) |
|
576 | 578 | horizontal = ValueType; |
|
577 | 579 | |
|
578 | 580 | if (vertical == ValueType && horizontal == ValueType) { |
|
579 | 581 | if (chartType == QChart::ChartTypeCartesian) |
|
580 | 582 | return AbstractDomain::XYDomain; |
|
581 | 583 | else if (chartType == QChart::ChartTypePolar) |
|
582 | 584 | return AbstractDomain::XYPolarDomain; |
|
583 | 585 | } |
|
584 | 586 | |
|
585 | 587 | if (vertical == LogType && horizontal == ValueType) { |
|
586 | 588 | if (chartType == QChart::ChartTypeCartesian) |
|
587 | 589 | return AbstractDomain::XLogYDomain; |
|
588 | 590 | if (chartType == QChart::ChartTypePolar) |
|
589 | 591 | return AbstractDomain::XLogYPolarDomain; |
|
590 | 592 | } |
|
591 | 593 | |
|
592 | 594 | if (vertical == ValueType && horizontal == LogType) { |
|
593 | 595 | if (chartType == QChart::ChartTypeCartesian) |
|
594 | 596 | return AbstractDomain::LogXYDomain; |
|
595 | 597 | else if (chartType == QChart::ChartTypePolar) |
|
596 | 598 | return AbstractDomain::LogXYPolarDomain; |
|
597 | 599 | } |
|
598 | 600 | |
|
599 | 601 | if (vertical == LogType && horizontal == LogType) { |
|
600 | 602 | if (chartType == QChart::ChartTypeCartesian) |
|
601 | 603 | return AbstractDomain::LogXLogYDomain; |
|
602 | 604 | else if (chartType == QChart::ChartTypePolar) |
|
603 | 605 | return AbstractDomain::LogXLogYPolarDomain; |
|
604 | 606 | } |
|
605 | 607 | |
|
606 | 608 | return AbstractDomain::UndefinedDomain; |
|
607 | 609 | } |
|
608 | 610 | |
|
609 | 611 | //refactor create factory |
|
610 | 612 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) |
|
611 | 613 | { |
|
612 | 614 | switch (type) |
|
613 | 615 | { |
|
614 | 616 | case AbstractDomain::LogXLogYDomain: |
|
615 | 617 | return new LogXLogYDomain(); |
|
616 | 618 | case AbstractDomain::XYDomain: |
|
617 | 619 | return new XYDomain(); |
|
618 | 620 | case AbstractDomain::XLogYDomain: |
|
619 | 621 | return new XLogYDomain(); |
|
620 | 622 | case AbstractDomain::LogXYDomain: |
|
621 | 623 | return new LogXYDomain(); |
|
622 | 624 | case AbstractDomain::XYPolarDomain: |
|
623 | 625 | return new XYPolarDomain(); |
|
624 | 626 | case AbstractDomain::XLogYPolarDomain: |
|
625 | 627 | return new XLogYPolarDomain(); |
|
626 | 628 | case AbstractDomain::LogXYPolarDomain: |
|
627 | 629 | return new LogXYPolarDomain(); |
|
628 | 630 | case AbstractDomain::LogXLogYPolarDomain: |
|
629 | 631 | return new LogXLogYPolarDomain(); |
|
630 | 632 | default: |
|
631 | 633 | return 0; |
|
632 | 634 | } |
|
633 | 635 | } |
|
634 | 636 | |
|
635 | 637 | #include "moc_chartdataset_p.cpp" |
|
636 | 638 | |
|
637 | 639 | QTCOMMERCIALCHART_END_NAMESPACE |
General Comments 0
You need to be logged in to leave comments.
Login now