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