##// END OF EJS Templates
Fixes nicenumbers missing update issue
Michal Klocek -
r1738:0029a831c085
parent child
Show More
@@ -1,381 +1,384
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 "qvaluesaxis.h"
21 #include "qvaluesaxis.h"
22 #include "qvaluesaxis_p.h"
22 #include "qvaluesaxis_p.h"
23 #include "chartvaluesaxisx_p.h"
23 #include "chartvaluesaxisx_p.h"
24 #include "chartvaluesaxisy_p.h"
24 #include "chartvaluesaxisy_p.h"
25 #include "domain_p.h"
25 #include "domain_p.h"
26 #include "chartdataset_p.h"
26 #include "chartdataset_p.h"
27 #include <qmath.h>
27 #include <qmath.h>
28
28
29
29
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 QTCOMMERCIALCHART_BEGIN_NAMESPACE
31 /*!
31 /*!
32 \class QValuesAxis
32 \class QValuesAxis
33 \brief The QValuesAxis class is used for manipulating chart's axis.
33 \brief The QValuesAxis class is used for manipulating chart's axis.
34 \mainclass
34 \mainclass
35
35
36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
37 Values of axis are drawn to position of ticks
37 Values of axis are drawn to position of ticks
38 */
38 */
39
39
40 /*!
40 /*!
41 \qmlclass ValuesAxis QValuesAxis
41 \qmlclass ValuesAxis QValuesAxis
42 \brief The ValuesAxis element is used for manipulating chart's axes
42 \brief The ValuesAxis element is used for manipulating chart's axes
43
43
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
45 Values of axis are drawn to position of ticks
45 Values of axis are drawn to position of ticks
46
46
47 To access Axes you can use ChartView API. For example:
47 To access Axes you can use ChartView API. For example:
48 \code
48 \code
49 ChartView {
49 ChartView {
50 ValuesAxis {
50 ValuesAxis {
51 id: xAxis
51 id: xAxis
52 min: 0
52 min: 0
53 max: 10
53 max: 10
54 }
54 }
55 // Add a few series...
55 // Add a few series...
56 }
56 }
57 \endcode
57 \endcode
58 */
58 */
59
59
60 /*!
60 /*!
61 \property QValuesAxis::min
61 \property QValuesAxis::min
62 Defines the minimum value on the axis.
62 Defines the minimum value on the axis.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
63 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
64 */
64 */
65 /*!
65 /*!
66 \qmlproperty real ValuesAxis::min
66 \qmlproperty real ValuesAxis::min
67 Defines the minimum value on the axis.
67 Defines the minimum value on the axis.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
68 When setting this property the max is adjusted if necessary, to ensure that the range remains valid.
69 */
69 */
70
70
71 /*!
71 /*!
72 \property QValuesAxis::max
72 \property QValuesAxis::max
73 Defines the maximum value on the axis.
73 Defines the maximum value on the axis.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
74 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
75 */
75 */
76 /*!
76 /*!
77 \qmlproperty real ValuesAxis::max
77 \qmlproperty real ValuesAxis::max
78 Defines the maximum value on the axis.
78 Defines the maximum value on the axis.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
79 When setting this property the min is adjusted if necessary, to ensure that the range remains valid.
80 */
80 */
81
81
82 /*!
82 /*!
83 \fn void QValuesAxis::minChanged(qreal min)
83 \fn void QValuesAxis::minChanged(qreal min)
84 Axis emits signal when \a min of axis has changed.
84 Axis emits signal when \a min of axis has changed.
85 */
85 */
86 /*!
86 /*!
87 \qmlsignal ValuesAxis::onMinChanged(real min)
87 \qmlsignal ValuesAxis::onMinChanged(real min)
88 Axis emits signal when \a min of axis has changed.
88 Axis emits signal when \a min of axis has changed.
89 */
89 */
90
90
91 /*!
91 /*!
92 \fn void QValuesAxis::maxChanged(qreal max)
92 \fn void QValuesAxis::maxChanged(qreal max)
93 Axis emits signal when \a max of axis has changed.
93 Axis emits signal when \a max of axis has changed.
94 */
94 */
95 /*!
95 /*!
96 \qmlsignal ValuesAxis::onMaxChanged(real max)
96 \qmlsignal ValuesAxis::onMaxChanged(real max)
97 Axis emits signal when \a max of axis has changed.
97 Axis emits signal when \a max of axis has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
101 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
102 Axis emits signal when \a min or \a max of axis has changed.
102 Axis emits signal when \a min or \a max of axis has changed.
103 */
103 */
104
104
105 /*!
105 /*!
106 \property QValuesAxis::ticksCount
106 \property QValuesAxis::ticksCount
107 The number of tick marks for the axis.
107 The number of tick marks for the axis.
108 */
108 */
109
109
110 /*!
110 /*!
111 \qmlproperty int ValuesAxis::ticksCount
111 \qmlproperty int ValuesAxis::ticksCount
112 The number of tick marks for the axis.
112 The number of tick marks for the axis.
113 */
113 */
114
114
115 /*!
115 /*!
116 \property QValuesAxis::niceNumbersEnabled
116 \property QValuesAxis::niceNumbersEnabled
117 Whether the nice numbers algorithm is enabled or not for the axis.
117 Whether the nice numbers algorithm is enabled or not for the axis.
118 */
118 */
119
119
120 /*!
120 /*!
121 \qmlproperty bool ValuesAxis::niceNumbersEnabled
121 \qmlproperty bool ValuesAxis::niceNumbersEnabled
122 Whether the nice numbers algorithm is enabled or not for the axis.
122 Whether the nice numbers algorithm is enabled or not for the axis.
123 */
123 */
124
124
125 /*!
125 /*!
126 Constructs an axis object which is a child of \a parent.
126 Constructs an axis object which is a child of \a parent.
127 */
127 */
128 QValuesAxis::QValuesAxis(QObject *parent) :
128 QValuesAxis::QValuesAxis(QObject *parent) :
129 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
129 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
130 {
130 {
131
131
132 }
132 }
133
133
134 /*!
134 /*!
135 \internal
135 \internal
136 */
136 */
137 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
137 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
138 {
138 {
139
139
140 }
140 }
141
141
142 /*!
142 /*!
143 Destroys the object
143 Destroys the object
144 */
144 */
145 QValuesAxis::~QValuesAxis()
145 QValuesAxis::~QValuesAxis()
146 {
146 {
147 Q_D(QValuesAxis);
147 Q_D(QValuesAxis);
148 if(d->m_dataset) {
148 if(d->m_dataset) {
149 d->m_dataset->removeAxis(this);
149 d->m_dataset->removeAxis(this);
150 }
150 }
151 }
151 }
152
152
153 void QValuesAxis::setMin(qreal min)
153 void QValuesAxis::setMin(qreal min)
154 {
154 {
155 Q_D(QValuesAxis);
155 Q_D(QValuesAxis);
156 setRange(min, qMax(d->m_max, min));
156 setRange(min, qMax(d->m_max, min));
157 }
157 }
158
158
159 qreal QValuesAxis::min() const
159 qreal QValuesAxis::min() const
160 {
160 {
161 Q_D(const QValuesAxis);
161 Q_D(const QValuesAxis);
162 return d->m_min;
162 return d->m_min;
163 }
163 }
164
164
165 void QValuesAxis::setMax(qreal max)
165 void QValuesAxis::setMax(qreal max)
166 {
166 {
167 Q_D(QValuesAxis);
167 Q_D(QValuesAxis);
168 setRange(qMin(d->m_min, max), max);
168 setRange(qMin(d->m_min, max), max);
169 }
169 }
170
170
171 qreal QValuesAxis::max() const
171 qreal QValuesAxis::max() const
172 {
172 {
173 Q_D(const QValuesAxis);
173 Q_D(const QValuesAxis);
174 return d->m_max;
174 return d->m_max;
175 }
175 }
176
176
177 /*!
177 /*!
178 Sets range from \a min to \a max on the axis.
178 Sets range from \a min to \a max on the axis.
179 If min is greater than max then this function returns without making any changes.
179 If min is greater than max then this function returns without making any changes.
180 */
180 */
181 void QValuesAxis::setRange(qreal min, qreal max)
181 void QValuesAxis::setRange(qreal min, qreal max)
182 {
182 {
183 if(max<min) return;
184
185 Q_D(QValuesAxis);
183 Q_D(QValuesAxis);
186 bool changed = false;
184 bool changed = false;
187
185
188 if (min > max)
186 if (min > max) return;
189 return;
187
188 if(d->m_niceNumbers) {
189 int ticks = d->m_tickCount;
190 d->looseNiceNumbers(min, max, ticks);
191 if(ticks!=d->m_tickCount) setTicksCount(ticks);
192 }
190
193
191 if (!qFuzzyIsNull(d->m_min - min)) {
194 if (!qFuzzyIsNull(d->m_min - min)) {
192 d->m_min = min;
195 d->m_min = min;
193 changed = true;
196 changed = true;
194 emit minChanged(min);
197 emit minChanged(min);
195 }
198 }
196
199
197 if (!qFuzzyIsNull(d->m_max - max)) {
200 if (!qFuzzyIsNull(d->m_max - max)) {
198 d->m_max = max;
201 d->m_max = max;
199 changed = true;
202 changed = true;
200 emit maxChanged(max);
203 emit maxChanged(max);
201 }
204 }
202
205
203 if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
204
205 if (changed) {
206 if (changed) {
206 emit rangeChanged(d->m_min,d->m_max);
207 emit rangeChanged(min,max);
207 d->emitUpdated();
208 d->emitUpdated();
208 }
209 }
209 }
210 }
210
211
211 /*!
212 /*!
212 Sets \a count for ticks on the axis.
213 Sets \a count for ticks on the axis.
213 */
214 */
214 void QValuesAxis::setTicksCount(int count)
215 void QValuesAxis::setTicksCount(int count)
215 {
216 {
216 Q_D(QValuesAxis);
217 Q_D(QValuesAxis);
217 if (d->m_tickCount != count && count >=2) {
218 if (d->m_tickCount != count && count >=2) {
218 d->m_tickCount = count;
219 d->m_tickCount = count;
219 d->emitUpdated();
220 d->emitUpdated();
220 }
221 }
221 }
222 }
222
223
223 /*!
224 /*!
224 \fn int QValuesAxis::ticksCount() const
225 \fn int QValuesAxis::ticksCount() const
225 Return number of ticks on the axis
226 Return number of ticks on the axis
226 */
227 */
227 int QValuesAxis::ticksCount() const
228 int QValuesAxis::ticksCount() const
228 {
229 {
229 Q_D(const QValuesAxis);
230 Q_D(const QValuesAxis);
230 return d->m_tickCount;
231 return d->m_tickCount;
231 }
232 }
232
233
233 void QValuesAxis::setNiceNumbersEnabled(bool enable)
234 void QValuesAxis::setNiceNumbersEnabled(bool enable)
234 {
235 {
235 Q_D(QValuesAxis);
236 Q_D(QValuesAxis);
236 if (d->m_niceNumbers != enable){
237 if (d->m_niceNumbers != enable){
237 d->m_niceNumbers = enable;
238 d->m_niceNumbers = enable;
238 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) setRange(d->min(),d->max());
239 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) {
240 setRange(d->m_min,d->m_max);
241 }
239 }
242 }
240 }
243 }
241
244
242 bool QValuesAxis::niceNumbersEnabled() const
245 bool QValuesAxis::niceNumbersEnabled() const
243 {
246 {
244 Q_D(const QValuesAxis);
247 Q_D(const QValuesAxis);
245 return d->m_niceNumbers;
248 return d->m_niceNumbers;
246 }
249 }
247
250
248 /*!
251 /*!
249 Returns the type of the axis
252 Returns the type of the axis
250 */
253 */
251 QAbstractAxis::AxisType QValuesAxis::type() const
254 QAbstractAxis::AxisType QValuesAxis::type() const
252 {
255 {
253 return AxisTypeValues;
256 return AxisTypeValues;
254 }
257 }
255
258
256 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
259 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
257
260
258 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
261 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
259 QAbstractAxisPrivate(q),
262 QAbstractAxisPrivate(q),
260 m_min(0),
263 m_min(0),
261 m_max(0),
264 m_max(0),
262 m_tickCount(5),
265 m_tickCount(5),
263 m_niceNumbers(false)
266 m_niceNumbers(false)
264 {
267 {
265
268
266 }
269 }
267
270
268 QValuesAxisPrivate::~QValuesAxisPrivate()
271 QValuesAxisPrivate::~QValuesAxisPrivate()
269 {
272 {
270
273
271 }
274 }
272
275
273 void QValuesAxisPrivate::handleDomainUpdated()
276 void QValuesAxisPrivate::handleDomainUpdated()
274 {
277 {
275 Q_Q(QValuesAxis);
278 Q_Q(QValuesAxis);
276 Domain* domain = qobject_cast<Domain*>(sender());
279 Domain* domain = qobject_cast<Domain*>(sender());
277 Q_ASSERT(domain);
280 Q_ASSERT(domain);
278
281
279 if(orientation()==Qt::Horizontal){
282 if(orientation()==Qt::Horizontal){
280 q->setRange(domain->minX(),domain->maxX());
283 q->setRange(domain->minX(),domain->maxX());
281 }else if(orientation()==Qt::Vertical){
284 }else if(orientation()==Qt::Vertical){
282 q->setRange(domain->minY(),domain->maxY());
285 q->setRange(domain->minY(),domain->maxY());
283 }
286 }
284 }
287 }
285
288
286
289
287 void QValuesAxisPrivate::setMin(const QVariant &min)
290 void QValuesAxisPrivate::setMin(const QVariant &min)
288 {
291 {
289 Q_Q(QValuesAxis);
292 Q_Q(QValuesAxis);
290 bool ok;
293 bool ok;
291 qreal value = min.toReal(&ok);
294 qreal value = min.toReal(&ok);
292 if(ok) q->setMin(value);
295 if(ok) q->setMin(value);
293 }
296 }
294
297
295 void QValuesAxisPrivate::setMax(const QVariant &max)
298 void QValuesAxisPrivate::setMax(const QVariant &max)
296 {
299 {
297
300
298 Q_Q(QValuesAxis);
301 Q_Q(QValuesAxis);
299 bool ok;
302 bool ok;
300 qreal value = max.toReal(&ok);
303 qreal value = max.toReal(&ok);
301 if(ok) q->setMax(value);
304 if(ok) q->setMax(value);
302 }
305 }
303
306
304 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
307 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
305 {
308 {
306 Q_Q(QValuesAxis);
309 Q_Q(QValuesAxis);
307 bool ok1;
310 bool ok1;
308 bool ok2;
311 bool ok2;
309 qreal value1 = min.toReal(&ok1);
312 qreal value1 = min.toReal(&ok1);
310 qreal value2 = max.toReal(&ok2);
313 qreal value2 = max.toReal(&ok2);
311 if(ok1&&ok2) q->setRange(value1,value2);
314 if(ok1&&ok2) q->setRange(value1,value2);
312 }
315 }
313
316
314 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
317 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
315 {
318 {
316 Q_Q(QValuesAxis);
319 Q_Q(QValuesAxis);
317 if(m_orientation == Qt::Vertical){
320 if(m_orientation == Qt::Vertical){
318 return new ChartValuesAxisY(q,presenter);
321 return new ChartValuesAxisY(q,presenter);
319 }else{
322 }else{
320 return new ChartValuesAxisX(q,presenter);
323 return new ChartValuesAxisX(q,presenter);
321 }
324 }
322
325
323 }
326 }
324
327
325 void QValuesAxisPrivate::intializeDomain(Domain* domain)
328 void QValuesAxisPrivate::intializeDomain(Domain* domain)
326 {
329 {
327 Q_Q(QValuesAxis);
330 Q_Q(QValuesAxis);
328 if(qFuzzyCompare(m_max,m_min)) {
331 if(qFuzzyCompare(m_max,m_min)) {
329 if(m_orientation==Qt::Vertical){
332 if(m_orientation==Qt::Vertical){
330 q->setRange(domain->minY(),domain->maxY());
333 q->setRange(domain->minY(),domain->maxY());
331 }else{
334 }else{
332 q->setRange(domain->minX(), domain->maxX());
335 q->setRange(domain->minX(), domain->maxX());
333 }
336 }
334 } else {
337 } else {
335 if(m_orientation==Qt::Vertical){
338 if(m_orientation==Qt::Vertical){
336 domain->setRangeY(m_min, m_max);
339 domain->setRangeY(m_min, m_max);
337 }else{
340 }else{
338 domain->setRangeX(m_min, m_max);
341 domain->setRangeX(m_min, m_max);
339 }
342 }
340 }
343 }
341 }
344 }
342
345
343 //algorithm defined by Paul S.Heckbert GraphicalGems I
346 //algorithm defined by Paul S.Heckbert GraphicalGems I
344
347
345 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
348 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
346 {
349 {
347 qreal range = niceNumber(max-min,true); //range with ceiling
350 qreal range = niceNumber(max-min,true); //range with ceiling
348 qreal step = niceNumber(range/(ticksCount-1),false);
351 qreal step = niceNumber(range/(ticksCount-1),false);
349 min = qFloor(min/step);
352 min = qFloor(min/step);
350 max = qCeil(max/step);
353 max = qCeil(max/step);
351 ticksCount = int(max-min) +1;
354 ticksCount = int(max-min) +1;
352 min*=step;
355 min*=step;
353 max*=step;
356 max*=step;
354 }
357 }
355
358
356 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
359 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
357
360
358 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
361 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
359 {
362 {
360 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
363 qreal z = qPow(10,qFloor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
361 qreal q = x/z;//q<10 && q>=1;
364 qreal q = x/z;//q<10 && q>=1;
362
365
363 if(ceiling) {
366 if(ceiling) {
364 if(q <= 1.0) q=1;
367 if(q <= 1.0) q=1;
365 else if(q <= 2.0) q=2;
368 else if(q <= 2.0) q=2;
366 else if(q <= 5.0) q=5;
369 else if(q <= 5.0) q=5;
367 else q=10;
370 else q=10;
368 }
371 }
369 else {
372 else {
370 if(q < 1.5) q=1;
373 if(q < 1.5) q=1;
371 else if(q < 3.0) q=2;
374 else if(q < 3.0) q=2;
372 else if(q < 7.0) q=5;
375 else if(q < 7.0) q=5;
373 else q=10;
376 else q=10;
374 }
377 }
375 return q*z;
378 return q*z;
376 }
379 }
377
380
378 #include "moc_qvaluesaxis.cpp"
381 #include "moc_qvaluesaxis.cpp"
379 #include "moc_qvaluesaxis_p.cpp"
382 #include "moc_qvaluesaxis_p.cpp"
380
383
381 QTCOMMERCIALCHART_END_NAMESPACE
384 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,472 +1,484
1 /****************************************************************************
1 /****************************************************************************
2 **
2 **
3 ** Copyright (C) 2012 Digia Plc
3 ** Copyright (C) 2012 Digia Plc
4 ** All rights reserved.
4 ** All rights reserved.
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
5 ** For any questions to Digia, please use contact form at http://qt.digia.com
6 **
6 **
7 ** This file is part of the Qt Commercial Charts Add-on.
7 ** This file is part of the Qt Commercial Charts Add-on.
8 **
8 **
9 ** $QT_BEGIN_LICENSE$
9 ** $QT_BEGIN_LICENSE$
10 ** Licensees holding valid Qt Commercial licenses may use this file in
10 ** Licensees holding valid Qt Commercial licenses may use this file in
11 ** accordance with the Qt Commercial License Agreement provided with the
11 ** accordance with the Qt Commercial License Agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.
13 ** a written agreement between you and Digia.
14 **
14 **
15 ** If you have questions regarding the use of this file, please use
15 ** If you have questions regarding the use of this file, please use
16 ** contact form at http://qt.digia.com
16 ** contact form at http://qt.digia.com
17 ** $QT_END_LICENSE$
17 ** $QT_END_LICENSE$
18 **
18 **
19 ****************************************************************************/
19 ****************************************************************************/
20
20
21 #include "chartdataset_p.h"
21 #include "chartdataset_p.h"
22 #include "qchart.h"
22 #include "qchart.h"
23 #include "qvaluesaxis.h"
23 #include "qvaluesaxis.h"
24 #include "qbarcategoriesaxis.h"
24 #include "qbarcategoriesaxis.h"
25 #include "qvaluesaxis_p.h"
25 #include "qvaluesaxis_p.h"
26 #include "qintervalsaxis.h"
26 #include "qintervalsaxis.h"
27 #include "qdatetimeaxis.h"
27 #include "qdatetimeaxis.h"
28 #include "qabstractseries_p.h"
28 #include "qabstractseries_p.h"
29 #include "qabstractbarseries.h"
29 #include "qabstractbarseries.h"
30 #include "qstackedbarseries.h"
30 #include "qstackedbarseries.h"
31 #include "qpercentbarseries.h"
31 #include "qpercentbarseries.h"
32 #include "qpieseries.h"
32 #include "qpieseries.h"
33
33
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
34 QTCOMMERCIALCHART_BEGIN_NAMESPACE
35
35
36 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
36 ChartDataSet::ChartDataSet(QChart *parent):QObject(parent)
37 {
37 {
38
38
39 }
39 }
40
40
41 ChartDataSet::~ChartDataSet()
41 ChartDataSet::~ChartDataSet()
42 {
42 {
43 removeAllSeries();
43 removeAllSeries();
44 }
44 }
45
45
46 void ChartDataSet::addSeries(QAbstractSeries* series)
46 void ChartDataSet::addSeries(QAbstractSeries* series)
47 {
47 {
48 Domain* domain = m_seriesDomainMap.value(series);
48 Domain* domain = m_seriesDomainMap.value(series);
49
49
50 if(domain) {
50 if(domain) {
51 qWarning() << "Can not add series. Series already on the chart";
51 qWarning() << "Can not add series. Series already on the chart";
52 return;
52 return;
53 }
53 }
54
54
55 domain = new Domain(series);
55 domain = new Domain(series);
56 m_seriesDomainMap.insert(series,domain);
56 m_seriesDomainMap.insert(series,domain);
57 series->d_ptr->scaleDomain(*domain);
57 series->d_ptr->scaleDomain(*domain);
58
58
59 createSeriesIndex(series);
59 createSeriesIndex(series);
60
60
61 series->setParent(this); // take ownership
61 series->setParent(this); // take ownership
62 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
62 series->d_ptr->m_chart = qobject_cast<QChart*>(parent());
63 series->d_ptr->m_dataset = this;
63 series->d_ptr->m_dataset = this;
64
64
65 emit seriesAdded(series,domain);
65 emit seriesAdded(series,domain);
66
66
67 }
67 }
68
68
69 void ChartDataSet::removeSeries(QAbstractSeries* series)
69 void ChartDataSet::removeSeries(QAbstractSeries* series)
70 {
70 {
71
71
72 if(!m_seriesDomainMap.contains(series)) {
72 if(!m_seriesDomainMap.contains(series)) {
73 qWarning()<<"Can not remove series. Series not found on the chart.";
73 qWarning()<<"Can not remove series. Series not found on the chart.";
74 return;
74 return;
75 }
75 }
76
76
77 emit seriesRemoved(series);
77 emit seriesRemoved(series);
78
78
79 Domain* domain = m_seriesDomainMap.take(series);
79 Domain* domain = m_seriesDomainMap.take(series);
80 delete domain;
80 delete domain;
81 domain = 0;
81 domain = 0;
82
82
83 removeSeriesIndex(series);
83 removeSeriesIndex(series);
84
84
85 series->setParent(0);
85 series->setParent(0);
86 series->d_ptr->m_chart = 0;
86 series->d_ptr->m_chart = 0;
87 series->d_ptr->m_dataset = 0;
87 series->d_ptr->m_dataset = 0;
88
88
89 removeAxes(series);
89 removeAxes(series);
90 }
90 }
91
91
92
92
93
93
94 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
94 void ChartDataSet::createSeriesIndex(QAbstractSeries* series)
95 {
95 {
96 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
96 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
97
97
98 int key=0;
98 int key=0;
99 while (i.hasNext()) {
99 while (i.hasNext()) {
100 i.next();
100 i.next();
101 if(i.key()!=key) {
101 if(i.key()!=key) {
102 break;
102 break;
103 }
103 }
104 key++;
104 key++;
105 }
105 }
106
106
107 m_indexSeriesMap.insert(key,series);
107 m_indexSeriesMap.insert(key,series);
108 }
108 }
109
109
110 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
110 void ChartDataSet::removeSeriesIndex(QAbstractSeries* series)
111 {
111 {
112 int key = seriesIndex(series);
112 int key = seriesIndex(series);
113 Q_ASSERT(key!=-1);
113 Q_ASSERT(key!=-1);
114 m_indexSeriesMap.remove(key);
114 m_indexSeriesMap.remove(key);
115 }
115 }
116
116
117 void ChartDataSet::createDefaultAxes()
117 void ChartDataSet::createDefaultAxes()
118 {
118 {
119
119
120 if(m_seriesDomainMap.isEmpty()) return;
120 if(m_seriesDomainMap.isEmpty()) return;
121
121
122 QAbstractAxis::AxisTypes typeX(0);
122 QAbstractAxis::AxisTypes typeX(0);
123 QAbstractAxis::AxisTypes typeY(0);
123 QAbstractAxis::AxisTypes typeY(0);
124
124
125 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
125 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
126 while (i.hasNext()) {
126 while (i.hasNext()) {
127 i.next();
127 i.next();
128 removeAxes(i.key());
128 removeAxes(i.key());
129 }
129 }
130
130
131 i.toFront();
131 i.toFront();
132
132
133 while (i.hasNext()) {
133 while (i.hasNext()) {
134 i.next();
134 i.next();
135 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
135 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
136 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
136 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
137 if(axisX) typeX&=axisX->type();
137 if(axisX) typeX&=axisX->type();
138 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
138 else typeX|=i.key()->d_ptr->defaultAxisType(Qt::Horizontal);
139 if(axisY) typeY&=axisY->type();
139 if(axisY) typeY&=axisY->type();
140 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
140 else typeY|=i.key()->d_ptr->defaultAxisType(Qt::Vertical);
141 }
141 }
142
142
143 createAxes(typeX,Qt::Horizontal);
143 createAxes(typeX,Qt::Horizontal);
144 createAxes(typeY,Qt::Vertical);
144 createAxes(typeY,Qt::Vertical);
145 }
145 }
146
146
147 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
147 void ChartDataSet::createAxes(QAbstractAxis::AxisTypes type,Qt::Orientation orientation)
148 {
148 {
149 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
149 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
150
150
151 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
151 if(type.testFlag(QAbstractAxis::AxisTypeValues) && type.testFlag(QAbstractAxis::AxisTypeCategories))
152 {
152 {
153 while (i.hasNext()) {
153 while (i.hasNext()) {
154 i.next();
154 i.next();
155 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
155 QAbstractAxis* axis = createAxis(i.key()->d_ptr->defaultAxisType(orientation),orientation);
156 if(!axis) continue;
156 if(!axis) continue;
157 initializeAxis(axis,i.key());
157 initializeAxis(axis,i.key());
158 emit axisAdded(axis,i.value());
158 emit axisAdded(axis,i.value());
159 }
159 }
160
160
161 }
161 }
162 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
162 else if(!type.testFlag(QAbstractAxis::AxisTypeNoAxis)) {
163 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
163 QAbstractAxis* axis = createAxis(QAbstractAxis::AxisType(int(type)),orientation);
164 i.toFront();
164 i.toFront();
165 while (i.hasNext()) {
165 while (i.hasNext()) {
166 i.next();
166 i.next();
167 initializeAxis(axis,i.key());
167 initializeAxis(axis,i.key());
168 }
168 }
169 emit axisAdded(axis,i.value());
169 emit axisAdded(axis,i.value());
170 }
170 }
171 }
171 }
172
172
173
173
174 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
174 QAbstractAxis* ChartDataSet::createAxis(QAbstractAxis::AxisType type,Qt::Orientation orientation)
175 {
175 {
176 QAbstractAxis* axis =0;
176 QAbstractAxis* axis =0;
177
177
178 switch(type) {
178 switch(type) {
179 case QAbstractAxis::AxisTypeValues:
179 case QAbstractAxis::AxisTypeValues:
180 axis = new QValuesAxis(this);
180 axis = new QValuesAxis(this);
181 break;
181 break;
182 case QAbstractAxis::AxisTypeCategories:
182 case QAbstractAxis::AxisTypeCategories:
183 axis = new QBarCategoriesAxis(this);
183 axis = new QBarCategoriesAxis(this);
184 break;
184 break;
185 case QAbstractAxis::AxisTypeIntervals:
185 case QAbstractAxis::AxisTypeIntervals:
186 axis = new QIntervalsAxis(this);
186 axis = new QIntervalsAxis(this);
187 break;
187 break;
188 case QAbstractAxis::AxisTypeDateTime:
188 case QAbstractAxis::AxisTypeDateTime:
189 axis = new QDateTimeAxis(this);
189 axis = new QDateTimeAxis(this);
190 break;
190 break;
191 default:
191 default:
192 axis = 0;
192 axis = 0;
193 break;
193 break;
194 }
194 }
195
195
196 if(axis)
196 if(axis)
197 axis->d_ptr->setOrientation(orientation);
197 axis->d_ptr->setOrientation(orientation);
198
198
199 return axis;
199 return axis;
200 }
200 }
201
201
202 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
202 void ChartDataSet::initializeAxis(QAbstractAxis* axis,QAbstractSeries* series)
203 {
203 {
204 Domain* domain = m_seriesDomainMap.value(series);
204 Domain* domain = m_seriesDomainMap.value(series);
205 axis->d_ptr->m_dataset = this;
205 axis->d_ptr->m_dataset = this;
206 axis->d_ptr->intializeDomain(domain);
206 axis->d_ptr->intializeDomain(domain);
207 series->d_ptr->initializeAxis(axis);
207 series->d_ptr->initializeAxis(axis);
208 if(axis->orientation()==Qt::Horizontal) {
208 if(axis->orientation()==Qt::Horizontal) {
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
209 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
210 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
211 m_seriesAxisXMap.insert(series,axis);
211 m_seriesAxisXMap.insert(series,axis);
212 }
212 }
213 else {
213 else {
214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
214 QObject::connect(axis->d_ptr.data(),SIGNAL(updated()),domain,SLOT(handleAxisUpdated()));
215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
215 QObject::connect(domain,SIGNAL(updated()),axis->d_ptr.data(),SLOT(handleDomainUpdated()));
216 m_seriesAxisYMap.insert(series,axis);
216 m_seriesAxisYMap.insert(series,axis);
217 }
217 }
218 axis->d_ptr->emitUpdated();
218 axis->d_ptr->emitUpdated();
219 }
219 }
220
220
221 void ChartDataSet::removeAxes(QAbstractSeries* series)
221 void ChartDataSet::removeAxes(QAbstractSeries* series)
222 {
222 {
223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
223 QAbstractAxis* axisX = m_seriesAxisXMap.take(series);
224
224
225 if(axisX) {
225 if(axisX) {
226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
226 QList<QAbstractAxis*> axesX = m_seriesAxisXMap.values();
227 int x = axesX.indexOf(axisX);
227 int x = axesX.indexOf(axisX);
228
228
229 if(x==-1) {
229 if(x==-1) {
230 emit axisRemoved(axisX);
230 emit axisRemoved(axisX);
231 axisX->d_ptr->m_dataset=0;
231 axisX->d_ptr->m_dataset=0;
232 axisX->deleteLater();
232 axisX->deleteLater();
233 }
233 }
234 }
234 }
235
235
236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
236 QAbstractAxis* axisY = m_seriesAxisYMap.take(series);
237
237
238 if(axisY) {
238 if(axisY) {
239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
239 QList<QAbstractAxis*> axesY = m_seriesAxisYMap.values();
240
240
241 int y = axesY.indexOf(axisY);
241 int y = axesY.indexOf(axisY);
242
242
243 if(y==-1) {
243 if(y==-1) {
244 emit axisRemoved(axisY);
244 emit axisRemoved(axisY);
245 axisY->d_ptr->m_dataset=0;
245 axisY->d_ptr->m_dataset=0;
246 axisY->deleteLater();
246 axisY->deleteLater();
247 }
247 }
248 }
248 }
249 }
249 }
250
250
251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
251 void ChartDataSet::removeAxis(QAbstractAxis* axis)
252 {
252 {
253 if(!axis->d_ptr->m_dataset) {
253 if(!axis->d_ptr->m_dataset) {
254 qWarning()<<"UnBound axis found !";
254 qWarning()<<"UnBound axis found !";
255 return;
255 return;
256 }
256 }
257
257
258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
258 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
259
259
260 if(axis->orientation()==Qt::Vertical) {
260 if(axis->orientation()==Qt::Vertical) {
261 seriesAxisMap= &m_seriesAxisYMap;
261 seriesAxisMap= &m_seriesAxisYMap;
262 }
262 }
263 else {
263 else {
264 seriesAxisMap= &m_seriesAxisXMap;
264 seriesAxisMap= &m_seriesAxisXMap;
265 }
265 }
266
266
267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
267 QMapIterator<QAbstractSeries*, QAbstractAxis*> i(*seriesAxisMap);
268
268
269 while (i.hasNext()) {
269 while (i.hasNext()) {
270 i.next();
270 i.next();
271 if(i.value()==axis) {
271 if(i.value()==axis) {
272 removeSeries(i.key());
272 removeSeries(i.key());
273 }
273 }
274 }
274 }
275 }
275 }
276
276
277 void ChartDataSet::removeAllSeries()
277 void ChartDataSet::removeAllSeries()
278 {
278 {
279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
279 QList<QAbstractSeries*> series = m_seriesDomainMap.keys();
280 foreach(QAbstractSeries *s , series) {
280 foreach(QAbstractSeries *s , series) {
281 removeSeries(s);
281 removeSeries(s);
282 }
282 }
283
283
284 Q_ASSERT(m_seriesAxisXMap.count()==0);
284 Q_ASSERT(m_seriesAxisXMap.count()==0);
285 Q_ASSERT(m_seriesAxisXMap.count()==0);
285 Q_ASSERT(m_seriesAxisXMap.count()==0);
286 Q_ASSERT(m_seriesDomainMap.count()==0);
286 Q_ASSERT(m_seriesDomainMap.count()==0);
287
287
288 qDeleteAll(series);
288 qDeleteAll(series);
289 }
289 }
290
290
291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
291 void ChartDataSet::zoomInDomain(const QRectF& rect, const QSizeF& size)
292 {
292 {
293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
293 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
294
294
295
295
296 blockAxisSignals(true);
296 blockAxisSignals(true);
297
297
298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
298 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
299
299
300 while (i.hasNext()) {
300 while (i.hasNext()) {
301 i.next();
301 i.next();
302 i.value()->zoomIn(rect,size);
302 i.value()->zoomIn(rect,size);
303 }
303 }
304
304
305 blockAxisSignals(false);
305 blockAxisSignals(false);
306
306
307 }
307 }
308
308
309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
309 void ChartDataSet::zoomOutDomain(const QRectF& rect, const QSizeF& size)
310 {
310 {
311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
311 //for performance reasons block, signals and scale "full" domain one by one. Gives twice less screen updates
312
312
313 blockAxisSignals(true);
313 blockAxisSignals(true);
314
314
315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
315 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
316
316
317 while (i.hasNext()) {
317 while (i.hasNext()) {
318 i.next();
318 i.next();
319 i.value()->zoomOut(rect,size);
319 i.value()->zoomOut(rect,size);
320 }
320 }
321
321
322 blockAxisSignals(false);
322 blockAxisSignals(false);
323 }
323 }
324
324
325 void ChartDataSet::blockAxisSignals(bool enabled)
325 void ChartDataSet::blockAxisSignals(bool enabled)
326 {
326 {
327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
327 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
328 while (i.hasNext()) {
328 while (i.hasNext()) {
329 i.next();
329 i.next();
330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
330 QAbstractAxis* axisX = m_seriesAxisXMap.value(i.key());
331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
331 QAbstractAxis* axisY = m_seriesAxisYMap.value(i.key());
332 if(axisX) axisX->d_ptr->blockSignals(enabled);
332 if(axisX) {
333 if(axisY) axisY->d_ptr->blockSignals(enabled);
333 axisX->d_ptr->blockSignals(enabled);
334 if(!enabled) {
335 axisX->d_ptr->setDirty(false);
336 axisX->d_ptr->emitUpdated();
337 }
338 }
339 if(axisY) {
340 axisY->d_ptr->blockSignals(enabled);
341 if(!enabled) {
342 axisY->d_ptr->setDirty(false);
343 axisY->d_ptr->emitUpdated();
344 }
345 }
334 }
346 }
335 }
347 }
336
348
337 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
349 int ChartDataSet::seriesCount(QAbstractSeries::SeriesType type)
338 {
350 {
339 int count=0;
351 int count=0;
340 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
352 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
341 while (i.hasNext()) {
353 while (i.hasNext()) {
342 i.next();
354 i.next();
343 if(i.key()->type()==type) count++;
355 if(i.key()->type()==type) count++;
344 }
356 }
345 return count;
357 return count;
346 }
358 }
347
359
348 int ChartDataSet::seriesIndex(QAbstractSeries *series)
360 int ChartDataSet::seriesIndex(QAbstractSeries *series)
349 {
361 {
350 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
362 QMapIterator<int, QAbstractSeries*> i(m_indexSeriesMap);
351 while (i.hasNext()) {
363 while (i.hasNext()) {
352 i.next();
364 i.next();
353 if (i.value() == series)
365 if (i.value() == series)
354 return i.key();
366 return i.key();
355 }
367 }
356 return -1;
368 return -1;
357 }
369 }
358
370
359 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
371 QAbstractAxis* ChartDataSet::axisX(QAbstractSeries *series) const
360 {
372 {
361 if(series == 0) {
373 if(series == 0) {
362
374
363 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
375 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisXMap);
364
376
365 while (i.hasNext()) {
377 while (i.hasNext()) {
366 i.next();
378 i.next();
367 if(i.value()->isVisible()) return i.value();
379 if(i.value()->isVisible()) return i.value();
368 }
380 }
369 return 0;
381 return 0;
370 }
382 }
371 return m_seriesAxisXMap.value(series);
383 return m_seriesAxisXMap.value(series);
372 }
384 }
373
385
374 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
386 QAbstractAxis* ChartDataSet::axisY(QAbstractSeries *series) const
375 {
387 {
376 if(series == 0) {
388 if(series == 0) {
377 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
389 QMapIterator<QAbstractSeries*, QAbstractAxis *> i(m_seriesAxisYMap);
378
390
379 while (i.hasNext()) {
391 while (i.hasNext()) {
380 i.next();
392 i.next();
381 if(i.value()->isVisible()) return i.value();
393 if(i.value()->isVisible()) return i.value();
382 }
394 }
383 return 0;
395 return 0;
384 }
396 }
385 return m_seriesAxisYMap.value(series);
397 return m_seriesAxisYMap.value(series);
386 }
398 }
387
399
388 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
400 void ChartDataSet::setAxis(QAbstractSeries *series, QAbstractAxis *axis, Qt::Orientation orientation)
389 {
401 {
390 Q_ASSERT(axis);
402 Q_ASSERT(axis);
391
403
392 if(!series) {
404 if(!series) {
393 qWarning() << "Series not found on the chart.";
405 qWarning() << "Series not found on the chart.";
394 return;
406 return;
395 }
407 }
396
408
397 Domain* domain = m_seriesDomainMap.value(series);
409 Domain* domain = m_seriesDomainMap.value(series);
398
410
399 if(!domain) {
411 if(!domain) {
400 qWarning() << "Series not found on the chart.";
412 qWarning() << "Series not found on the chart.";
401 return;
413 return;
402 }
414 }
403
415
404 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
416 if(orientation==Qt::Horizontal && axis->orientation()==Qt::Vertical) {
405 qWarning()<<"Axis already defined as axis Y";
417 qWarning()<<"Axis already defined as axis Y";
406 return;
418 return;
407 }
419 }
408
420
409 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
421 if(orientation==Qt::Vertical && axis->orientation()==Qt::Horizontal) {
410 qWarning()<<"Axis already defined as axis X";
422 qWarning()<<"Axis already defined as axis X";
411 return;
423 return;
412 }
424 }
413
425
414 axis->d_ptr->setOrientation(orientation);
426 axis->d_ptr->setOrientation(orientation);
415
427
416 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
428 QMap<QAbstractSeries*, QAbstractAxis*> *seriesAxisMap;
417
429
418 if(orientation==Qt::Vertical) {
430 if(orientation==Qt::Vertical) {
419 seriesAxisMap= &m_seriesAxisYMap;
431 seriesAxisMap= &m_seriesAxisYMap;
420 }else{
432 }else{
421 seriesAxisMap= &m_seriesAxisXMap;
433 seriesAxisMap= &m_seriesAxisXMap;
422 }
434 }
423
435
424 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
436 QAbstractAxis *oldAxis = seriesAxisMap->take(series);
425 QList<QAbstractAxis*> axes = seriesAxisMap->values();
437 QList<QAbstractAxis*> axes = seriesAxisMap->values();
426 if(oldAxis) {
438 if(oldAxis) {
427 if(axes.indexOf(oldAxis)==-1) {
439 if(axes.indexOf(oldAxis)==-1) {
428 emit axisRemoved(oldAxis);
440 emit axisRemoved(oldAxis);
429 oldAxis->disconnect();
441 oldAxis->disconnect();
430 QObject::disconnect(domain,0,oldAxis,0);
442 QObject::disconnect(domain,0,oldAxis,0);
431 oldAxis->d_ptr->m_dataset=0;
443 oldAxis->d_ptr->m_dataset=0;
432 oldAxis->deleteLater();
444 oldAxis->deleteLater();
433 }
445 }
434 }
446 }
435
447
436 if(axes.indexOf(axis)==-1) {
448 if(axes.indexOf(axis)==-1) {
437 initializeAxis(axis,series);
449 initializeAxis(axis,series);
438 emit axisAdded(axis,domain);
450 emit axisAdded(axis,domain);
439 }else{
451 }else{
440 initializeAxis(axis,series);
452 initializeAxis(axis,series);
441 }
453 }
442 }
454 }
443
455
444 Domain* ChartDataSet::domain(QAbstractSeries *series) const
456 Domain* ChartDataSet::domain(QAbstractSeries *series) const
445 {
457 {
446 return m_seriesDomainMap.value(series);
458 return m_seriesDomainMap.value(series);
447 }
459 }
448
460
449 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
461 void ChartDataSet::scrollDomain(qreal dx,qreal dy,const QSizeF& size)
450 {
462 {
451 blockAxisSignals(true);
463 blockAxisSignals(true);
452 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
464 QMapIterator<QAbstractSeries*, Domain*> i(m_seriesDomainMap);
453 while (i.hasNext()) {
465 while (i.hasNext()) {
454 i.next();
466 i.next();
455 i.value()->move(dx,dy,size);
467 i.value()->move(dx,dy,size);
456 }
468 }
457 blockAxisSignals(false);
469 blockAxisSignals(false);
458 }
470 }
459
471
460 QList<QAbstractSeries*> ChartDataSet::series() const
472 QList<QAbstractSeries*> ChartDataSet::series() const
461 {
473 {
462 return m_seriesDomainMap.keys();
474 return m_seriesDomainMap.keys();
463 }
475 }
464
476
465 void ChartDataSet::updateSeries(QAbstractSeries *series)
477 void ChartDataSet::updateSeries(QAbstractSeries *series)
466 {
478 {
467 emit seriesUpdated(series);
479 emit seriesUpdated(series);
468 }
480 }
469
481
470 #include "moc_chartdataset_p.cpp"
482 #include "moc_chartdataset_p.cpp"
471
483
472 QTCOMMERCIALCHART_END_NAMESPACE
484 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,412 +1,415
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 "../qabstractaxis/tst_qabstractaxis.h"
21 #include "../qabstractaxis/tst_qabstractaxis.h"
22 #include "qvaluesaxis.h"
22 #include "qvaluesaxis.h"
23 #include <qlineseries.h>
23 #include <qlineseries.h>
24
24
25 class tst_QValuesAxis: public tst_QAbstractAxis
25 class tst_QValuesAxis: public tst_QAbstractAxis
26 {
26 {
27 Q_OBJECT
27 Q_OBJECT
28
28
29 public slots:
29 public slots:
30 void initTestCase();
30 void initTestCase();
31 void cleanupTestCase();
31 void cleanupTestCase();
32 void init();
32 void init();
33 void cleanup();
33 void cleanup();
34
34
35 private slots:
35 private slots:
36 void qvaluesaxis_data();
36 void qvaluesaxis_data();
37 void qvaluesaxis();
37 void qvaluesaxis();
38 void max_raw_data();
38 void max_raw_data();
39 void max_raw();
39 void max_raw();
40 void max_data();
40 void max_data();
41 void max();
41 void max();
42 void max_animation_data();
42 void max_animation_data();
43 void max_animation();
43 void max_animation();
44 void min_raw_data();
44 void min_raw_data();
45 void min_raw();
45 void min_raw();
46 void min_data();
46 void min_data();
47 void min();
47 void min();
48 void min_animation_data();
48 void min_animation_data();
49 void min_animation();
49 void min_animation();
50 void niceNumbersEnabled_data();
50 void niceNumbersEnabled_data();
51 void niceNumbersEnabled();
51 void niceNumbersEnabled();
52 void range_raw_data();
52 void range_raw_data();
53 void range_raw();
53 void range_raw();
54 void range_data();
54 void range_data();
55 void range();
55 void range();
56 void range_animation_data();
56 void range_animation_data();
57 void range_animation();
57 void range_animation();
58 void ticksCount_data();
58 void ticksCount_data();
59 void ticksCount();
59 void ticksCount();
60 void noautoscale_data();
60 void noautoscale_data();
61 void noautoscale();
61 void noautoscale();
62 void autoscale_data();
62 void autoscale_data();
63 void autoscale();
63 void autoscale();
64
64
65 private:
65 private:
66 QValuesAxis* m_valuesaxis;
66 QValuesAxis* m_valuesaxis;
67 QLineSeries* m_series;
67 QLineSeries* m_series;
68 };
68 };
69
69
70 void tst_QValuesAxis::initTestCase()
70 void tst_QValuesAxis::initTestCase()
71 {
71 {
72 }
72 }
73
73
74 void tst_QValuesAxis::cleanupTestCase()
74 void tst_QValuesAxis::cleanupTestCase()
75 {
75 {
76 }
76 }
77
77
78 void tst_QValuesAxis::init()
78 void tst_QValuesAxis::init()
79 {
79 {
80 m_valuesaxis = new QValuesAxis();
80 m_valuesaxis = new QValuesAxis();
81 m_series = new QLineSeries();
81 m_series = new QLineSeries();
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
84 m_chart->addSeries(m_series);
84 m_chart->addSeries(m_series);
85 m_chart->createDefaultAxes();
85 m_chart->createDefaultAxes();
86 }
86 }
87
87
88 void tst_QValuesAxis::cleanup()
88 void tst_QValuesAxis::cleanup()
89 {
89 {
90 delete m_series;
90 delete m_series;
91 delete m_valuesaxis;
91 delete m_valuesaxis;
92 m_series = 0;
92 m_series = 0;
93 m_valuesaxis = 0;
93 m_valuesaxis = 0;
94 tst_QAbstractAxis::cleanup();
94 tst_QAbstractAxis::cleanup();
95 }
95 }
96
96
97 void tst_QValuesAxis::qvaluesaxis_data()
97 void tst_QValuesAxis::qvaluesaxis_data()
98 {
98 {
99 }
99 }
100
100
101 void tst_QValuesAxis::qvaluesaxis()
101 void tst_QValuesAxis::qvaluesaxis()
102 {
102 {
103 qabstractaxis();
103 qabstractaxis();
104
104
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
110
110
111 m_chart->setAxisX(m_valuesaxis, m_series);
111 m_chart->setAxisX(m_valuesaxis, m_series);
112 m_view->show();
112 m_view->show();
113 QTest::qWaitForWindowShown(m_view);
113 QTest::qWaitForWindowShown(m_view);
114
114
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
119 }
119 }
120
120
121 void tst_QValuesAxis::max_raw_data()
121 void tst_QValuesAxis::max_raw_data()
122 {
122 {
123 QTest::addColumn<qreal>("max");
123 QTest::addColumn<qreal>("max");
124 QTest::newRow("1.0") << 1.0;
124 QTest::newRow("1.0") << 1.0;
125 QTest::newRow("50.0") << 50.0;
125 QTest::newRow("50.0") << 50.0;
126 QTest::newRow("101.0") << 101.0;
126 QTest::newRow("101.0") << 101.0;
127 }
127 }
128
128
129 void tst_QValuesAxis::max_raw()
129 void tst_QValuesAxis::max_raw()
130 {
130 {
131 QFETCH(qreal, max);
131 QFETCH(qreal, max);
132
132
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
136
136
137 m_valuesaxis->setMax(max);
137 m_valuesaxis->setMax(max);
138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
139
139
140 QCOMPARE(spy0.count(), 1);
140 QCOMPARE(spy0.count(), 1);
141 QCOMPARE(spy1.count(), 0);
141 QCOMPARE(spy1.count(), 0);
142 QCOMPARE(spy2.count(), 1);
142 QCOMPARE(spy2.count(), 1);
143
143
144 }
144 }
145
145
146 void tst_QValuesAxis::max_data()
146 void tst_QValuesAxis::max_data()
147 {
147 {
148 max_raw_data();
148 max_raw_data();
149 }
149 }
150
150
151 void tst_QValuesAxis::max()
151 void tst_QValuesAxis::max()
152 {
152 {
153 m_chart->setAxisX(m_valuesaxis, m_series);
153 m_chart->setAxisX(m_valuesaxis, m_series);
154 m_view->show();
154 m_view->show();
155 QTest::qWaitForWindowShown(m_view);
155 QTest::qWaitForWindowShown(m_view);
156 max_raw();
156 max_raw();
157 }
157 }
158
158
159 void tst_QValuesAxis::max_animation_data()
159 void tst_QValuesAxis::max_animation_data()
160 {
160 {
161 max_data();
161 max_data();
162 }
162 }
163
163
164 void tst_QValuesAxis::max_animation()
164 void tst_QValuesAxis::max_animation()
165 {
165 {
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
167 max();
167 max();
168 }
168 }
169
169
170 void tst_QValuesAxis::min_raw_data()
170 void tst_QValuesAxis::min_raw_data()
171 {
171 {
172 QTest::addColumn<qreal>("min");
172 QTest::addColumn<qreal>("min");
173 QTest::newRow("-1.0") << -1.0;
173 QTest::newRow("-1.0") << -1.0;
174 QTest::newRow("-50.0") << -50.0;
174 QTest::newRow("-50.0") << -50.0;
175 QTest::newRow("-101.0") << -101.0;
175 QTest::newRow("-101.0") << -101.0;
176 }
176 }
177
177
178 void tst_QValuesAxis::min_raw()
178 void tst_QValuesAxis::min_raw()
179 {
179 {
180 QFETCH(qreal, min);
180 QFETCH(qreal, min);
181
181
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
185
185
186 m_valuesaxis->setMin(min);
186 m_valuesaxis->setMin(min);
187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
188
188
189 QCOMPARE(spy0.count(), 0);
189 QCOMPARE(spy0.count(), 0);
190 QCOMPARE(spy1.count(), 1);
190 QCOMPARE(spy1.count(), 1);
191 QCOMPARE(spy2.count(), 1);
191 QCOMPARE(spy2.count(), 1);
192 }
192 }
193
193
194 void tst_QValuesAxis::min_data()
194 void tst_QValuesAxis::min_data()
195 {
195 {
196 min_raw_data();
196 min_raw_data();
197 }
197 }
198
198
199 void tst_QValuesAxis::min()
199 void tst_QValuesAxis::min()
200 {
200 {
201 m_chart->setAxisX(m_valuesaxis, m_series);
201 m_chart->setAxisX(m_valuesaxis, m_series);
202 m_view->show();
202 m_view->show();
203 QTest::qWaitForWindowShown(m_view);
203 QTest::qWaitForWindowShown(m_view);
204 min_raw();
204 min_raw();
205 }
205 }
206
206
207 void tst_QValuesAxis::min_animation_data()
207 void tst_QValuesAxis::min_animation_data()
208 {
208 {
209 min_data();
209 min_data();
210 }
210 }
211
211
212 void tst_QValuesAxis::min_animation()
212 void tst_QValuesAxis::min_animation()
213 {
213 {
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
215 min();
215 min();
216 }
216 }
217
217
218 void tst_QValuesAxis::niceNumbersEnabled_data()
218 void tst_QValuesAxis::niceNumbersEnabled_data()
219 {
219 {
220 QTest::addColumn<bool>("niceNumbersEnabled");
220 QTest::addColumn<bool>("niceNumbersEnabled");
221 QTest::addColumn<qreal>("min");
221 QTest::addColumn<qreal>("min");
222 QTest::addColumn<qreal>("max");
222 QTest::addColumn<qreal>("max");
223 QTest::addColumn<int>("ticks");
223 QTest::addColumn<int>("ticks");
224 QTest::addColumn<qreal>("expectedMin");
224 QTest::addColumn<qreal>("expectedMin");
225 QTest::addColumn<qreal>("expectedMax");
225 QTest::addColumn<qreal>("expectedMax");
226 QTest::addColumn<int>("expectedTicks");
226 QTest::addColumn<int>("expectedTicks");
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
233 }
233 }
234
234
235 void tst_QValuesAxis::niceNumbersEnabled()
235 void tst_QValuesAxis::niceNumbersEnabled()
236 {
236 {
237 QFETCH(bool, niceNumbersEnabled);
237 QFETCH(bool, niceNumbersEnabled);
238 QFETCH(qreal, min);
238 QFETCH(qreal, min);
239 QFETCH(qreal, max);
239 QFETCH(qreal, max);
240 QFETCH(int, ticks);
240 QFETCH(int, ticks);
241 QFETCH(qreal, expectedMin);
241 QFETCH(qreal, expectedMin);
242 QFETCH(qreal, expectedMax);
242 QFETCH(qreal, expectedMax);
243 QFETCH(int, expectedTicks);
243 QFETCH(int, expectedTicks);
244
244
245 m_valuesaxis->setRange(min, max);
246 m_valuesaxis->setTicksCount(ticks);
247
248 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
249 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
250
245 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
251 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
246 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
252 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
247 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
253 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
248
254
249 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
255 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
250 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
256 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
251
257
252 QCOMPARE(spy0.count(), 0);
258 if(!qFuzzyIsNull(expectedMin - min))
253 QCOMPARE(spy1.count(), 0);
259 QCOMPARE(spy1.count(), 1);
254 QCOMPARE(spy2.count(), 0);
260 if(!qFuzzyIsNull(expectedMax - max))
261 QCOMPARE(spy0.count(), 1);
262 if((!qFuzzyIsNull(expectedMin - min)) || (!qFuzzyIsNull(expectedMax - max)))
263 QCOMPARE(spy2.count(), 1);
255
264
256 m_valuesaxis->setTicksCount(ticks);
257 m_valuesaxis->setRange(min, max);
258 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
265 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
259 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
266 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
260 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
267 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
261
268
262 QCOMPARE(spy0.count(), 1);
263 QCOMPARE(spy1.count(), 1);
264 QCOMPARE(spy2.count(), 1);
265
266 }
269 }
267
270
268 void tst_QValuesAxis::range_raw_data()
271 void tst_QValuesAxis::range_raw_data()
269 {
272 {
270 QTest::addColumn<qreal>("min");
273 QTest::addColumn<qreal>("min");
271 QTest::addColumn<qreal>("max");
274 QTest::addColumn<qreal>("max");
272 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
275 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
273 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
276 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
274 QTest::newRow("101.0") << 40.0 << 60.0;
277 QTest::newRow("101.0") << 40.0 << 60.0;
275 }
278 }
276
279
277 void tst_QValuesAxis::range_raw()
280 void tst_QValuesAxis::range_raw()
278 {
281 {
279 QFETCH(qreal, min);
282 QFETCH(qreal, min);
280 QFETCH(qreal, max);
283 QFETCH(qreal, max);
281
284
282 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
285 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
283 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
286 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
284 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
287 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
285
288
286 m_valuesaxis->setRange(min, max);
289 m_valuesaxis->setRange(min, max);
287 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
290 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
288 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
291 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
289
292
290 QCOMPARE(spy0.count(), 1);
293 QCOMPARE(spy0.count(), 1);
291 QCOMPARE(spy1.count(), 1);
294 QCOMPARE(spy1.count(), 1);
292 QCOMPARE(spy2.count(), 1);
295 QCOMPARE(spy2.count(), 1);
293 }
296 }
294
297
295 void tst_QValuesAxis::range_data()
298 void tst_QValuesAxis::range_data()
296 {
299 {
297 range_raw_data();
300 range_raw_data();
298 }
301 }
299
302
300 void tst_QValuesAxis::range()
303 void tst_QValuesAxis::range()
301 {
304 {
302 m_chart->setAxisX(m_valuesaxis, m_series);
305 m_chart->setAxisX(m_valuesaxis, m_series);
303 m_view->show();
306 m_view->show();
304 QTest::qWaitForWindowShown(m_view);
307 QTest::qWaitForWindowShown(m_view);
305 range_raw();
308 range_raw();
306 }
309 }
307
310
308 void tst_QValuesAxis::range_animation_data()
311 void tst_QValuesAxis::range_animation_data()
309 {
312 {
310 range_data();
313 range_data();
311 }
314 }
312
315
313 void tst_QValuesAxis::range_animation()
316 void tst_QValuesAxis::range_animation()
314 {
317 {
315 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
318 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
316 range();
319 range();
317 }
320 }
318
321
319 void tst_QValuesAxis::ticksCount_data()
322 void tst_QValuesAxis::ticksCount_data()
320 {
323 {
321 QTest::addColumn<int>("ticksCount");
324 QTest::addColumn<int>("ticksCount");
322 QTest::addColumn<int>("expectedCount");
325 QTest::addColumn<int>("expectedCount");
323 QTest::newRow("0") << 2;
326 QTest::newRow("0") << 2;
324 QTest::newRow("1") << 2;
327 QTest::newRow("1") << 2;
325 QTest::newRow("2") << 2;
328 QTest::newRow("2") << 2;
326 QTest::newRow("3") << 3;
329 QTest::newRow("3") << 3;
327 QTest::newRow("-1") << 2;
330 QTest::newRow("-1") << 2;
328 }
331 }
329
332
330 void tst_QValuesAxis::ticksCount()
333 void tst_QValuesAxis::ticksCount()
331 {
334 {
332 QFETCH(int, ticksCount);
335 QFETCH(int, ticksCount);
333
336
334 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
337 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
335 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
338 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
336 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
339 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
337
340
338 m_valuesaxis->setTicksCount(ticksCount);
341 m_valuesaxis->setTicksCount(ticksCount);
339 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
342 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
340
343
341 QCOMPARE(spy0.count(), 0);
344 QCOMPARE(spy0.count(), 0);
342 QCOMPARE(spy1.count(), 0);
345 QCOMPARE(spy1.count(), 0);
343 QCOMPARE(spy2.count(), 0);
346 QCOMPARE(spy2.count(), 0);
344
347
345 m_chart->setAxisX(m_valuesaxis, m_series);
348 m_chart->setAxisX(m_valuesaxis, m_series);
346 m_view->show();
349 m_view->show();
347 QTest::qWaitForWindowShown(m_view);
350 QTest::qWaitForWindowShown(m_view);
348
351
349 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
352 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
350 }
353 }
351
354
352 void tst_QValuesAxis::noautoscale_data()
355 void tst_QValuesAxis::noautoscale_data()
353 {
356 {
354 QTest::addColumn<qreal>("min");
357 QTest::addColumn<qreal>("min");
355 QTest::addColumn<qreal>("max");
358 QTest::addColumn<qreal>("max");
356 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
359 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
357 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
360 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
358 QTest::newRow("101.0") << 40.0 << 60.0;
361 QTest::newRow("101.0") << 40.0 << 60.0;
359 }
362 }
360
363
361 void tst_QValuesAxis::noautoscale()
364 void tst_QValuesAxis::noautoscale()
362 {
365 {
363 QFETCH(qreal, min);
366 QFETCH(qreal, min);
364 QFETCH(qreal, max);
367 QFETCH(qreal, max);
365
368
366 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
369 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
367 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
370 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
368 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
371 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
369
372
370 m_valuesaxis->setRange(min, max);
373 m_valuesaxis->setRange(min, max);
371 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
374 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
372 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
375 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
373
376
374 QCOMPARE(spy0.count(), 1);
377 QCOMPARE(spy0.count(), 1);
375 QCOMPARE(spy1.count(), 1);
378 QCOMPARE(spy1.count(), 1);
376 QCOMPARE(spy2.count(), 1);
379 QCOMPARE(spy2.count(), 1);
377
380
378 m_chart->setAxisX(m_valuesaxis, m_series);
381 m_chart->setAxisX(m_valuesaxis, m_series);
379 m_view->show();
382 m_view->show();
380 QTest::qWaitForWindowShown(m_view);
383 QTest::qWaitForWindowShown(m_view);
381 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
384 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
382 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
385 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
383 }
386 }
384
387
385 void tst_QValuesAxis::autoscale_data()
388 void tst_QValuesAxis::autoscale_data()
386 {
389 {
387
390
388 }
391 }
389
392
390 void tst_QValuesAxis::autoscale()
393 void tst_QValuesAxis::autoscale()
391 {
394 {
392 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
395 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
393 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
396 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
394 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
397 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
395
398
396 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
399 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
397 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
400 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
398 m_chart->setAxisX(m_valuesaxis, m_series);
401 m_chart->setAxisX(m_valuesaxis, m_series);
399
402
400 QCOMPARE(spy0.count(), 1);
403 QCOMPARE(spy0.count(), 1);
401 QCOMPARE(spy1.count(), 1);
404 QCOMPARE(spy1.count(), 1);
402 QCOMPARE(spy2.count(), 1);
405 QCOMPARE(spy2.count(), 1);
403
406
404 m_view->show();
407 m_view->show();
405 QTest::qWaitForWindowShown(m_view);
408 QTest::qWaitForWindowShown(m_view);
406 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
409 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
407 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
410 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
408 }
411 }
409
412
410 QTEST_MAIN(tst_QValuesAxis)
413 QTEST_MAIN(tst_QValuesAxis)
411 #include "tst_qvaluesaxis.moc"
414 #include "tst_qvaluesaxis.moc"
412
415
General Comments 0
You need to be logged in to leave comments. Login now