@@ -1,513 +1,530 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 "xlogydomain_p.h" |
|
37 | 37 | #include "logxydomain_p.h" |
|
38 | 38 | #include "logxlogydomain_p.h" |
|
39 | 39 | |
|
40 | 40 | #ifndef QT_ON_ARM |
|
41 | 41 | #include "qdatetimeaxis.h" |
|
42 | 42 | #endif |
|
43 | 43 | |
|
44 | 44 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
45 | 45 | |
|
46 | 46 | ChartDataSet::ChartDataSet(QChart *chart) |
|
47 | 47 | : QObject(chart), |
|
48 | 48 | m_chart(chart) |
|
49 | 49 | { |
|
50 | 50 | |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | ChartDataSet::~ChartDataSet() |
|
54 | 54 | { |
|
55 | 55 | deleteAllSeries(); |
|
56 | 56 | deleteAllAxes(); |
|
57 | 57 | } |
|
58 | 58 | |
|
59 | 59 | /* |
|
60 | 60 | * This method adds series to chartdataset, series ownership is taken from caller. |
|
61 | 61 | */ |
|
62 | 62 | void ChartDataSet::addSeries(QAbstractSeries *series) |
|
63 | 63 | { |
|
64 | 64 | if (m_seriesList.contains(series)) { |
|
65 | 65 | qWarning() << QObject::tr("Can not add series. Series already on the chart."); |
|
66 | 66 | return; |
|
67 | 67 | } |
|
68 | 68 | |
|
69 | 69 | series->d_ptr->initializeDomain(); |
|
70 | 70 | m_seriesList.append(series); |
|
71 | 71 | |
|
72 | 72 | series->setParent(this); // take ownership |
|
73 | 73 | series->d_ptr->m_chart = m_chart; |
|
74 | 74 | |
|
75 | 75 | emit seriesAdded(series); |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | /* |
|
79 | 79 | * This method adds axis to chartdataset, axis ownership is taken from caller. |
|
80 | 80 | */ |
|
81 | 81 | void ChartDataSet::addAxis(QAbstractAxis *axis,Qt::Alignment aligment) |
|
82 | 82 | { |
|
83 | 83 | if (m_axisList.contains(axis)) { |
|
84 | 84 | qWarning() << QObject::tr("Can not add axis. Axis already on the chart."); |
|
85 | 85 | return; |
|
86 | 86 | } |
|
87 | 87 | |
|
88 | 88 | axis->d_ptr->setAlignment(aligment); |
|
89 | 89 | |
|
90 | 90 | if(!axis->alignment()) { |
|
91 | 91 | qWarning()<< QObject::tr("No alignment specified !"); |
|
92 | 92 | return; |
|
93 | 93 | }; |
|
94 | 94 | |
|
95 | 95 | QSharedPointer<AbstractDomain> domain(new XYDomain()); |
|
96 | 96 | axis->d_ptr->initializeDomain(domain.data()); |
|
97 | 97 | |
|
98 | 98 | axis->setParent(this); |
|
99 | 99 | axis->d_ptr->m_chart = m_chart; |
|
100 | 100 | m_axisList.append(axis); |
|
101 | 101 | |
|
102 | 102 | emit axisAdded(axis); |
|
103 | 103 | } |
|
104 | 104 | |
|
105 | 105 | /* |
|
106 | 106 | * This method removes series form chartdataset, series ownership is passed back to caller. |
|
107 | 107 | */ |
|
108 | 108 | void ChartDataSet::removeSeries(QAbstractSeries *series) |
|
109 | 109 | { |
|
110 | 110 | |
|
111 | 111 | if (! m_seriesList.contains(series)) { |
|
112 | 112 | qWarning() << QObject::tr("Can not remove series. Series not found on the chart."); |
|
113 | 113 | return; |
|
114 | 114 | } |
|
115 | 115 | |
|
116 | 116 | QList<QAbstractAxis*> axes = series->d_ptr->m_axes; |
|
117 | 117 | |
|
118 | 118 | foreach(QAbstractAxis* axis, axes) { |
|
119 | 119 | detachAxis(series,axis); |
|
120 | 120 | } |
|
121 | 121 | |
|
122 | 122 | emit seriesRemoved(series); |
|
123 | 123 | m_seriesList.removeAll(series); |
|
124 | 124 | |
|
125 | 125 | series->setParent(0); |
|
126 | 126 | series->d_ptr->m_chart = 0; |
|
127 | 127 | } |
|
128 | 128 | |
|
129 | 129 | /* |
|
130 | 130 | * This method removes axis form chartdataset, series ownership is passed back to caller. |
|
131 | 131 | */ |
|
132 | 132 | void ChartDataSet::removeAxis(QAbstractAxis *axis) |
|
133 | 133 | { |
|
134 | 134 | if (! m_axisList.contains(axis)) { |
|
135 | 135 | qWarning() << QObject::tr("Can not remove axis. Axis not found on the chart."); |
|
136 | 136 | return; |
|
137 | 137 | } |
|
138 | 138 | |
|
139 | 139 | QList<QAbstractSeries*> series = axis->d_ptr->m_series; |
|
140 | 140 | |
|
141 | 141 | foreach(QAbstractSeries* s, series) { |
|
142 | 142 | detachAxis(s,axis); |
|
143 | 143 | } |
|
144 | 144 | |
|
145 | 145 | emit axisRemoved(axis); |
|
146 | 146 | m_axisList.removeAll(axis); |
|
147 | 147 | |
|
148 | 148 | axis->setParent(0); |
|
149 | 149 | axis->d_ptr->m_chart = 0; |
|
150 | 150 | } |
|
151 | 151 | |
|
152 | 152 | /* |
|
153 | 153 | * This method attaches axis to series, return true if success. |
|
154 | 154 | */ |
|
155 | 155 | bool ChartDataSet::attachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
156 | 156 | { |
|
157 | 157 | Q_ASSERT(series); |
|
158 | 158 | Q_ASSERT(axis); |
|
159 | 159 | |
|
160 | 160 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
161 | 161 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
162 | 162 | |
|
163 | 163 | if (!m_seriesList.contains(series)) { |
|
164 | 164 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
165 | 165 | return false; |
|
166 | 166 | } |
|
167 | 167 | |
|
168 | 168 | if (axis && !m_axisList.contains(axis)) { |
|
169 | 169 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
170 | 170 | return false; |
|
171 | 171 | } |
|
172 | 172 | |
|
173 | 173 | if (attachedAxisList.contains(axis)) { |
|
174 | 174 | qWarning() << QObject::tr("Axis already attached to series."); |
|
175 | 175 | return false; |
|
176 | 176 | } |
|
177 | 177 | |
|
178 | 178 | if (attachedSeriesList.contains(series)) { |
|
179 | 179 | qWarning() << QObject::tr("Axis already attached to series."); |
|
180 | 180 | return false; |
|
181 | 181 | } |
|
182 | 182 | |
|
183 | 183 | AbstractDomain* domain = series->d_ptr->domain(); |
|
184 | 184 | AbstractDomain::DomainType type = selectDomain(attachedAxisList<<axis); |
|
185 | 185 | |
|
186 | 186 | if(type == AbstractDomain::UndefinedDomain) return false; |
|
187 | 187 | |
|
188 | 188 | if(domain->type()!=type){ |
|
189 | 189 | AbstractDomain *old = domain; |
|
190 | 190 | domain = createDomain(type); |
|
191 | 191 | domain->setRange(old->minX(), old->maxX(), old->minY(), old->maxY()); |
|
192 | 192 | } |
|
193 | 193 | |
|
194 | 194 | if(!domain) return false; |
|
195 | 195 | |
|
196 | 196 | if(!domain->attachAxis(axis)) return false; |
|
197 | 197 | |
|
198 | 198 | if(domain!=series->d_ptr->domain()){ |
|
199 | 199 | foreach(QAbstractAxis* axis,series->d_ptr->m_axes){ |
|
200 | 200 | series->d_ptr->domain()->detachAxis(axis); |
|
201 | 201 | domain->attachAxis(axis); |
|
202 | 202 | } |
|
203 | 203 | series->d_ptr->setDomain(domain); |
|
204 | 204 | series->d_ptr->initializeDomain(); |
|
205 | 205 | } |
|
206 | 206 | |
|
207 | 207 | series->d_ptr->m_axes<<axis; |
|
208 | 208 | axis->d_ptr->m_series<<series; |
|
209 | 209 | |
|
210 | 210 | series->d_ptr->initializeAxes(); |
|
211 | 211 | axis->d_ptr->initializeDomain(domain); |
|
212 | 212 | |
|
213 | 213 | return true; |
|
214 | 214 | } |
|
215 | 215 | |
|
216 | 216 | /* |
|
217 | 217 | * This method detaches axis to series, return true if success. |
|
218 | 218 | */ |
|
219 | 219 | bool ChartDataSet::detachAxis(QAbstractSeries* series,QAbstractAxis *axis) |
|
220 | 220 | { |
|
221 | 221 | Q_ASSERT(series); |
|
222 | 222 | Q_ASSERT(axis); |
|
223 | 223 | |
|
224 | 224 | QList<QAbstractSeries* > attachedSeriesList = axis->d_ptr->m_series; |
|
225 | 225 | QList<QAbstractAxis* > attachedAxisList = series->d_ptr->m_axes; |
|
226 | 226 | AbstractDomain* domain = series->d_ptr->domain(); |
|
227 | 227 | |
|
228 | 228 | if (!m_seriesList.contains(series)) { |
|
229 | 229 | qWarning() << QObject::tr("Can not find series on the chart."); |
|
230 | 230 | return false; |
|
231 | 231 | } |
|
232 | 232 | |
|
233 | 233 | if (axis && !m_axisList.contains(axis)) { |
|
234 | 234 | qWarning() << QObject::tr("Can not find axis on the chart."); |
|
235 | 235 | return false; |
|
236 | 236 | } |
|
237 | 237 | |
|
238 | 238 | if (!attachedAxisList.contains(axis)) { |
|
239 | 239 | qWarning() << QObject::tr("Axis not attached to series."); |
|
240 | 240 | return false; |
|
241 | 241 | } |
|
242 | 242 | |
|
243 | 243 | Q_ASSERT(axis->d_ptr->m_series.contains(series)); |
|
244 | 244 | |
|
245 | 245 | domain->detachAxis(axis); |
|
246 | 246 | series->d_ptr->m_axes.removeAll(axis); |
|
247 | 247 | axis->d_ptr->m_series.removeAll(series); |
|
248 | 248 | |
|
249 | 249 | return true; |
|
250 | 250 | } |
|
251 | 251 | |
|
252 | 252 | void ChartDataSet::createDefaultAxes() |
|
253 | 253 | { |
|
254 | 254 | if (m_seriesList.isEmpty()) |
|
255 | 255 | return; |
|
256 | 256 | |
|
257 | 257 | QAbstractAxis::AxisTypes typeX(0); |
|
258 | 258 | QAbstractAxis::AxisTypes typeY(0); |
|
259 | 259 | |
|
260 | 260 | // Remove possibly existing axes |
|
261 | 261 | deleteAllAxes(); |
|
262 | 262 | |
|
263 | 263 | Q_ASSERT(m_axisList.isEmpty()); |
|
264 | 264 | |
|
265 | 265 | // Select the required axis x and axis y types based on the types of the current series |
|
266 | 266 | foreach(QAbstractSeries* s, m_seriesList) { |
|
267 | 267 | typeX |= s->d_ptr->defaultAxisType(Qt::Horizontal); |
|
268 | 268 | typeY |= s->d_ptr->defaultAxisType(Qt::Vertical); |
|
269 | 269 | } |
|
270 | 270 | |
|
271 | 271 | // Create the axes of the types selected |
|
272 | 272 | createAxes(typeX, Qt::Horizontal); |
|
273 | 273 | createAxes(typeY, Qt::Vertical); |
|
274 | 274 | |
|
275 | 275 | } |
|
276 | 276 | |
|
277 | 277 | void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation) |
|
278 | 278 | { |
|
279 | 279 | QAbstractAxis *axis = 0; |
|
280 | 280 | //decide what axis should be created |
|
281 | 281 | |
|
282 | 282 | switch (type) { |
|
283 | 283 | case QAbstractAxis::AxisTypeValue: |
|
284 | 284 | axis = new QValueAxis(this); |
|
285 | 285 | break; |
|
286 | 286 | case QAbstractAxis::AxisTypeBarCategory: |
|
287 | 287 | axis = new QBarCategoryAxis(this); |
|
288 | 288 | break; |
|
289 | 289 | case QAbstractAxis::AxisTypeCategory: |
|
290 | 290 | axis = new QCategoryAxis(this); |
|
291 | 291 | break; |
|
292 | 292 | #ifndef Q_WS_QWS |
|
293 | 293 | case QAbstractAxis::AxisTypeDateTime: |
|
294 | 294 | axis = new QDateTimeAxis(this); |
|
295 | 295 | break; |
|
296 | 296 | #endif |
|
297 | 297 | default: |
|
298 | 298 | axis = 0; |
|
299 | 299 | break; |
|
300 | 300 | } |
|
301 | 301 | |
|
302 | 302 | if (axis) { |
|
303 | 303 | //create one axis for all |
|
304 | 304 | |
|
305 | 305 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
306 | ||
|
306 | qreal min = 0; | |
|
307 | qreal max = 0; | |
|
308 | findMinMaxForSeries(m_seriesList,orientation,min,max); | |
|
307 | 309 | foreach(QAbstractSeries *s, m_seriesList) { |
|
308 | 310 | attachAxis(s,axis); |
|
309 | 311 | } |
|
310 | ||
|
312 | axis->setRange(min,max); | |
|
311 | 313 | } |
|
312 | 314 | else if (!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) { |
|
313 | 315 | //create separate axis |
|
314 | 316 | foreach(QAbstractSeries *s, m_seriesList) { |
|
315 | 317 | QAbstractAxis *axis = s->d_ptr->createDefaultAxis(orientation); |
|
316 | 318 | if(axis) { |
|
317 | 319 | addAxis(axis,orientation==Qt::Horizontal?Qt::AlignBottom:Qt::AlignLeft); |
|
318 | 320 | attachAxis(s,axis); |
|
319 | 321 | } |
|
320 | 322 | } |
|
321 | 323 | } |
|
322 | 324 | } |
|
323 | 325 | |
|
326 | void ChartDataSet::findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max) | |
|
327 | { | |
|
328 | Q_ASSERT(!series.isEmpty()); | |
|
329 | ||
|
330 | AbstractDomain* domain = series.first()->d_ptr->domain(); | |
|
331 | min = (orientation == Qt::Vertical) ? domain->minY() : domain->minX(); | |
|
332 | max = (orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(); | |
|
333 | ||
|
334 | for(int i = 1; i< series.size(); i++) { | |
|
335 | AbstractDomain* domain = series[i]->d_ptr->domain(); | |
|
336 | min = qMin((orientation == Qt::Vertical) ? domain->minY() : domain->minX(), min); | |
|
337 | max = qMax((orientation == Qt::Vertical) ? domain->maxY() : domain->maxX(), max); | |
|
338 | } | |
|
339 | } | |
|
340 | ||
|
324 | 341 | void ChartDataSet::deleteAllSeries() |
|
325 | 342 | { |
|
326 | 343 | foreach (QAbstractSeries *s , m_seriesList){ |
|
327 | 344 | removeSeries(s); |
|
328 | 345 | s->deleteLater(); |
|
329 | 346 | } |
|
330 | 347 | Q_ASSERT(m_seriesList.count() == 0); |
|
331 | 348 | } |
|
332 | 349 | |
|
333 | 350 | void ChartDataSet::deleteAllAxes() |
|
334 | 351 | { |
|
335 | 352 | foreach (QAbstractAxis *a , m_axisList){ |
|
336 | 353 | removeAxis(a); |
|
337 | 354 | a->deleteLater(); |
|
338 | 355 | } |
|
339 | 356 | Q_ASSERT(m_axisList.count() == 0); |
|
340 | 357 | } |
|
341 | 358 | |
|
342 | 359 | void ChartDataSet::zoomInDomain(const QRectF &rect) |
|
343 | 360 | { |
|
344 | 361 | QList<AbstractDomain*> domains; |
|
345 | 362 | foreach(QAbstractSeries *s, m_seriesList) { |
|
346 | 363 | AbstractDomain* domain = s->d_ptr->domain(); |
|
347 | 364 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
348 | 365 | domains<<domain; |
|
349 | 366 | } |
|
350 | 367 | |
|
351 | 368 | foreach(AbstractDomain *domain, domains) |
|
352 | 369 | domain->zoomIn(rect); |
|
353 | 370 | |
|
354 | 371 | foreach(AbstractDomain *domain, domains) |
|
355 | 372 | domain->blockRangeSignals(false); |
|
356 | 373 | } |
|
357 | 374 | |
|
358 | 375 | void ChartDataSet::zoomOutDomain(const QRectF &rect) |
|
359 | 376 | { |
|
360 | 377 | QList<AbstractDomain*> domains; |
|
361 | 378 | foreach(QAbstractSeries *s, m_seriesList) { |
|
362 | 379 | AbstractDomain* domain = s->d_ptr->domain(); |
|
363 | 380 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
364 | 381 | domains<<domain; |
|
365 | 382 | } |
|
366 | 383 | |
|
367 | 384 | foreach(AbstractDomain *domain, domains) |
|
368 | 385 | domain->zoomOut(rect); |
|
369 | 386 | |
|
370 | 387 | foreach(AbstractDomain *domain, domains) |
|
371 | 388 | domain->blockRangeSignals(false); |
|
372 | 389 | } |
|
373 | 390 | |
|
374 | 391 | void ChartDataSet::scrollDomain(qreal dx, qreal dy) |
|
375 | 392 | { |
|
376 | 393 | QList<AbstractDomain*> domains; |
|
377 | 394 | foreach(QAbstractSeries *s, m_seriesList) { |
|
378 | 395 | AbstractDomain* domain = s->d_ptr->domain(); |
|
379 | 396 | s->d_ptr->m_domain->blockRangeSignals(true); |
|
380 | 397 | domains<<domain; |
|
381 | 398 | } |
|
382 | 399 | |
|
383 | 400 | foreach(AbstractDomain *domain, domains) |
|
384 | 401 | domain->move(dx, dy); |
|
385 | 402 | |
|
386 | 403 | foreach(AbstractDomain *domain, domains) |
|
387 | 404 | domain->blockRangeSignals(false); |
|
388 | 405 | } |
|
389 | 406 | |
|
390 | 407 | QPointF ChartDataSet::mapToValue(const QPointF &position, QAbstractSeries *series) |
|
391 | 408 | { |
|
392 | 409 | QPointF point; |
|
393 | 410 | if (series == 0 && !m_seriesList.isEmpty()) |
|
394 | 411 | series = m_seriesList.first(); |
|
395 | 412 | |
|
396 | 413 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
397 | 414 | return point; |
|
398 | 415 | |
|
399 | 416 | if (series && m_seriesList.contains(series)) |
|
400 | 417 | point = series->d_ptr->m_domain->calculateDomainPoint(position - m_chart->plotArea().topLeft()); |
|
401 | 418 | return point; |
|
402 | 419 | } |
|
403 | 420 | |
|
404 | 421 | QPointF ChartDataSet::mapToPosition(const QPointF &value, QAbstractSeries *series) |
|
405 | 422 | { |
|
406 | 423 | QPointF point = m_chart->plotArea().topLeft(); |
|
407 | 424 | if (series == 0 && !m_seriesList.isEmpty()) |
|
408 | 425 | series = m_seriesList.first(); |
|
409 | 426 | |
|
410 | 427 | if (series && series->type() == QAbstractSeries::SeriesTypePie) |
|
411 | 428 | return QPoint(0, 0); |
|
412 | 429 | |
|
413 | 430 | bool ok; |
|
414 | 431 | if (series && m_seriesList.contains(series)) |
|
415 | 432 | point += series->d_ptr->m_domain->calculateGeometryPoint(value, ok); |
|
416 | 433 | return point; |
|
417 | 434 | } |
|
418 | 435 | |
|
419 | 436 | QList<QAbstractAxis*> ChartDataSet::axes() const |
|
420 | 437 | { |
|
421 | 438 | return m_axisList; |
|
422 | 439 | } |
|
423 | 440 | |
|
424 | 441 | QList<QAbstractSeries *> ChartDataSet::series() const |
|
425 | 442 | { |
|
426 | 443 | return m_seriesList; |
|
427 | 444 | } |
|
428 | 445 | |
|
429 | 446 | AbstractDomain::DomainType ChartDataSet::selectDomain(QList<QAbstractAxis*> axes) |
|
430 | 447 | { |
|
431 | 448 | enum Type { |
|
432 | 449 | Undefined = 0, |
|
433 | 450 | LogType = 0x1, |
|
434 | 451 | ValueType = 0x2 |
|
435 | 452 | }; |
|
436 | 453 | |
|
437 | 454 | int horizontal(Undefined); |
|
438 | 455 | int vertical(Undefined); |
|
439 | 456 | |
|
440 | 457 | foreach(QAbstractAxis* axis, axes) |
|
441 | 458 | { |
|
442 | 459 | switch(axis->type()) { |
|
443 | 460 | case QAbstractAxis::AxisTypeLogValue: |
|
444 | 461 | |
|
445 | 462 | if(axis->orientation()==Qt::Horizontal) { |
|
446 | 463 | horizontal|=LogType; |
|
447 | 464 | } |
|
448 | 465 | if(axis->orientation()==Qt::Vertical) { |
|
449 | 466 | vertical|=LogType; |
|
450 | 467 | } |
|
451 | 468 | |
|
452 | 469 | break; |
|
453 | 470 | case QAbstractAxis::AxisTypeValue: |
|
454 | 471 | case QAbstractAxis::AxisTypeBarCategory: |
|
455 | 472 | case QAbstractAxis::AxisTypeCategory: |
|
456 | 473 | case QAbstractAxis::AxisTypeDateTime: |
|
457 | 474 | if(axis->orientation()==Qt::Horizontal) { |
|
458 | 475 | horizontal|=ValueType; |
|
459 | 476 | } |
|
460 | 477 | if(axis->orientation()==Qt::Vertical) { |
|
461 | 478 | vertical|=ValueType; |
|
462 | 479 | } |
|
463 | 480 | break; |
|
464 | 481 | default: |
|
465 | 482 | qWarning()<<"Undefined type"; |
|
466 | 483 | break; |
|
467 | 484 | } |
|
468 | 485 | } |
|
469 | 486 | |
|
470 | 487 | if(vertical==Undefined) vertical=ValueType; |
|
471 | 488 | if(horizontal==Undefined) horizontal=ValueType; |
|
472 | 489 | |
|
473 | 490 | if(vertical==ValueType && horizontal== ValueType) { |
|
474 | 491 | return AbstractDomain::XYDomain; |
|
475 | 492 | } |
|
476 | 493 | |
|
477 | 494 | if(vertical==LogType && horizontal== ValueType) { |
|
478 | 495 | return AbstractDomain::XLogYDomain; |
|
479 | 496 | } |
|
480 | 497 | |
|
481 | 498 | if(vertical==ValueType && horizontal== LogType) { |
|
482 | 499 | return AbstractDomain::LogXYDomain; |
|
483 | 500 | } |
|
484 | 501 | |
|
485 | 502 | if(vertical==LogType && horizontal== LogType) { |
|
486 | 503 | return AbstractDomain::LogXLogYDomain; |
|
487 | 504 | } |
|
488 | 505 | |
|
489 | 506 | return AbstractDomain::UndefinedDomain; |
|
490 | 507 | } |
|
491 | 508 | |
|
492 | 509 | |
|
493 | 510 | //refactor create factory |
|
494 | 511 | AbstractDomain* ChartDataSet::createDomain(AbstractDomain::DomainType type) |
|
495 | 512 | { |
|
496 | 513 | switch(type) |
|
497 | 514 | { |
|
498 | 515 | case AbstractDomain::LogXLogYDomain: |
|
499 | 516 | return new LogXLogYDomain(); |
|
500 | 517 | case AbstractDomain::XYDomain: |
|
501 | 518 | return new XYDomain(); |
|
502 | 519 | case AbstractDomain::XLogYDomain: |
|
503 | 520 | return new XLogYDomain(); |
|
504 | 521 | case AbstractDomain::LogXYDomain: |
|
505 | 522 | return new LogXYDomain(); |
|
506 | 523 | default: |
|
507 | 524 | return 0; |
|
508 | 525 | } |
|
509 | 526 | } |
|
510 | 527 | |
|
511 | 528 | #include "moc_chartdataset_p.cpp" |
|
512 | 529 | |
|
513 | 530 | QTCOMMERCIALCHART_END_NAMESPACE |
@@ -1,91 +1,92 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 | // W A R N I N G |
|
22 | 22 | // ------------- |
|
23 | 23 | // |
|
24 | 24 | // This file is not part of the QtCommercial Chart API. It exists purely as an |
|
25 | 25 | // implementation detail. This header file may change from version to |
|
26 | 26 | // version without notice, or even be removed. |
|
27 | 27 | // |
|
28 | 28 | // We mean it. |
|
29 | 29 | |
|
30 | 30 | #ifndef CHARTDATASET_P_H |
|
31 | 31 | #define CHARTDATASET_P_H |
|
32 | 32 | |
|
33 | 33 | #include "qabstractseries.h" |
|
34 | 34 | #include "abstractdomain_p.h" |
|
35 | 35 | #include "qabstractaxis_p.h" |
|
36 | 36 | #include <QVector> |
|
37 | 37 | |
|
38 | 38 | QTCOMMERCIALCHART_BEGIN_NAMESPACE |
|
39 | 39 | |
|
40 | 40 | class QAbstractAxis; |
|
41 | 41 | class ChartPresenter; |
|
42 | 42 | |
|
43 | 43 | class QTCOMMERCIALCHART_AUTOTEST_EXPORT ChartDataSet : public QObject |
|
44 | 44 | { |
|
45 | 45 | Q_OBJECT |
|
46 | 46 | public: |
|
47 | 47 | ChartDataSet(QChart *chart); |
|
48 | 48 | virtual ~ChartDataSet(); |
|
49 | 49 | |
|
50 | 50 | void addSeries(QAbstractSeries *series); |
|
51 | 51 | void removeSeries(QAbstractSeries *series); |
|
52 | 52 | QList<QAbstractSeries *> series() const; |
|
53 | 53 | |
|
54 | 54 | void addAxis(QAbstractAxis *axis,Qt::Alignment aligment); |
|
55 | 55 | void removeAxis(QAbstractAxis *axis); |
|
56 | 56 | QList<QAbstractAxis*> axes() const; |
|
57 | 57 | |
|
58 | 58 | bool attachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
59 | 59 | bool detachAxis(QAbstractSeries* series,QAbstractAxis *axis); |
|
60 | 60 | |
|
61 | 61 | void createDefaultAxes(); |
|
62 | 62 | |
|
63 | 63 | void zoomInDomain(const QRectF &rect); |
|
64 | 64 | void zoomOutDomain(const QRectF &rect); |
|
65 | 65 | void scrollDomain(qreal dx, qreal dy); |
|
66 | 66 | |
|
67 | 67 | QPointF mapToValue(const QPointF &position, QAbstractSeries *series = 0); |
|
68 | 68 | QPointF mapToPosition(const QPointF &value, QAbstractSeries *series = 0); |
|
69 | 69 | |
|
70 | 70 | Q_SIGNALS: |
|
71 | 71 | void axisAdded(QAbstractAxis* axis); |
|
72 | 72 | void axisRemoved(QAbstractAxis* axis); |
|
73 | 73 | void seriesAdded(QAbstractSeries* series); |
|
74 | 74 | void seriesRemoved(QAbstractSeries* series); |
|
75 | 75 | |
|
76 | 76 | private: |
|
77 | 77 | void createAxes(QAbstractAxis::AxisTypes type, Qt::Orientation orientation); |
|
78 | 78 | QAbstractAxis *createAxis(QAbstractAxis::AxisType type, Qt::Orientation orientation); |
|
79 | 79 | AbstractDomain::DomainType selectDomain(QList<QAbstractAxis* > axes); |
|
80 | 80 | AbstractDomain* createDomain(AbstractDomain::DomainType type); |
|
81 | 81 | void deleteAllAxes(); |
|
82 | 82 | void deleteAllSeries(); |
|
83 | void findMinMaxForSeries(QList<QAbstractSeries *> series,Qt::Orientations orientation, qreal &min, qreal &max); | |
|
83 | 84 | private: |
|
84 | 85 | QList<QAbstractSeries *> m_seriesList; |
|
85 | 86 | QList<QAbstractAxis *> m_axisList; |
|
86 | 87 | QChart* m_chart; |
|
87 | 88 | }; |
|
88 | 89 | |
|
89 | 90 | QTCOMMERCIALCHART_END_NAMESPACE |
|
90 | 91 | |
|
91 | 92 | #endif /* CHARTENGINE_P_H */ |
@@ -1,798 +1,876 | |||
|
1 | 1 | /**************************************************************************** |
|
2 | 2 | ** |
|
3 | 3 | ** Copyright (C) 2012 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 Commercial Charts Add-on. |
|
8 | 8 | ** |
|
9 | 9 | ** $QT_BEGIN_LICENSE$ |
|
10 | 10 | ** Licensees holding valid Qt Commercial licenses may use this file in |
|
11 | 11 | ** accordance with the Qt Commercial 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 <QtTest/QtTest> |
|
22 | 22 | #include <qchartview.h> |
|
23 | 23 | #include <qlineseries.h> |
|
24 | 24 | #include <qareaseries.h> |
|
25 | 25 | #include <qscatterseries.h> |
|
26 | 26 | #include <qsplineseries.h> |
|
27 | 27 | #include <qpieseries.h> |
|
28 | 28 | #include <qabstractbarseries.h> |
|
29 | 29 | #include <qbarseries.h> |
|
30 | 30 | #include <qpercentbarseries.h> |
|
31 | 31 | #include <qstackedbarseries.h> |
|
32 | 32 | #include <qvalueaxis.h> |
|
33 | 33 | #include <qbarcategoryaxis.h> |
|
34 | 34 | #include "tst_definitions.h" |
|
35 | 35 | |
|
36 | 36 | QTCOMMERCIALCHART_USE_NAMESPACE |
|
37 | 37 | |
|
38 | 38 | Q_DECLARE_METATYPE(QAbstractAxis *) |
|
39 | 39 | Q_DECLARE_METATYPE(QValueAxis *) |
|
40 | 40 | Q_DECLARE_METATYPE(QBarCategoryAxis *) |
|
41 | 41 | Q_DECLARE_METATYPE(QAbstractSeries *) |
|
42 | 42 | Q_DECLARE_METATYPE(QChart::AnimationOption) |
|
43 | 43 | Q_DECLARE_METATYPE(QBrush) |
|
44 | 44 | Q_DECLARE_METATYPE(QPen) |
|
45 | 45 | Q_DECLARE_METATYPE(QChart::ChartTheme) |
|
46 | 46 | |
|
47 | 47 | class tst_QChart : public QObject |
|
48 | 48 | { |
|
49 | 49 | Q_OBJECT |
|
50 | 50 | |
|
51 | 51 | public slots: |
|
52 | 52 | void initTestCase(); |
|
53 | 53 | void cleanupTestCase(); |
|
54 | 54 | void init(); |
|
55 | 55 | void cleanup(); |
|
56 | 56 | |
|
57 | 57 | private slots: |
|
58 | 58 | void qchart_data(); |
|
59 | 59 | void qchart(); |
|
60 | 60 | void addSeries_data(); |
|
61 | 61 | void addSeries(); |
|
62 | 62 | void animationOptions_data(); |
|
63 | 63 | void animationOptions(); |
|
64 | 64 | void axisX_data(); |
|
65 | 65 | void axisX(); |
|
66 | 66 | void axisY_data(); |
|
67 | 67 | void axisY(); |
|
68 | 68 | void backgroundBrush_data(); |
|
69 | 69 | void backgroundBrush(); |
|
70 | 70 | void backgroundPen_data(); |
|
71 | 71 | void backgroundPen(); |
|
72 | 72 | void isBackgroundVisible_data(); |
|
73 | 73 | void isBackgroundVisible(); |
|
74 | 74 | void legend_data(); |
|
75 | 75 | void legend(); |
|
76 | 76 | void plotArea_data(); |
|
77 | 77 | void plotArea(); |
|
78 | 78 | void removeAllSeries_data(); |
|
79 | 79 | void removeAllSeries(); |
|
80 | 80 | void removeSeries_data(); |
|
81 | 81 | void removeSeries(); |
|
82 | 82 | void scroll_right_data(); |
|
83 | 83 | void scroll_right(); |
|
84 | 84 | void scroll_left_data(); |
|
85 | 85 | void scroll_left(); |
|
86 | 86 | void scroll_up_data(); |
|
87 | 87 | void scroll_up(); |
|
88 | 88 | void scroll_down_data(); |
|
89 | 89 | void scroll_down(); |
|
90 | 90 | void theme_data(); |
|
91 | 91 | void theme(); |
|
92 | 92 | void title_data(); |
|
93 | 93 | void title(); |
|
94 | 94 | void titleBrush_data(); |
|
95 | 95 | void titleBrush(); |
|
96 | 96 | void titleFont_data(); |
|
97 | 97 | void titleFont(); |
|
98 | 98 | void zoomIn_data(); |
|
99 | 99 | void zoomIn(); |
|
100 | 100 | void zoomOut_data(); |
|
101 | 101 | void zoomOut(); |
|
102 | ||
|
102 | void createDefaultAxesForLineSeries_data(); | |
|
103 | void createDefaultAxesForLineSeries(); | |
|
103 | 104 | private: |
|
104 | 105 | void createTestData(); |
|
105 | 106 | |
|
106 | 107 | private: |
|
107 | 108 | QChartView* m_view; |
|
108 | 109 | QChart* m_chart; |
|
109 | 110 | }; |
|
110 | 111 | |
|
111 | 112 | void tst_QChart::initTestCase() |
|
112 | 113 | { |
|
113 | 114 | |
|
114 | 115 | } |
|
115 | 116 | |
|
116 | 117 | void tst_QChart::cleanupTestCase() |
|
117 | 118 | { |
|
118 | 119 | |
|
119 | 120 | } |
|
120 | 121 | |
|
121 | 122 | void tst_QChart::init() |
|
122 | 123 | { |
|
123 | 124 | m_view = new QChartView(new QChart()); |
|
124 | 125 | m_chart = m_view->chart(); |
|
125 | 126 | } |
|
126 | 127 | |
|
127 | 128 | void tst_QChart::cleanup() |
|
128 | 129 | { |
|
129 | 130 | delete m_view; |
|
130 | 131 | m_view = 0; |
|
131 | 132 | m_chart = 0; |
|
132 | 133 | } |
|
133 | 134 | |
|
134 | 135 | |
|
135 | 136 | void tst_QChart::createTestData() |
|
136 | 137 | { |
|
137 | 138 | QLineSeries* series0 = new QLineSeries(this); |
|
138 | 139 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
139 | 140 | m_chart->addSeries(series0); |
|
140 | 141 | m_view->show(); |
|
141 | 142 | QTest::qWaitForWindowShown(m_view); |
|
142 | 143 | } |
|
143 | 144 | |
|
144 | 145 | void tst_QChart::qchart_data() |
|
145 | 146 | { |
|
146 | 147 | } |
|
147 | 148 | |
|
148 | 149 | void tst_QChart::qchart() |
|
149 | 150 | { |
|
150 | 151 | QVERIFY(m_chart); |
|
151 | 152 | QVERIFY(m_chart->legend()); |
|
152 | 153 | QVERIFY(m_chart->legend()->isVisible()); |
|
153 | 154 | |
|
154 | 155 | QCOMPARE(m_chart->animationOptions(), QChart::NoAnimation); |
|
155 | 156 | QVERIFY(!m_chart->axisX()); |
|
156 | 157 | QVERIFY(!m_chart->axisY()); |
|
157 | 158 | QVERIFY(m_chart->backgroundBrush()!=QBrush()); |
|
158 | 159 | QVERIFY(m_chart->backgroundPen()!=QPen()); |
|
159 | 160 | QCOMPARE(m_chart->isBackgroundVisible(), true); |
|
160 | 161 | QVERIFY(m_chart->plotArea().top()==0); |
|
161 | 162 | QVERIFY(m_chart->plotArea().left()==0); |
|
162 | 163 | QVERIFY(m_chart->plotArea().right()==0); |
|
163 | 164 | QVERIFY(m_chart->plotArea().bottom()==0); |
|
164 | 165 | QCOMPARE(m_chart->theme(), QChart::ChartThemeLight); |
|
165 | 166 | QCOMPARE(m_chart->title(), QString()); |
|
166 | 167 | |
|
167 | 168 | //QCOMPARE(m_chart->titleBrush(),QBrush()); |
|
168 | 169 | //QCOMPARE(m_chart->titleFont(),QFont()); |
|
169 | 170 | |
|
170 | 171 | m_chart->removeAllSeries(); |
|
171 | 172 | m_chart->scroll(0,0); |
|
172 | 173 | |
|
173 | 174 | m_chart->zoomIn(); |
|
174 | 175 | m_chart->zoomIn(QRectF()); |
|
175 | 176 | m_chart->zoomOut(); |
|
176 | 177 | |
|
177 | 178 | m_view->show(); |
|
178 | 179 | |
|
179 | 180 | QVERIFY(m_chart->plotArea().top()>0); |
|
180 | 181 | QVERIFY(m_chart->plotArea().left()>0); |
|
181 | 182 | QVERIFY(m_chart->plotArea().right()>0); |
|
182 | 183 | QVERIFY(m_chart->plotArea().bottom()>0); |
|
183 | 184 | } |
|
184 | 185 | |
|
185 | 186 | void tst_QChart::addSeries_data() |
|
186 | 187 | { |
|
187 | 188 | QTest::addColumn<QAbstractSeries *>("series"); |
|
188 | 189 | |
|
189 | 190 | QAbstractSeries* line = new QLineSeries(this); |
|
190 | 191 | QAbstractSeries* area = new QAreaSeries(static_cast<QLineSeries*>(line)); |
|
191 | 192 | QAbstractSeries* scatter = new QScatterSeries(this); |
|
192 | 193 | QAbstractSeries* spline = new QSplineSeries(this); |
|
193 | 194 | QAbstractSeries* pie = new QPieSeries(this); |
|
194 | 195 | QAbstractSeries* bar = new QBarSeries(this); |
|
195 | 196 | QAbstractSeries* percent = new QPercentBarSeries(this); |
|
196 | 197 | QAbstractSeries* stacked = new QStackedBarSeries(this); |
|
197 | 198 | |
|
198 | 199 | QTest::newRow("lineSeries") << line; |
|
199 | 200 | QTest::newRow("areaSeries") << area; |
|
200 | 201 | QTest::newRow("scatterSeries") << scatter; |
|
201 | 202 | QTest::newRow("splineSeries") << spline; |
|
202 | 203 | QTest::newRow("pieSeries") << pie; |
|
203 | 204 | QTest::newRow("barSeries") << bar; |
|
204 | 205 | QTest::newRow("percentBarSeries") << percent; |
|
205 | 206 | QTest::newRow("stackedBarSeries") << stacked; |
|
206 | 207 | |
|
207 | 208 | } |
|
208 | 209 | |
|
209 | 210 | void tst_QChart::addSeries() |
|
210 | 211 | { |
|
211 | 212 | QFETCH(QAbstractSeries *, series); |
|
212 | 213 | m_view->show(); |
|
213 | 214 | QTest::qWaitForWindowShown(m_view); |
|
214 | 215 | QVERIFY(!series->chart()); |
|
215 | 216 | QCOMPARE(m_chart->series().count(), 0); |
|
216 | 217 | m_chart->addSeries(series); |
|
217 | 218 | QCOMPARE(m_chart->series().count(), 1); |
|
218 | 219 | QCOMPARE(m_chart->series().first(), series); |
|
219 | 220 | QVERIFY(series->chart() == m_chart); |
|
220 | 221 | m_chart->createDefaultAxes(); |
|
221 | 222 | if(series->type()!=QAbstractSeries::SeriesTypePie){ |
|
222 | 223 | QVERIFY(m_chart->axisY(series)); |
|
223 | 224 | QVERIFY(m_chart->axisX(series)); |
|
224 | 225 | }else{ |
|
225 | 226 | QVERIFY(!m_chart->axisY(series)); |
|
226 | 227 | QVERIFY(!m_chart->axisX(series)); |
|
227 | 228 | } |
|
228 | 229 | m_chart->removeSeries(series); |
|
229 | 230 | QVERIFY(!series->chart()); |
|
230 | 231 | QCOMPARE(m_chart->series().count(), 0); |
|
231 | 232 | } |
|
232 | 233 | |
|
233 | 234 | void tst_QChart::animationOptions_data() |
|
234 | 235 | { |
|
235 | 236 | QTest::addColumn<QChart::AnimationOption>("animationOptions"); |
|
236 | 237 | QTest::newRow("AllAnimations") << QChart::AllAnimations; |
|
237 | 238 | QTest::newRow("NoAnimation") << QChart::NoAnimation; |
|
238 | 239 | QTest::newRow("GridAxisAnimations") << QChart::GridAxisAnimations; |
|
239 | 240 | QTest::newRow("SeriesAnimations") << QChart::SeriesAnimations; |
|
240 | 241 | } |
|
241 | 242 | |
|
242 | 243 | void tst_QChart::animationOptions() |
|
243 | 244 | { |
|
244 | 245 | createTestData(); |
|
245 | 246 | QFETCH(QChart::AnimationOption, animationOptions); |
|
246 | 247 | m_chart->setAnimationOptions(animationOptions); |
|
247 | 248 | QCOMPARE(m_chart->animationOptions(), animationOptions); |
|
248 | 249 | } |
|
249 | 250 | |
|
250 | 251 | void tst_QChart::axisX_data() |
|
251 | 252 | { |
|
252 | 253 | |
|
253 | 254 | QTest::addColumn<QAbstractAxis*>("axis"); |
|
254 | 255 | QTest::addColumn<QAbstractSeries *>("series"); |
|
255 | 256 | |
|
256 | 257 | QTest::newRow("categories,lineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
257 | 258 | QTest::newRow("categories,areaSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
258 | 259 | QTest::newRow("categories,scatterSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
259 | 260 | QTest::newRow("categories,splineSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
260 | 261 | QTest::newRow("categories,pieSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
261 | 262 | QTest::newRow("categories,barSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
262 | 263 | QTest::newRow("categories,percentBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
263 | 264 | QTest::newRow("categories,stackedBarSeries") << (QAbstractAxis*) new QBarCategoryAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
264 | 265 | |
|
265 | 266 | QTest::newRow("value,lineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QLineSeries(this); |
|
266 | 267 | QTest::newRow("value,areaSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QAreaSeries(new QLineSeries(this)); |
|
267 | 268 | QTest::newRow("value,scatterSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QScatterSeries(this); |
|
268 | 269 | QTest::newRow("value,splineSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QSplineSeries(this); |
|
269 | 270 | QTest::newRow("value,pieSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPieSeries(this); |
|
270 | 271 | QTest::newRow("value,barSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QBarSeries(this); |
|
271 | 272 | QTest::newRow("value,percentBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QPercentBarSeries(this); |
|
272 | 273 | QTest::newRow("value,stackedBarSeries") << (QAbstractAxis*) new QValueAxis() << (QAbstractSeries*) new QStackedBarSeries(this); |
|
273 | 274 | |
|
274 | 275 | } |
|
275 | 276 | |
|
276 | 277 | void tst_QChart::axisX() |
|
277 | 278 | { |
|
278 | 279 | QFETCH(QAbstractAxis*, axis); |
|
279 | 280 | QFETCH(QAbstractSeries*, series); |
|
280 | 281 | QVERIFY(!m_chart->axisX()); |
|
281 | 282 | m_view->show(); |
|
282 | 283 | QTest::qWaitForWindowShown(m_view); |
|
283 | 284 | m_chart->addSeries(series); |
|
284 | 285 | m_chart->setAxisX(axis,series); |
|
285 | 286 | QVERIFY(m_chart->axisX(series)==axis); |
|
286 | 287 | } |
|
287 | 288 | |
|
288 | 289 | void tst_QChart::axisY_data() |
|
289 | 290 | { |
|
290 | 291 | axisX_data(); |
|
291 | 292 | } |
|
292 | 293 | |
|
293 | 294 | |
|
294 | 295 | void tst_QChart::axisY() |
|
295 | 296 | { |
|
296 | 297 | QFETCH(QAbstractAxis*, axis); |
|
297 | 298 | QFETCH(QAbstractSeries*, series); |
|
298 | 299 | QVERIFY(!m_chart->axisY()); |
|
299 | 300 | m_view->show(); |
|
300 | 301 | QTest::qWaitForWindowShown(m_view); |
|
301 | 302 | m_chart->addSeries(series); |
|
302 | 303 | m_chart->setAxisY(axis,series); |
|
303 | 304 | QVERIFY(m_chart->axisY(series)==axis); |
|
304 | 305 | } |
|
305 | 306 | |
|
306 | 307 | void tst_QChart::backgroundBrush_data() |
|
307 | 308 | { |
|
308 | 309 | QTest::addColumn<QBrush>("backgroundBrush"); |
|
309 | 310 | QTest::newRow("null") << QBrush(); |
|
310 | 311 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
311 | 312 | QTest::newRow("white") << QBrush(Qt::white); |
|
312 | 313 | QTest::newRow("black") << QBrush(Qt::black); |
|
313 | 314 | } |
|
314 | 315 | |
|
315 | 316 | void tst_QChart::backgroundBrush() |
|
316 | 317 | { |
|
317 | 318 | QFETCH(QBrush, backgroundBrush); |
|
318 | 319 | m_chart->setBackgroundBrush(backgroundBrush); |
|
319 | 320 | QCOMPARE(m_chart->backgroundBrush(), backgroundBrush); |
|
320 | 321 | } |
|
321 | 322 | |
|
322 | 323 | void tst_QChart::backgroundPen_data() |
|
323 | 324 | { |
|
324 | 325 | QTest::addColumn<QPen>("backgroundPen"); |
|
325 | 326 | QTest::newRow("null") << QPen(); |
|
326 | 327 | QTest::newRow("blue") << QPen(Qt::blue); |
|
327 | 328 | QTest::newRow("white") << QPen(Qt::white); |
|
328 | 329 | QTest::newRow("black") << QPen(Qt::black); |
|
329 | 330 | } |
|
330 | 331 | |
|
331 | 332 | |
|
332 | 333 | void tst_QChart::backgroundPen() |
|
333 | 334 | { |
|
334 | 335 | QFETCH(QPen, backgroundPen); |
|
335 | 336 | m_chart->setBackgroundPen(backgroundPen); |
|
336 | 337 | QCOMPARE(m_chart->backgroundPen(), backgroundPen); |
|
337 | 338 | } |
|
338 | 339 | |
|
339 | 340 | void tst_QChart::isBackgroundVisible_data() |
|
340 | 341 | { |
|
341 | 342 | QTest::addColumn<bool>("isBackgroundVisible"); |
|
342 | 343 | QTest::newRow("true") << true; |
|
343 | 344 | QTest::newRow("false") << false; |
|
344 | 345 | } |
|
345 | 346 | |
|
346 | 347 | void tst_QChart::isBackgroundVisible() |
|
347 | 348 | { |
|
348 | 349 | QFETCH(bool, isBackgroundVisible); |
|
349 | 350 | m_chart->setBackgroundVisible(isBackgroundVisible); |
|
350 | 351 | QCOMPARE(m_chart->isBackgroundVisible(), isBackgroundVisible); |
|
351 | 352 | } |
|
352 | 353 | |
|
353 | 354 | void tst_QChart::legend_data() |
|
354 | 355 | { |
|
355 | 356 | |
|
356 | 357 | } |
|
357 | 358 | |
|
358 | 359 | void tst_QChart::legend() |
|
359 | 360 | { |
|
360 | 361 | QLegend *legend = m_chart->legend(); |
|
361 | 362 | QVERIFY(legend); |
|
362 | 363 | |
|
363 | 364 | // Colors related signals |
|
364 | 365 | QSignalSpy colorSpy(legend, SIGNAL(colorChanged(QColor))); |
|
365 | 366 | QSignalSpy borderColorSpy(legend, SIGNAL(borderColorChanged(QColor))); |
|
366 | 367 | QSignalSpy labelColorSpy(legend, SIGNAL(labelColorChanged(QColor))); |
|
367 | 368 | |
|
368 | 369 | // colorChanged |
|
369 | 370 | legend->setColor(QColor("aliceblue")); |
|
370 | 371 | QCOMPARE(colorSpy.count(), 1); |
|
371 | 372 | QBrush b = legend->brush(); |
|
372 | 373 | b.setColor(QColor("aqua")); |
|
373 | 374 | legend->setBrush(b); |
|
374 | 375 | QCOMPARE(colorSpy.count(), 2); |
|
375 | 376 | |
|
376 | 377 | // borderColorChanged |
|
377 | 378 | legend->setBorderColor(QColor("aliceblue")); |
|
378 | 379 | QCOMPARE(borderColorSpy.count(), 1); |
|
379 | 380 | QPen p = legend->pen(); |
|
380 | 381 | p.setColor(QColor("aqua")); |
|
381 | 382 | legend->setPen(p); |
|
382 | 383 | QCOMPARE(borderColorSpy.count(), 2); |
|
383 | 384 | |
|
384 | 385 | // labelColorChanged |
|
385 | 386 | legend->setLabelColor(QColor("lightsalmon")); |
|
386 | 387 | QCOMPARE(labelColorSpy.count(), 1); |
|
387 | 388 | b = legend->labelBrush(); |
|
388 | 389 | b.setColor(QColor("lightseagreen")); |
|
389 | 390 | legend->setLabelBrush(b); |
|
390 | 391 | QCOMPARE(labelColorSpy.count(), 2); |
|
391 | 392 | |
|
392 | 393 | // fontChanged |
|
393 | 394 | QSignalSpy fontSpy(legend, SIGNAL(fontChanged(QFont))); |
|
394 | 395 | QFont f = legend->font(); |
|
395 | 396 | f.setBold(!f.bold()); |
|
396 | 397 | legend->setFont(f); |
|
397 | 398 | QCOMPARE(fontSpy.count(), 1); |
|
398 | 399 | } |
|
399 | 400 | |
|
400 | 401 | void tst_QChart::plotArea_data() |
|
401 | 402 | { |
|
402 | 403 | |
|
403 | 404 | } |
|
404 | 405 | |
|
405 | 406 | void tst_QChart::plotArea() |
|
406 | 407 | { |
|
407 | 408 | createTestData(); |
|
408 | 409 | QRectF rect = m_chart->geometry(); |
|
409 | 410 | QVERIFY(m_chart->plotArea().isValid()); |
|
410 | 411 | QVERIFY(m_chart->plotArea().height() < rect.height()); |
|
411 | 412 | QVERIFY(m_chart->plotArea().width() < rect.width()); |
|
412 | 413 | } |
|
413 | 414 | |
|
414 | 415 | void tst_QChart::removeAllSeries_data() |
|
415 | 416 | { |
|
416 | 417 | |
|
417 | 418 | } |
|
418 | 419 | |
|
419 | 420 | void tst_QChart::removeAllSeries() |
|
420 | 421 | { |
|
421 | 422 | QLineSeries* series0 = new QLineSeries(this); |
|
422 | 423 | QLineSeries* series1 = new QLineSeries(this); |
|
423 | 424 | QLineSeries* series2 = new QLineSeries(this); |
|
424 | 425 | QSignalSpy deleteSpy1(series0, SIGNAL(destroyed())); |
|
425 | 426 | QSignalSpy deleteSpy2(series1, SIGNAL(destroyed())); |
|
426 | 427 | QSignalSpy deleteSpy3(series2, SIGNAL(destroyed())); |
|
427 | 428 | |
|
428 | 429 | m_chart->addSeries(series0); |
|
429 | 430 | m_chart->addSeries(series1); |
|
430 | 431 | m_chart->addSeries(series2); |
|
431 | 432 | m_view->show(); |
|
432 | 433 | QTest::qWaitForWindowShown(m_view); |
|
433 | 434 | m_chart->createDefaultAxes(); |
|
434 | 435 | QCOMPARE(m_chart->axes().count(), 2); |
|
435 | 436 | QVERIFY(m_chart->axisY(series0)!=0); |
|
436 | 437 | QVERIFY(m_chart->axisY(series1)!=0); |
|
437 | 438 | QVERIFY(m_chart->axisY(series2)!=0); |
|
438 | 439 | |
|
439 | 440 | m_chart->removeAllSeries(); |
|
440 | 441 | QCOMPARE(m_chart->axes().count(), 2); |
|
441 | 442 | QVERIFY(m_chart->axisX() != 0); |
|
442 | 443 | QVERIFY(m_chart->axisY() != 0); |
|
443 | 444 | QCOMPARE(deleteSpy1.count(), 1); |
|
444 | 445 | QCOMPARE(deleteSpy2.count(), 1); |
|
445 | 446 | QCOMPARE(deleteSpy3.count(), 1); |
|
446 | 447 | } |
|
447 | 448 | |
|
448 | 449 | void tst_QChart::removeSeries_data() |
|
449 | 450 | { |
|
450 | 451 | axisX_data(); |
|
451 | 452 | } |
|
452 | 453 | |
|
453 | 454 | void tst_QChart::removeSeries() |
|
454 | 455 | { |
|
455 | 456 | QFETCH(QAbstractAxis *, axis); |
|
456 | 457 | QFETCH(QAbstractSeries *, series); |
|
457 | 458 | QSignalSpy deleteSpy(series, SIGNAL(destroyed())); |
|
458 | 459 | m_view->show(); |
|
459 | 460 | QTest::qWaitForWindowShown(m_view); |
|
460 | 461 | if(!axis) axis = m_chart->axisY(); |
|
461 | 462 | m_chart->addSeries(series); |
|
462 | 463 | m_chart->setAxisY(axis,series); |
|
463 | 464 | QCOMPARE(m_chart->axisY(series),axis); |
|
464 | 465 | m_chart->removeSeries(series); |
|
465 | 466 | QCOMPARE(m_chart->axes().count(), 1); |
|
466 | 467 | QVERIFY(m_chart->axisY() != 0); |
|
467 | 468 | QVERIFY(m_chart->axisY(series)==0); |
|
468 | 469 | QCOMPARE(deleteSpy.count(), 0); |
|
469 | 470 | } |
|
470 | 471 | |
|
471 | 472 | void tst_QChart::scroll_right_data() |
|
472 | 473 | { |
|
473 | 474 | QTest::addColumn<QAbstractSeries *>("series"); |
|
474 | 475 | |
|
475 | 476 | QLineSeries* series0 = new QLineSeries(this); |
|
476 | 477 | *series0 << QPointF(0, 0) << QPointF(100, 100); |
|
477 | 478 | |
|
478 | 479 | QTest::newRow("lineSeries") << (QAbstractSeries*) series0; |
|
479 | 480 | |
|
480 | 481 | |
|
481 | 482 | } |
|
482 | 483 | |
|
483 | 484 | void tst_QChart::scroll_right() |
|
484 | 485 | { |
|
485 | 486 | QFETCH(QAbstractSeries *, series); |
|
486 | 487 | m_chart->addSeries(series); |
|
487 | 488 | m_chart->createDefaultAxes(); |
|
488 | 489 | m_view->show(); |
|
489 | 490 | QTest::qWaitForWindowShown(m_view); |
|
490 | 491 | QAbstractAxis * axis = m_chart->axisX(); |
|
491 | 492 | QVERIFY(axis!=0); |
|
492 | 493 | |
|
493 | 494 | switch(axis->type()) |
|
494 | 495 | { |
|
495 | 496 | case QAbstractAxis::AxisTypeValue:{ |
|
496 | 497 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
497 | 498 | QVERIFY(vaxis!=0); |
|
498 | 499 | qreal min = vaxis->min(); |
|
499 | 500 | qreal max = vaxis->max(); |
|
500 | 501 | QVERIFY(max>min); |
|
501 | 502 | m_chart->scroll(50, 0); |
|
502 | 503 | QVERIFY(min<vaxis->min()); |
|
503 | 504 | QVERIFY(max<vaxis->max()); |
|
504 | 505 | break; |
|
505 | 506 | } |
|
506 | 507 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
507 | 508 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
508 | 509 | QVERIFY(caxis!=0); |
|
509 | 510 | qreal min = caxis->min().toDouble(); |
|
510 | 511 | qreal max = caxis->max().toDouble(); |
|
511 | 512 | m_chart->scroll(50, 0); |
|
512 | 513 | QVERIFY(min<caxis->min().toDouble()); |
|
513 | 514 | QVERIFY(max<caxis->max().toDouble()); |
|
514 | 515 | break; |
|
515 | 516 | } |
|
516 | 517 | default: |
|
517 | 518 | qFatal("Unsupported type"); |
|
518 | 519 | break; |
|
519 | 520 | } |
|
520 | 521 | } |
|
521 | 522 | |
|
522 | 523 | void tst_QChart::scroll_left_data() |
|
523 | 524 | { |
|
524 | 525 | scroll_right_data(); |
|
525 | 526 | } |
|
526 | 527 | |
|
527 | 528 | void tst_QChart::scroll_left() |
|
528 | 529 | { |
|
529 | 530 | QFETCH(QAbstractSeries *, series); |
|
530 | 531 | m_chart->addSeries(series); |
|
531 | 532 | m_chart->createDefaultAxes(); |
|
532 | 533 | m_view->show(); |
|
533 | 534 | QTest::qWaitForWindowShown(m_view); |
|
534 | 535 | QAbstractAxis * axis = m_chart->axisX(); |
|
535 | 536 | QVERIFY(axis!=0); |
|
536 | 537 | |
|
537 | 538 | switch(axis->type()) |
|
538 | 539 | { |
|
539 | 540 | case QAbstractAxis::AxisTypeValue:{ |
|
540 | 541 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
541 | 542 | QVERIFY(vaxis!=0); |
|
542 | 543 | qreal min = vaxis->min(); |
|
543 | 544 | qreal max = vaxis->max(); |
|
544 | 545 | m_chart->scroll(-50, 0); |
|
545 | 546 | QVERIFY(min>vaxis->min()); |
|
546 | 547 | QVERIFY(max>vaxis->max()); |
|
547 | 548 | break; |
|
548 | 549 | } |
|
549 | 550 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
550 | 551 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
551 | 552 | QVERIFY(caxis!=0); |
|
552 | 553 | qreal min = caxis->min().toDouble(); |
|
553 | 554 | qreal max = caxis->max().toDouble(); |
|
554 | 555 | m_chart->scroll(-50, 0); |
|
555 | 556 | QVERIFY(min>caxis->min().toDouble()); |
|
556 | 557 | QVERIFY(max>caxis->max().toDouble()); |
|
557 | 558 | break; |
|
558 | 559 | } |
|
559 | 560 | default: |
|
560 | 561 | qFatal("Unsupported type"); |
|
561 | 562 | break; |
|
562 | 563 | } |
|
563 | 564 | } |
|
564 | 565 | |
|
565 | 566 | void tst_QChart::scroll_up_data() |
|
566 | 567 | { |
|
567 | 568 | scroll_right_data(); |
|
568 | 569 | } |
|
569 | 570 | |
|
570 | 571 | void tst_QChart::scroll_up() |
|
571 | 572 | { |
|
572 | 573 | QFETCH(QAbstractSeries *, series); |
|
573 | 574 | m_chart->addSeries(series); |
|
574 | 575 | m_chart->createDefaultAxes(); |
|
575 | 576 | m_view->show(); |
|
576 | 577 | QTest::qWaitForWindowShown(m_view); |
|
577 | 578 | QAbstractAxis * axis = m_chart->axisY(); |
|
578 | 579 | QVERIFY(axis!=0); |
|
579 | 580 | |
|
580 | 581 | switch(axis->type()) |
|
581 | 582 | { |
|
582 | 583 | case QAbstractAxis::AxisTypeValue:{ |
|
583 | 584 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
584 | 585 | QVERIFY(vaxis!=0); |
|
585 | 586 | qreal min = vaxis->min(); |
|
586 | 587 | qreal max = vaxis->max(); |
|
587 | 588 | m_chart->scroll(0, 50); |
|
588 | 589 | QVERIFY(min<vaxis->min()); |
|
589 | 590 | QVERIFY(max<vaxis->max()); |
|
590 | 591 | break; |
|
591 | 592 | } |
|
592 | 593 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
593 | 594 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
594 | 595 | QVERIFY(caxis!=0); |
|
595 | 596 | qreal min = caxis->min().toDouble(); |
|
596 | 597 | qreal max = caxis->max().toDouble(); |
|
597 | 598 | m_chart->scroll(0, 50); |
|
598 | 599 | QVERIFY(min<caxis->min().toDouble()); |
|
599 | 600 | QVERIFY(max<caxis->max().toDouble()); |
|
600 | 601 | break; |
|
601 | 602 | } |
|
602 | 603 | default: |
|
603 | 604 | qFatal("Unsupported type"); |
|
604 | 605 | break; |
|
605 | 606 | } |
|
606 | 607 | } |
|
607 | 608 | |
|
608 | 609 | void tst_QChart::scroll_down_data() |
|
609 | 610 | { |
|
610 | 611 | scroll_right_data(); |
|
611 | 612 | } |
|
612 | 613 | |
|
613 | 614 | void tst_QChart::scroll_down() |
|
614 | 615 | { |
|
615 | 616 | QFETCH(QAbstractSeries *, series); |
|
616 | 617 | m_chart->addSeries(series); |
|
617 | 618 | m_chart->createDefaultAxes(); |
|
618 | 619 | m_view->show(); |
|
619 | 620 | QTest::qWaitForWindowShown(m_view); |
|
620 | 621 | QAbstractAxis * axis = m_chart->axisY(); |
|
621 | 622 | QVERIFY(axis!=0); |
|
622 | 623 | |
|
623 | 624 | switch(axis->type()) |
|
624 | 625 | { |
|
625 | 626 | case QAbstractAxis::AxisTypeValue:{ |
|
626 | 627 | QValueAxis* vaxis = qobject_cast<QValueAxis*>(axis); |
|
627 | 628 | QVERIFY(vaxis!=0); |
|
628 | 629 | qreal min = vaxis->min(); |
|
629 | 630 | qreal max = vaxis->max(); |
|
630 | 631 | m_chart->scroll(0, -50); |
|
631 | 632 | QVERIFY(min>vaxis->min()); |
|
632 | 633 | QVERIFY(max>vaxis->max()); |
|
633 | 634 | break; |
|
634 | 635 | } |
|
635 | 636 | case QAbstractAxis::AxisTypeBarCategory:{ |
|
636 | 637 | QBarCategoryAxis* caxis = qobject_cast<QBarCategoryAxis*>(axis); |
|
637 | 638 | QVERIFY(caxis!=0); |
|
638 | 639 | qreal min = caxis->min().toDouble(); |
|
639 | 640 | qreal max = caxis->max().toDouble(); |
|
640 | 641 | m_chart->scroll(0, -50); |
|
641 | 642 | QVERIFY(min>caxis->min().toDouble()); |
|
642 | 643 | QVERIFY(max>caxis->max().toDouble()); |
|
643 | 644 | break; |
|
644 | 645 | } |
|
645 | 646 | default: |
|
646 | 647 | qFatal("Unsupported type"); |
|
647 | 648 | break; |
|
648 | 649 | } |
|
649 | 650 | } |
|
650 | 651 | |
|
651 | 652 | void tst_QChart::theme_data() |
|
652 | 653 | { |
|
653 | 654 | QTest::addColumn<QChart::ChartTheme>("theme"); |
|
654 | 655 | QTest::newRow("ChartThemeBlueCerulean") << QChart::ChartThemeBlueCerulean; |
|
655 | 656 | QTest::newRow("ChartThemeBlueIcy") << QChart::ChartThemeBlueIcy; |
|
656 | 657 | QTest::newRow("ChartThemeBlueNcs") << QChart::ChartThemeBlueNcs; |
|
657 | 658 | QTest::newRow("ChartThemeBrownSand") << QChart::ChartThemeBrownSand; |
|
658 | 659 | QTest::newRow("ChartThemeDark") << QChart::ChartThemeDark; |
|
659 | 660 | QTest::newRow("hartThemeHighContrast") << QChart::ChartThemeHighContrast; |
|
660 | 661 | QTest::newRow("ChartThemeLight") << QChart::ChartThemeLight; |
|
661 | 662 | } |
|
662 | 663 | |
|
663 | 664 | void tst_QChart::theme() |
|
664 | 665 | { |
|
665 | 666 | QFETCH(QChart::ChartTheme, theme); |
|
666 | 667 | createTestData(); |
|
667 | 668 | m_chart->setTheme(theme); |
|
668 | 669 | QVERIFY(m_chart->theme()==theme); |
|
669 | 670 | } |
|
670 | 671 | |
|
671 | 672 | void tst_QChart::title_data() |
|
672 | 673 | { |
|
673 | 674 | QTest::addColumn<QString>("title"); |
|
674 | 675 | QTest::newRow("null") << QString(); |
|
675 | 676 | QTest::newRow("foo") << QString("foo"); |
|
676 | 677 | } |
|
677 | 678 | |
|
678 | 679 | void tst_QChart::title() |
|
679 | 680 | { |
|
680 | 681 | QFETCH(QString, title); |
|
681 | 682 | m_chart->setTitle(title); |
|
682 | 683 | QCOMPARE(m_chart->title(), title); |
|
683 | 684 | } |
|
684 | 685 | |
|
685 | 686 | void tst_QChart::titleBrush_data() |
|
686 | 687 | { |
|
687 | 688 | QTest::addColumn<QBrush>("titleBrush"); |
|
688 | 689 | QTest::newRow("null") << QBrush(); |
|
689 | 690 | QTest::newRow("blue") << QBrush(Qt::blue); |
|
690 | 691 | QTest::newRow("white") << QBrush(Qt::white); |
|
691 | 692 | QTest::newRow("black") << QBrush(Qt::black); |
|
692 | 693 | } |
|
693 | 694 | |
|
694 | 695 | void tst_QChart::titleBrush() |
|
695 | 696 | { |
|
696 | 697 | QFETCH(QBrush, titleBrush); |
|
697 | 698 | m_chart->setTitleBrush(titleBrush); |
|
698 | 699 | QCOMPARE(m_chart->titleBrush(), titleBrush); |
|
699 | 700 | } |
|
700 | 701 | |
|
701 | 702 | void tst_QChart::titleFont_data() |
|
702 | 703 | { |
|
703 | 704 | QTest::addColumn<QFont>("titleFont"); |
|
704 | 705 | QTest::newRow("null") << QFont(); |
|
705 | 706 | QTest::newRow("courier") << QFont("Courier", 8, QFont::Bold, true); |
|
706 | 707 | } |
|
707 | 708 | |
|
708 | 709 | void tst_QChart::titleFont() |
|
709 | 710 | { |
|
710 | 711 | QFETCH(QFont, titleFont); |
|
711 | 712 | m_chart->setTitleFont(titleFont); |
|
712 | 713 | QCOMPARE(m_chart->titleFont(), titleFont); |
|
713 | 714 | } |
|
714 | 715 | |
|
715 | 716 | void tst_QChart::zoomIn_data() |
|
716 | 717 | { |
|
717 | 718 | QTest::addColumn<QRectF>("rect"); |
|
718 | 719 | QTest::newRow("null") << QRectF(); |
|
719 | 720 | QTest::newRow("100x100") << QRectF(10,10,100,100); |
|
720 | 721 | QTest::newRow("200x200") << QRectF(10,10,200,200); |
|
721 | 722 | } |
|
722 | 723 | |
|
723 | 724 | |
|
724 | 725 | void tst_QChart::zoomIn() |
|
725 | 726 | { |
|
726 | 727 | |
|
727 | 728 | QFETCH(QRectF, rect); |
|
728 | 729 | createTestData(); |
|
729 | 730 | m_chart->createDefaultAxes(); |
|
730 | 731 | QRectF marigns = m_chart->plotArea(); |
|
731 | 732 | rect.adjust(marigns.left(),marigns.top(),-marigns.right(),-marigns.bottom()); |
|
732 | 733 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
733 | 734 | QVERIFY(axisX!=0); |
|
734 | 735 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
735 | 736 | QVERIFY(axisY!=0); |
|
736 | 737 | qreal minX = axisX->min(); |
|
737 | 738 | qreal minY = axisY->min(); |
|
738 | 739 | qreal maxX = axisX->max(); |
|
739 | 740 | qreal maxY = axisY->max(); |
|
740 | 741 | m_chart->zoomIn(rect); |
|
741 | 742 | if(rect.isValid()){ |
|
742 | 743 | QVERIFY(minX<axisX->min()); |
|
743 | 744 | QVERIFY(maxX>axisX->max()); |
|
744 | 745 | QVERIFY(minY<axisY->min()); |
|
745 | 746 | QVERIFY(maxY>axisY->max()); |
|
746 | 747 | } |
|
747 | 748 | |
|
748 | 749 | } |
|
749 | 750 | |
|
750 | 751 | void tst_QChart::zoomOut_data() |
|
751 | 752 | { |
|
752 | 753 | |
|
753 | 754 | } |
|
754 | 755 | |
|
755 | 756 | void tst_QChart::zoomOut() |
|
756 | 757 | { |
|
757 | 758 | createTestData(); |
|
758 | 759 | m_chart->createDefaultAxes(); |
|
759 | 760 | |
|
760 | 761 | QValueAxis* axisX = qobject_cast<QValueAxis*>(m_chart->axisX()); |
|
761 | 762 | QVERIFY(axisX!=0); |
|
762 | 763 | QValueAxis* axisY = qobject_cast<QValueAxis*>(m_chart->axisY()); |
|
763 | 764 | QVERIFY(axisY!=0); |
|
764 | 765 | |
|
765 | 766 | qreal minX = axisX->min(); |
|
766 | 767 | qreal minY = axisY->min(); |
|
767 | 768 | qreal maxX = axisX->max(); |
|
768 | 769 | qreal maxY = axisY->max(); |
|
769 | 770 | |
|
770 | 771 | m_chart->zoomIn(); |
|
771 | 772 | |
|
772 | 773 | QVERIFY(minX < axisX->min()); |
|
773 | 774 | QVERIFY(maxX > axisX->max()); |
|
774 | 775 | QVERIFY(minY < axisY->min()); |
|
775 | 776 | QVERIFY(maxY > axisY->max()); |
|
776 | 777 | |
|
777 | 778 | m_chart->zoomOut(); |
|
778 | 779 | |
|
779 | 780 | // min x may be a zero value |
|
780 | 781 | if (qFuzzyIsNull(minX)) |
|
781 | 782 | QVERIFY(qFuzzyIsNull(axisX->min())); |
|
782 | 783 | else |
|
783 | 784 | QCOMPARE(minX, axisX->min()); |
|
784 | 785 | |
|
785 | 786 | // min y may be a zero value |
|
786 | 787 | if (qFuzzyIsNull(minY)) |
|
787 | 788 | QVERIFY(qFuzzyIsNull(axisY->min())); |
|
788 | 789 | else |
|
789 | 790 | QCOMPARE(minY, axisY->min()); |
|
790 | 791 | |
|
791 | 792 | QVERIFY(maxX == axisX->max()); |
|
792 | 793 | QVERIFY(maxY == axisY->max()); |
|
793 | 794 | |
|
794 | 795 | } |
|
795 | 796 | |
|
797 | void tst_QChart::createDefaultAxesForLineSeries_data() | |
|
798 | { | |
|
799 | QTest::addColumn<qreal>("series1minX"); | |
|
800 | QTest::addColumn<qreal>("series1midX"); | |
|
801 | QTest::addColumn<qreal>("series1maxX"); | |
|
802 | QTest::addColumn<qreal>("series2minX"); | |
|
803 | QTest::addColumn<qreal>("series2midX"); | |
|
804 | QTest::addColumn<qreal>("series2maxX"); | |
|
805 | QTest::addColumn<qreal>("overallminX"); | |
|
806 | QTest::addColumn<qreal>("overallmaxX"); | |
|
807 | QTest::addColumn<qreal>("series1minY"); | |
|
808 | QTest::addColumn<qreal>("series1midY"); | |
|
809 | QTest::addColumn<qreal>("series1maxY"); | |
|
810 | QTest::addColumn<qreal>("series2minY"); | |
|
811 | QTest::addColumn<qreal>("series2midY"); | |
|
812 | QTest::addColumn<qreal>("series2maxY"); | |
|
813 | QTest::addColumn<qreal>("overallminY"); | |
|
814 | QTest::addColumn<qreal>("overallmaxY"); | |
|
815 | QTest::newRow("series1hasMinAndMax") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 | |
|
816 | << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0; | |
|
817 | QTest::newRow("series2hasMinAndMax") << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 | |
|
818 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
|
819 | QTest::newRow("series1hasMinAndMaxX_series2hasMinAndMaxY") << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.1 << (qreal)1.7 << (qreal)2.9 << (qreal)1.0 << (qreal)3.0 | |
|
820 | << (qreal)1.1 << (qreal)2.0 << (qreal)2.9 << (qreal)1.0 << (qreal)2.0 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
|
821 | QTest::newRow("series1hasMin_series2hasMax") << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0 | |
|
822 | << (qreal)1.0 << (qreal)2.0 << (qreal)2.9 << (qreal)1.1 << (qreal)1.7 << (qreal)3.0 << (qreal)1.0 << (qreal)3.0; | |
|
823 | } | |
|
824 | ||
|
825 | void tst_QChart::createDefaultAxesForLineSeries() | |
|
826 | { | |
|
827 | QFETCH(qreal, series1minX); | |
|
828 | QFETCH(qreal, series1midX); | |
|
829 | QFETCH(qreal, series1maxX); | |
|
830 | QFETCH(qreal, series2minX); | |
|
831 | QFETCH(qreal, series2midX); | |
|
832 | QFETCH(qreal, series2maxX); | |
|
833 | QFETCH(qreal, series1minY); | |
|
834 | QFETCH(qreal, series1midY); | |
|
835 | QFETCH(qreal, series1maxY); | |
|
836 | QFETCH(qreal, series2minY); | |
|
837 | QFETCH(qreal, series2midY); | |
|
838 | QFETCH(qreal, series2maxY); | |
|
839 | QFETCH(qreal, overallminX); | |
|
840 | QFETCH(qreal, overallmaxX); | |
|
841 | QFETCH(qreal, overallminY); | |
|
842 | QFETCH(qreal, overallmaxY); | |
|
843 | QLineSeries* series1 = new QLineSeries(this); | |
|
844 | series1->append(series1minX, series1minY); | |
|
845 | series1->append(series1midX, series1midY); | |
|
846 | series1->append(series1maxX, series1maxY); | |
|
847 | QLineSeries* series2 = new QLineSeries(this); | |
|
848 | series2->append(series2minX, series2minY); | |
|
849 | series2->append(series2midX, series2midY); | |
|
850 | series2->append(series2maxX, series2maxY); | |
|
851 | QChart chart; | |
|
852 | chart.addSeries(series1); | |
|
853 | chart.addSeries(series2); | |
|
854 | chart.createDefaultAxes(); | |
|
855 | QValueAxis *xAxis = (QValueAxis *)chart.axisX(); | |
|
856 | QCOMPARE(xAxis->min(), overallminX); | |
|
857 | QCOMPARE(xAxis->max(), overallmaxX); | |
|
858 | QValueAxis *yAxis = (QValueAxis *)chart.axisY(); | |
|
859 | QCOMPARE(yAxis->min(), overallminY); | |
|
860 | QCOMPARE(yAxis->max(), overallmaxY); | |
|
861 | QLineSeries *series3 = new QLineSeries(this); | |
|
862 | // Numbers clearly out of existing range | |
|
863 | series3->append(0, 0); | |
|
864 | series3->append(100, 100); | |
|
865 | // Adding a new series should not change the axes as they have not been told to update | |
|
866 | chart.addSeries(series3); | |
|
867 | QCOMPARE(xAxis->min(), overallminX); | |
|
868 | QCOMPARE(xAxis->max(), overallmaxX); | |
|
869 | QCOMPARE(yAxis->min(), overallminY); | |
|
870 | QCOMPARE(yAxis->max(), overallmaxY); | |
|
871 | ||
|
872 | } | |
|
873 | ||
|
796 | 874 | QTEST_MAIN(tst_QChart) |
|
797 | 875 | #include "tst_qchart.moc" |
|
798 | 876 |
General Comments 0
You need to be logged in to leave comments.
Login now