##// END OF EJS Templates
Updates tst_qvaluesaxis test cases
Michal Klocek -
r1700:d1f113b2af85
parent child
Show More
@@ -1,362 +1,362
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 <cmath>
26 #include <cmath>
27 #include <QDebug>
27 #include <QDebug>
28
28
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
29 QTCOMMERCIALCHART_BEGIN_NAMESPACE
30 /*!
30 /*!
31 \class QValuesAxis
31 \class QValuesAxis
32 \brief The QValuesAxis class is used for manipulating chart's axis.
32 \brief The QValuesAxis class is used for manipulating chart's axis.
33 \mainclass
33 \mainclass
34
34
35 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
35 ValuesAxis can be setup to show axis line with tick marks, grid lines and shades.
36 Values of axis are drawn to position of ticks
36 Values of axis are drawn to position of ticks
37 */
37 */
38
38
39 /*!
39 /*!
40 \qmlclass ValuesAxis QValuesAxis
40 \qmlclass ValuesAxis QValuesAxis
41 \brief The ValuesAxis element is used for manipulating chart's axes
41 \brief The ValuesAxis element is used for manipulating chart's axes
42
42
43 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
43 ValueAxis can be setup to show axis line with tick marks, grid lines and shades.
44 Values of axis are drawn to position of ticks
44 Values of axis are drawn to position of ticks
45
45
46 To access Axes you can use ChartView API. For example:
46 To access Axes you can use ChartView API. For example:
47 \code
47 \code
48 ChartView {
48 ChartView {
49 ValuesAxis {
49 ValuesAxis {
50 id: xAxis
50 id: xAxis
51 min: 0
51 min: 0
52 max: 10
52 max: 10
53 }
53 }
54 // Add a few series...
54 // Add a few series...
55 }
55 }
56 \endcode
56 \endcode
57 */
57 */
58
58
59 /*!
59 /*!
60 \property QValuesAxis::min
60 \property QValuesAxis::min
61 Defines the minimum value on the axis.
61 Defines the minimum value on the axis.
62 */
62 */
63 /*!
63 /*!
64 \qmlproperty real ValuesAxis::min
64 \qmlproperty real ValuesAxis::min
65 Defines the minimum value on the axis.
65 Defines the minimum value on the axis.
66 */
66 */
67
67
68 /*!
68 /*!
69 \property QValuesAxis::max
69 \property QValuesAxis::max
70 Defines the maximum value on the axis.
70 Defines the maximum value on the axis.
71 */
71 */
72 /*!
72 /*!
73 \qmlproperty real ValuesAxis::max
73 \qmlproperty real ValuesAxis::max
74 Defines the maximum value on the axis.
74 Defines the maximum value on the axis.
75 */
75 */
76
76
77 /*!
77 /*!
78 \fn void QValuesAxis::minChanged(qreal min)
78 \fn void QValuesAxis::minChanged(qreal min)
79 Axis emits signal when \a min of axis has changed.
79 Axis emits signal when \a min of axis has changed.
80 */
80 */
81 /*!
81 /*!
82 \qmlsignal ValuesAxis::onMinChanged(real min)
82 \qmlsignal ValuesAxis::onMinChanged(real min)
83 Axis emits signal when \a min of axis has changed.
83 Axis emits signal when \a min of axis has changed.
84 */
84 */
85
85
86 /*!
86 /*!
87 \fn void QValuesAxis::maxChanged(qreal max)
87 \fn void QValuesAxis::maxChanged(qreal max)
88 Axis emits signal when \a max of axis has changed.
88 Axis emits signal when \a max of axis has changed.
89 */
89 */
90 /*!
90 /*!
91 \qmlsignal ValuesAxis::onMaxChanged(real max)
91 \qmlsignal ValuesAxis::onMaxChanged(real max)
92 Axis emits signal when \a max of axis has changed.
92 Axis emits signal when \a max of axis has changed.
93 */
93 */
94
94
95 /*!
95 /*!
96 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
96 \fn void QValuesAxis::rangeChanged(qreal min, qreal max)
97 Axis emits signal when \a min or \a max of axis has changed.
97 Axis emits signal when \a min or \a max of axis has changed.
98 */
98 */
99
99
100 /*!
100 /*!
101 \property QValuesAxis::ticksCount
101 \property QValuesAxis::ticksCount
102 The number of tick marks for the axis.
102 The number of tick marks for the axis.
103 */
103 */
104
104
105 /*!
105 /*!
106 \qmlproperty int ValuesAxis::ticksCount
106 \qmlproperty int ValuesAxis::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 \property QValuesAxis::niceNumbersEnabled
111 \property QValuesAxis::niceNumbersEnabled
112 Whether the nice numbers algorithm is enabled or not for the axis.
112 Whether the nice numbers algorithm is enabled or not for the axis.
113 */
113 */
114
114
115 /*!
115 /*!
116 \qmlproperty bool ValuesAxis::niceNumbersEnabled
116 \qmlproperty bool ValuesAxis::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 Constructs an axis object which is a child of \a parent.
121 Constructs an axis object which is a child of \a parent.
122 */
122 */
123 QValuesAxis::QValuesAxis(QObject *parent) :
123 QValuesAxis::QValuesAxis(QObject *parent) :
124 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
124 QAbstractAxis(*new QValuesAxisPrivate(this),parent)
125 {
125 {
126
126
127 }
127 }
128
128
129 /*!
129 /*!
130 \internal
130 \internal
131 */
131 */
132 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
132 QValuesAxis::QValuesAxis(QValuesAxisPrivate &d,QObject *parent) : QAbstractAxis(d,parent)
133 {
133 {
134
134
135 }
135 }
136
136
137 /*!
137 /*!
138 Destroys the object
138 Destroys the object
139 */
139 */
140 QValuesAxis::~QValuesAxis()
140 QValuesAxis::~QValuesAxis()
141 {
141 {
142
142
143 }
143 }
144
144
145 void QValuesAxis::setMin(qreal min)
145 void QValuesAxis::setMin(qreal min)
146 {
146 {
147 Q_D(QValuesAxis);
147 Q_D(QValuesAxis);
148 setRange(min,d->m_max);
148 setRange(min,d->m_max);
149 }
149 }
150
150
151 qreal QValuesAxis::min() const
151 qreal QValuesAxis::min() const
152 {
152 {
153 Q_D(const QValuesAxis);
153 Q_D(const QValuesAxis);
154 return d->m_min;
154 return d->m_min;
155 }
155 }
156
156
157 void QValuesAxis::setMax(qreal max)
157 void QValuesAxis::setMax(qreal max)
158 {
158 {
159 Q_D(QValuesAxis);
159 Q_D(QValuesAxis);
160 setRange(d->m_min,max);
160 setRange(d->m_min,max);
161 }
161 }
162
162
163 qreal QValuesAxis::max() const
163 qreal QValuesAxis::max() const
164 {
164 {
165 Q_D(const QValuesAxis);
165 Q_D(const QValuesAxis);
166 return d->m_max;
166 return d->m_max;
167 }
167 }
168
168
169 /*!
169 /*!
170 Sets range from \a min to \a max on the axis.
170 Sets range from \a min to \a max on the axis.
171 */
171 */
172 void QValuesAxis::setRange(qreal min, qreal max)
172 void QValuesAxis::setRange(qreal min, qreal max)
173 {
173 {
174 Q_D(QValuesAxis);
174 Q_D(QValuesAxis);
175 bool changed = false;
175 bool changed = false;
176
176
177 if (!qFuzzyIsNull(d->m_min - min)) {
177 if (!qFuzzyIsNull(d->m_min - min)) {
178 d->m_min = min;
178 d->m_min = min;
179 changed = true;
179 changed = true;
180 emit minChanged(min);
180 emit minChanged(min);
181 }
181 }
182
182
183 if (!qFuzzyIsNull(d->m_max - max)) {
183 if (!qFuzzyIsNull(d->m_max - max)) {
184 d->m_max = max;
184 d->m_max = max;
185 changed = true;
185 changed = true;
186 emit maxChanged(max);
186 emit maxChanged(max);
187 }
187 }
188
188
189 if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
189 if(d->m_niceNumbers) d->looseNiceNumbers(d->m_min, d->m_max, d->m_tickCount);
190
190
191 if (changed) {
191 if (changed) {
192 emit rangeChanged(d->m_min,d->m_max);
192 emit rangeChanged(d->m_min,d->m_max);
193 d->emitUpdated();
193 d->emitUpdated();
194 }
194 }
195 }
195 }
196
196
197 /*!
197 /*!
198 Sets \a count for ticks on the axis.
198 Sets \a count for ticks on the axis.
199 */
199 */
200 void QValuesAxis::setTicksCount(int count)
200 void QValuesAxis::setTicksCount(int count)
201 {
201 {
202 Q_D(QValuesAxis);
202 Q_D(QValuesAxis);
203 if (d->m_tickCount != count) {
203 if (d->m_tickCount != count && count >=2) {
204 d->m_tickCount = count;
204 d->m_tickCount = count;
205 d->emitUpdated();
205 d->emitUpdated();
206 }
206 }
207 }
207 }
208
208
209 /*!
209 /*!
210 \fn int QValuesAxis::ticksCount() const
210 \fn int QValuesAxis::ticksCount() const
211 Return number of ticks on the axis
211 Return number of ticks on the axis
212 */
212 */
213 int QValuesAxis::ticksCount() const
213 int QValuesAxis::ticksCount() const
214 {
214 {
215 Q_D(const QValuesAxis);
215 Q_D(const QValuesAxis);
216 return d->m_tickCount;
216 return d->m_tickCount;
217 }
217 }
218
218
219 void QValuesAxis::setNiceNumbersEnabled(bool enable)
219 void QValuesAxis::setNiceNumbersEnabled(bool enable)
220 {
220 {
221 Q_D(QValuesAxis);
221 Q_D(QValuesAxis);
222 if (d->m_niceNumbers != enable){
222 if (d->m_niceNumbers != enable){
223 d->m_niceNumbers = enable;
223 d->m_niceNumbers = enable;
224 if(enable) setRange(d->min(),d->max());
224 if(enable && !qFuzzyIsNull(d->m_max - d->m_min)) setRange(d->min(),d->max());
225 }
225 }
226 }
226 }
227
227
228 bool QValuesAxis::niceNumbersEnabled() const
228 bool QValuesAxis::niceNumbersEnabled() const
229 {
229 {
230 Q_D(const QValuesAxis);
230 Q_D(const QValuesAxis);
231 return d->m_niceNumbers;
231 return d->m_niceNumbers;
232 }
232 }
233
233
234 /*!
234 /*!
235 Returns the type of the axis
235 Returns the type of the axis
236 */
236 */
237 QAbstractAxis::AxisType QValuesAxis::type() const
237 QAbstractAxis::AxisType QValuesAxis::type() const
238 {
238 {
239 return AxisTypeValues;
239 return AxisTypeValues;
240 }
240 }
241
241
242 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
242 /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
243
243
244 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
244 QValuesAxisPrivate::QValuesAxisPrivate(QValuesAxis* q):
245 QAbstractAxisPrivate(q),
245 QAbstractAxisPrivate(q),
246 m_min(0),
246 m_min(0),
247 m_max(0),
247 m_max(0),
248 m_tickCount(5),
248 m_tickCount(5),
249 m_niceNumbers(false)
249 m_niceNumbers(false)
250 {
250 {
251
251
252 }
252 }
253
253
254 QValuesAxisPrivate::~QValuesAxisPrivate()
254 QValuesAxisPrivate::~QValuesAxisPrivate()
255 {
255 {
256
256
257 }
257 }
258
258
259 void QValuesAxisPrivate::handleDomainUpdated()
259 void QValuesAxisPrivate::handleDomainUpdated()
260 {
260 {
261 Q_Q(QValuesAxis);
261 Q_Q(QValuesAxis);
262 Domain* domain = qobject_cast<Domain*>(sender());
262 Domain* domain = qobject_cast<Domain*>(sender());
263 Q_ASSERT(domain);
263 Q_ASSERT(domain);
264
264
265 if(orientation()==Qt::Horizontal){
265 if(orientation()==Qt::Horizontal){
266 q->setRange(domain->minX(),domain->maxX());
266 q->setRange(domain->minX(),domain->maxX());
267 }else if(orientation()==Qt::Vertical){
267 }else if(orientation()==Qt::Vertical){
268 q->setRange(domain->minY(),domain->maxY());
268 q->setRange(domain->minY(),domain->maxY());
269 }
269 }
270 }
270 }
271
271
272
272
273 void QValuesAxisPrivate::setMin(const QVariant &min)
273 void QValuesAxisPrivate::setMin(const QVariant &min)
274 {
274 {
275 Q_Q(QValuesAxis);
275 Q_Q(QValuesAxis);
276 bool ok;
276 bool ok;
277 qreal value = min.toReal(&ok);
277 qreal value = min.toReal(&ok);
278 if(ok) q->setMin(value);
278 if(ok) q->setMin(value);
279 }
279 }
280
280
281 void QValuesAxisPrivate::setMax(const QVariant &max)
281 void QValuesAxisPrivate::setMax(const QVariant &max)
282 {
282 {
283
283
284 Q_Q(QValuesAxis);
284 Q_Q(QValuesAxis);
285 bool ok;
285 bool ok;
286 qreal value = max.toReal(&ok);
286 qreal value = max.toReal(&ok);
287 if(ok) q->setMax(value);
287 if(ok) q->setMax(value);
288 }
288 }
289
289
290 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
290 void QValuesAxisPrivate::setRange(const QVariant &min, const QVariant &max)
291 {
291 {
292 Q_Q(QValuesAxis);
292 Q_Q(QValuesAxis);
293 bool ok1;
293 bool ok1;
294 bool ok2;
294 bool ok2;
295 qreal value1 = min.toReal(&ok1);
295 qreal value1 = min.toReal(&ok1);
296 qreal value2 = max.toReal(&ok2);
296 qreal value2 = max.toReal(&ok2);
297 if(ok1&&ok2) q->setRange(value1,value2);
297 if(ok1&&ok2) q->setRange(value1,value2);
298 }
298 }
299
299
300 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
300 ChartAxis* QValuesAxisPrivate::createGraphics(ChartPresenter* presenter)
301 {
301 {
302 Q_Q(QValuesAxis);
302 Q_Q(QValuesAxis);
303 if(m_orientation == Qt::Vertical){
303 if(m_orientation == Qt::Vertical){
304 return new ChartValuesAxisY(q,presenter);
304 return new ChartValuesAxisY(q,presenter);
305 }else{
305 }else{
306 return new ChartValuesAxisX(q,presenter);
306 return new ChartValuesAxisX(q,presenter);
307 }
307 }
308
308
309 }
309 }
310
310
311 void QValuesAxisPrivate::intializeDomain(Domain* domain)
311 void QValuesAxisPrivate::intializeDomain(Domain* domain)
312 {
312 {
313 if(qFuzzyCompare(m_max,m_min)) {
313 if(qFuzzyCompare(m_max,m_min)) {
314 if(m_orientation==Qt::Vertical){
314 if(m_orientation==Qt::Vertical){
315 m_min = domain->minY();
315 m_min = domain->minY();
316 m_max = domain->maxY();
316 m_max = domain->maxY();
317 }else{
317 }else{
318 m_min = domain->minX();
318 m_min = domain->minX();
319 m_max = domain->maxX();
319 m_max = domain->maxX();
320 }
320 }
321 }
321 }
322 }
322 }
323
323
324 //algorithm defined by Paul S.Heckbert GraphicalGems I
324 //algorithm defined by Paul S.Heckbert GraphicalGems I
325
325
326 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
326 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
327 {
327 {
328 qreal range = niceNumber(max-min,true); //range with ceiling
328 qreal range = niceNumber(max-min,true); //range with ceiling
329 qreal step = niceNumber(range/(ticksCount-1),false);
329 qreal step = niceNumber(range/(ticksCount-1),false);
330 min = floor(min/step);
330 min = floor(min/step);
331 max = ceil(max/step);
331 max = ceil(max/step);
332 ticksCount = int(max-min) +1;
332 ticksCount = int(max-min) +1;
333 min*=step;
333 min*=step;
334 max*=step;
334 max*=step;
335 }
335 }
336
336
337 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
337 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
338
338
339 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
339 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
340 {
340 {
341 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
341 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
342 qreal q = x/z;//q<10 && q>=1;
342 qreal q = x/z;//q<10 && q>=1;
343
343
344 if(ceiling) {
344 if(ceiling) {
345 if(q <= 1.0) q=1;
345 if(q <= 1.0) q=1;
346 else if(q <= 2.0) q=2;
346 else if(q <= 2.0) q=2;
347 else if(q <= 5.0) q=5;
347 else if(q <= 5.0) q=5;
348 else q=10;
348 else q=10;
349 }
349 }
350 else {
350 else {
351 if(q < 1.5) q=1;
351 if(q < 1.5) q=1;
352 else if(q < 3.0) q=2;
352 else if(q < 3.0) q=2;
353 else if(q < 7.0) q=5;
353 else if(q < 7.0) q=5;
354 else q=10;
354 else q=10;
355 }
355 }
356 return q*z;
356 return q*z;
357 }
357 }
358
358
359 #include "moc_qvaluesaxis.cpp"
359 #include "moc_qvaluesaxis.cpp"
360 #include "moc_qvaluesaxis_p.cpp"
360 #include "moc_qvaluesaxis_p.cpp"
361
361
362 QTCOMMERCIALCHART_END_NAMESPACE
362 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,733 +1,661
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 <private/domain_p.h>
22 #include <private/domain_p.h>
23 #include <private/qabstractaxis_p.h>
23 #include <private/qabstractaxis_p.h>
24 #include <tst_definitions.h>
24 #include <tst_definitions.h>
25
25
26 QTCOMMERCIALCHART_USE_NAMESPACE
26 QTCOMMERCIALCHART_USE_NAMESPACE
27
27
28 Q_DECLARE_METATYPE(Domain*)
28 Q_DECLARE_METATYPE(Domain*)
29 Q_DECLARE_METATYPE(QSizeF)
29 Q_DECLARE_METATYPE(QSizeF)
30
30
31
31
32 class AxisMock: public QAbstractAxisPrivate
32 class AxisMock: public QAbstractAxisPrivate
33 {
33 {
34 Q_OBJECT
34 Q_OBJECT
35 public:
35 public:
36 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
36 AxisMock(Qt::Orientation orientation):QAbstractAxisPrivate(0){ setOrientation(orientation);};
37 ChartAxis* createGraphics(ChartPresenter* presenter){};
37 ChartAxis* createGraphics(ChartPresenter* presenter){};
38 void intializeDomain(Domain* domain){};
38 void intializeDomain(Domain* domain){};
39 void setMin(const QVariant &min){}
39 void setMin(const QVariant &min){}
40 qreal min() { return m_min;}
40 qreal min() { return m_min;}
41 void setMax(const QVariant &max){}
41 void setMax(const QVariant &max){}
42 qreal max() { return m_max; }
42 qreal max() { return m_max; }
43 void setRange(const QVariant &min, const QVariant &max){};
43 void setRange(const QVariant &min, const QVariant &max){};
44
44
45 void handleDomainUpdated(){};
45 void handleDomainUpdated(){};
46 public:
46 public:
47 qreal m_min;
47 qreal m_min;
48 qreal m_max;
48 qreal m_max;
49 };
49 };
50
50
51 class tst_Domain: public QObject
51 class tst_Domain: public QObject
52 {
52 {
53 Q_OBJECT
53 Q_OBJECT
54
54
55 public Q_SLOTS:
55 public Q_SLOTS:
56 void initTestCase();
56 void initTestCase();
57 void cleanupTestCase();
57 void cleanupTestCase();
58 void init();
58 void init();
59 void cleanup();
59 void cleanup();
60
60
61 private Q_SLOTS:
61 private Q_SLOTS:
62 void domain();
62 void domain();
63 void handleAxisUpdatedX_data();
63 void handleAxisUpdatedX_data();
64 void handleAxisUpdatedX();
64 void handleAxisUpdatedX();
65 void handleAxisUpdatedY_data();
65 void handleAxisUpdatedY_data();
66 void handleAxisUpdatedY();
66 void handleAxisUpdatedY();
67 void isEmpty_data();
67 void isEmpty_data();
68 void isEmpty();
68 void isEmpty();
69 void maxX_data();
69 void maxX_data();
70 void maxX();
70 void maxX();
71 void maxY_data();
71 void maxY_data();
72 void maxY();
72 void maxY();
73 void minX_data();
73 void minX_data();
74 void minX();
74 void minX();
75 void minY_data();
75 void minY_data();
76 void minY();
76 void minY();
77 void operatorEquals_data();
77 void operatorEquals_data();
78 void operatorEquals();
78 void operatorEquals();
79 void setRange_data();
79 void setRange_data();
80 void setRange();
80 void setRange();
81 void setRangeX_data();
81 void setRangeX_data();
82 void setRangeX();
82 void setRangeX();
83 void setRangeY_data();
83 void setRangeY_data();
84 void setRangeY();
84 void setRangeY();
85 void spanX_data();
85 void spanX_data();
86 void spanX();
86 void spanX();
87 void spanY_data();
87 void spanY_data();
88 void spanY();
88 void spanY();
89 void zoom_data();
89 void zoom_data();
90 void zoom();
90 void zoom();
91 void move_data();
91 void move_data();
92 void move();
92 void move();
93 };
93 };
94
94
95 void tst_Domain::initTestCase()
95 void tst_Domain::initTestCase()
96 {
96 {
97 }
97 }
98
98
99 void tst_Domain::cleanupTestCase()
99 void tst_Domain::cleanupTestCase()
100 {
100 {
101 }
101 }
102
102
103 void tst_Domain::init()
103 void tst_Domain::init()
104 {
104 {
105 }
105 }
106
106
107 void tst_Domain::cleanup()
107 void tst_Domain::cleanup()
108 {
108 {
109 }
109 }
110
110
111 void tst_Domain::domain()
111 void tst_Domain::domain()
112 {
112 {
113 Domain domain;
113 Domain domain;
114
114
115 QCOMPARE(domain.isEmpty(), true);
115 QCOMPARE(domain.isEmpty(), true);
116 QCOMPARE(domain.maxX(), 0.0);
116 QCOMPARE(domain.maxX(), 0.0);
117 QCOMPARE(domain.maxY(), 0.0);
117 QCOMPARE(domain.maxY(), 0.0);
118 QCOMPARE(domain.minX(), 0.0);
118 QCOMPARE(domain.minX(), 0.0);
119 QCOMPARE(domain.minY(), 0.0);
119 QCOMPARE(domain.minY(), 0.0);
120 }
120 }
121
121
122 void tst_Domain::handleAxisUpdatedX_data()
122 void tst_Domain::handleAxisUpdatedX_data()
123 {
123 {
124 QTest::addColumn<qreal>("min");
124 QTest::addColumn<qreal>("min");
125 QTest::addColumn<qreal>("max");
125 QTest::addColumn<qreal>("max");
126 QTest::newRow("-1 1") << -1.0 << 1.0;
126 QTest::newRow("-1 1") << -1.0 << 1.0;
127 QTest::newRow("0 1") << 0.0 << 1.0;
127 QTest::newRow("0 1") << 0.0 << 1.0;
128 QTest::newRow("-1 0") << -1.0 << 0.0;
128 QTest::newRow("-1 0") << -1.0 << 0.0;
129 }
129 }
130
130
131 void tst_Domain::handleAxisUpdatedX()
131 void tst_Domain::handleAxisUpdatedX()
132 {
132 {
133 QFETCH(qreal, min);
133 QFETCH(qreal, min);
134 QFETCH(qreal, max);
134 QFETCH(qreal, max);
135
135
136 Domain domain;
136 Domain domain;
137
137
138 QSignalSpy spy0(&domain, SIGNAL(updated()));
138 QSignalSpy spy0(&domain, SIGNAL(updated()));
139 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
139 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
140 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
140 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
141
141
142 AxisMock axis(Qt::Horizontal);
142 AxisMock axis(Qt::Horizontal);
143 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
143 QObject::connect(&axis,SIGNAL(updated()),&domain,SLOT(handleAxisUpdated()));
144 axis.m_min=min;
144 axis.m_min=min;
145 axis.m_max=max;
145 axis.m_max=max;
146 axis.emitUpdated();
146 axis.emitUpdated();
147
147
148 QVERIFY(qFuzzyIsNull(domain.minX() - min));
148 QVERIFY(qFuzzyIsNull(domain.minX() - min));
149 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
149 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
150
150
151 QList<QVariant> arg1 = spy1.first();
151 QList<QVariant> arg1 = spy1.first();
152 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
152 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
153 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
153 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
154
154
155 TRY_COMPARE(spy0.count(), 1);
155 TRY_COMPARE(spy0.count(), 1);
156 TRY_COMPARE(spy1.count(), 1);
156 TRY_COMPARE(spy1.count(), 1);
157 TRY_COMPARE(spy2.count(), 0);
157 TRY_COMPARE(spy2.count(), 0);
158
158
159 }
159 }
160
160
161 void tst_Domain::handleAxisUpdatedY_data()
161 void tst_Domain::handleAxisUpdatedY_data()
162 {
162 {
163 QTest::addColumn<qreal>("min");
163 QTest::addColumn<qreal>("min");
164 QTest::addColumn<qreal>("max");
164 QTest::addColumn<qreal>("max");
165 QTest::newRow("-1 1") << -1.0 << 1.0;
165 QTest::newRow("-1 1") << -1.0 << 1.0;
166 QTest::newRow("0 1") << 0.0 << 1.0;
166 QTest::newRow("0 1") << 0.0 << 1.0;
167 QTest::newRow("-1 0") << -1.0 << 0.0;
167 QTest::newRow("-1 0") << -1.0 << 0.0;
168 }
168 }
169
169
170 void tst_Domain::handleAxisUpdatedY()
170 void tst_Domain::handleAxisUpdatedY()
171 {
171 {
172 QFETCH(qreal, min);
172 QFETCH(qreal, min);
173 QFETCH(qreal, max);
173 QFETCH(qreal, max);
174
174
175 Domain domain;
175 Domain domain;
176
176
177 QSignalSpy spy0(&domain, SIGNAL(updated()));
177 QSignalSpy spy0(&domain, SIGNAL(updated()));
178 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
178 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
179 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
179 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
180
180
181 AxisMock axis(Qt::Vertical);
181 AxisMock axis(Qt::Vertical);
182 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
182 QObject::connect(&axis, SIGNAL(updated()), &domain, SLOT(handleAxisUpdated()));
183 axis.m_min = min;
183 axis.m_min = min;
184 axis.m_max = max;
184 axis.m_max = max;
185 axis.emitUpdated();
185 axis.emitUpdated();
186
186
187 QVERIFY(qFuzzyIsNull(domain.minY() - min));
187 QVERIFY(qFuzzyIsNull(domain.minY() - min));
188 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
188 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
189
189
190 QList<QVariant> arg1 = spy2.first();
190 QList<QVariant> arg1 = spy2.first();
191 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
191 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
192 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
192 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
193
193
194 TRY_COMPARE(spy0.count(), 1);
194 TRY_COMPARE(spy0.count(), 1);
195 TRY_COMPARE(spy1.count(), 0);
195 TRY_COMPARE(spy1.count(), 0);
196 TRY_COMPARE(spy2.count(), 1);
196 TRY_COMPARE(spy2.count(), 1);
197 }
197 }
198
198
199 void tst_Domain::isEmpty_data()
199 void tst_Domain::isEmpty_data()
200 {
200 {
201 QTest::addColumn<qreal>("minX");
201 QTest::addColumn<qreal>("minX");
202 QTest::addColumn<qreal>("maxX");
202 QTest::addColumn<qreal>("maxX");
203 QTest::addColumn<qreal>("minY");
203 QTest::addColumn<qreal>("minY");
204 QTest::addColumn<qreal>("maxY");
204 QTest::addColumn<qreal>("maxY");
205 QTest::addColumn<bool>("isEmpty");
205 QTest::addColumn<bool>("isEmpty");
206 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
206 QTest::newRow("0 0 0 0") << 0.0 << 0.0 << 0.0 << 0.0 << true;
207 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
207 QTest::newRow("0 1 0 0") << 0.0 << 1.0 << 0.0 << 0.0 << true;
208 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
208 QTest::newRow("0 0 0 1") << 0.0 << 1.0 << 0.0 << 0.0 << true;
209 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
209 QTest::newRow("0 1 0 1") << 0.0 << 1.0 << 0.0 << 1.0 << false;
210 }
210 }
211
211
212 void tst_Domain::isEmpty()
212 void tst_Domain::isEmpty()
213 {
213 {
214 QFETCH(qreal, minX);
214 QFETCH(qreal, minX);
215 QFETCH(qreal, maxX);
215 QFETCH(qreal, maxX);
216 QFETCH(qreal, minY);
216 QFETCH(qreal, minY);
217 QFETCH(qreal, maxY);
217 QFETCH(qreal, maxY);
218 QFETCH(bool, isEmpty);
218 QFETCH(bool, isEmpty);
219
219
220 Domain domain;
220 Domain domain;
221 domain.setRange(minX, maxX, minY, maxY);
221 domain.setRange(minX, maxX, minY, maxY);
222 QCOMPARE(domain.isEmpty(), isEmpty);
222 QCOMPARE(domain.isEmpty(), isEmpty);
223 }
223 }
224
224
225 void tst_Domain::maxX_data()
225 void tst_Domain::maxX_data()
226 {
226 {
227 QTest::addColumn<qreal>("maxX1");
227 QTest::addColumn<qreal>("maxX1");
228 QTest::addColumn<qreal>("maxX2");
228 QTest::addColumn<qreal>("maxX2");
229 QTest::addColumn<int>("count");
229 QTest::addColumn<int>("count");
230 QTest::newRow("1") << 0.0 << 1.0 << 1;
230 QTest::newRow("1") << 0.0 << 1.0 << 1;
231 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
231 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
232 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
232 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
233 }
233 }
234
234
235 void tst_Domain::maxX()
235 void tst_Domain::maxX()
236 {
236 {
237 QFETCH(qreal, maxX1);
237 QFETCH(qreal, maxX1);
238 QFETCH(qreal, maxX2);
238 QFETCH(qreal, maxX2);
239 QFETCH(int, count);
239 QFETCH(int, count);
240
240
241 Domain domain;
241 Domain domain;
242
242
243 QSignalSpy spy0(&domain, SIGNAL(updated()));
243 QSignalSpy spy0(&domain, SIGNAL(updated()));
244 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
244 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
245 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
245 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
246
246
247 domain.setMaxX(maxX1);
247 domain.setMaxX(maxX1);
248 QCOMPARE(domain.maxX(), maxX1);
248 QCOMPARE(domain.maxX(), maxX1);
249 domain.setMaxX(maxX2);
249 domain.setMaxX(maxX2);
250 QCOMPARE(domain.maxX(), maxX2);
250 QCOMPARE(domain.maxX(), maxX2);
251
251
252 TRY_COMPARE(spy0.count(), count);
252 TRY_COMPARE(spy0.count(), count);
253 TRY_COMPARE(spy1.count(), count);
253 TRY_COMPARE(spy1.count(), count);
254 TRY_COMPARE(spy2.count(), 0);
254 TRY_COMPARE(spy2.count(), 0);
255
255
256 }
256 }
257
257
258 void tst_Domain::maxY_data()
258 void tst_Domain::maxY_data()
259 {
259 {
260 QTest::addColumn<qreal>("maxY1");
260 QTest::addColumn<qreal>("maxY1");
261 QTest::addColumn<qreal>("maxY2");
261 QTest::addColumn<qreal>("maxY2");
262 QTest::addColumn<int>("count");
262 QTest::addColumn<int>("count");
263 QTest::newRow("1") << 0.0 << 1.0 << 1;
263 QTest::newRow("1") << 0.0 << 1.0 << 1;
264 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
264 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
265 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
265 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
266 }
266 }
267
267
268 void tst_Domain::maxY()
268 void tst_Domain::maxY()
269 {
269 {
270 QFETCH(qreal, maxY1);
270 QFETCH(qreal, maxY1);
271 QFETCH(qreal, maxY2);
271 QFETCH(qreal, maxY2);
272 QFETCH(int, count);
272 QFETCH(int, count);
273
273
274 Domain domain;
274 Domain domain;
275
275
276 QSignalSpy spy0(&domain, SIGNAL(updated()));
276 QSignalSpy spy0(&domain, SIGNAL(updated()));
277 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
277 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
278 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
278 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
279
279
280 domain.setMaxY(maxY1);
280 domain.setMaxY(maxY1);
281 QCOMPARE(domain.maxY(), maxY1);
281 QCOMPARE(domain.maxY(), maxY1);
282 domain.setMaxY(maxY2);
282 domain.setMaxY(maxY2);
283 QCOMPARE(domain.maxY(), maxY2);
283 QCOMPARE(domain.maxY(), maxY2);
284
284
285 TRY_COMPARE(spy0.count(), count);
285 TRY_COMPARE(spy0.count(), count);
286 TRY_COMPARE(spy1.count(), 0);
286 TRY_COMPARE(spy1.count(), 0);
287 TRY_COMPARE(spy2.count(), count);
287 TRY_COMPARE(spy2.count(), count);
288 }
288 }
289
289
290 void tst_Domain::minX_data()
290 void tst_Domain::minX_data()
291 {
291 {
292 QTest::addColumn<qreal>("minX1");
292 QTest::addColumn<qreal>("minX1");
293 QTest::addColumn<qreal>("minX2");
293 QTest::addColumn<qreal>("minX2");
294 QTest::addColumn<int>("count");
294 QTest::addColumn<int>("count");
295 QTest::newRow("1") << 0.0 << 1.0 << 1;
295 QTest::newRow("1") << 0.0 << 1.0 << 1;
296 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
296 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
297 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
297 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
298 }
298 }
299
299
300 void tst_Domain::minX()
300 void tst_Domain::minX()
301 {
301 {
302 QFETCH(qreal, minX1);
302 QFETCH(qreal, minX1);
303 QFETCH(qreal, minX2);
303 QFETCH(qreal, minX2);
304 QFETCH(int, count);
304 QFETCH(int, count);
305
305
306 Domain domain;
306 Domain domain;
307
307
308 QSignalSpy spy0(&domain, SIGNAL(updated()));
308 QSignalSpy spy0(&domain, SIGNAL(updated()));
309 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
309 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
310 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
310 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
311
311
312 domain.setMinX(minX1);
312 domain.setMinX(minX1);
313 QCOMPARE(domain.minX(), minX1);
313 QCOMPARE(domain.minX(), minX1);
314 domain.setMinX(minX2);
314 domain.setMinX(minX2);
315 QCOMPARE(domain.minX(), minX2);
315 QCOMPARE(domain.minX(), minX2);
316
316
317 TRY_COMPARE(spy0.count(), count);
317 TRY_COMPARE(spy0.count(), count);
318 TRY_COMPARE(spy1.count(), count);
318 TRY_COMPARE(spy1.count(), count);
319 TRY_COMPARE(spy2.count(), 0);
319 TRY_COMPARE(spy2.count(), 0);
320 }
320 }
321
321
322 void tst_Domain::minY_data()
322 void tst_Domain::minY_data()
323 {
323 {
324 QTest::addColumn<qreal>("minY1");
324 QTest::addColumn<qreal>("minY1");
325 QTest::addColumn<qreal>("minY2");
325 QTest::addColumn<qreal>("minY2");
326 QTest::addColumn<int>("count");
326 QTest::addColumn<int>("count");
327 QTest::newRow("1") << 0.0 << 1.0 << 1;
327 QTest::newRow("1") << 0.0 << 1.0 << 1;
328 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
328 QTest::newRow("1.0") << 1.0 << 1.0 << 1;
329 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
329 QTest::newRow("2.0") << 1.0 << 0.0 << 2;
330 }
330 }
331
331
332 void tst_Domain::minY()
332 void tst_Domain::minY()
333 {
333 {
334 QFETCH(qreal, minY1);
334 QFETCH(qreal, minY1);
335 QFETCH(qreal, minY2);
335 QFETCH(qreal, minY2);
336 QFETCH(int, count);
336 QFETCH(int, count);
337
337
338 Domain domain;
338 Domain domain;
339
339
340 QSignalSpy spy0(&domain, SIGNAL(updated()));
340 QSignalSpy spy0(&domain, SIGNAL(updated()));
341 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
341 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
342 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
342 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
343
343
344 domain.setMinY(minY1);
344 domain.setMinY(minY1);
345 QCOMPARE(domain.minY(), minY1);
345 QCOMPARE(domain.minY(), minY1);
346 domain.setMinY(minY2);
346 domain.setMinY(minY2);
347 QCOMPARE(domain.minY(), minY2);
347 QCOMPARE(domain.minY(), minY2);
348
348
349 TRY_COMPARE(spy0.count(), count);
349 TRY_COMPARE(spy0.count(), count);
350 TRY_COMPARE(spy1.count(), 0);
350 TRY_COMPARE(spy1.count(), 0);
351 TRY_COMPARE(spy2.count(), count);
351 TRY_COMPARE(spy2.count(), count);
352 }
352 }
353
353
354 void tst_Domain::operatorEquals_data()
354 void tst_Domain::operatorEquals_data()
355 {
355 {
356
356
357 QTest::addColumn<Domain*>("domain1");
357 QTest::addColumn<Domain*>("domain1");
358 QTest::addColumn<Domain*>("domain2");
358 QTest::addColumn<Domain*>("domain2");
359 QTest::addColumn<bool>("equals");
359 QTest::addColumn<bool>("equals");
360 QTest::addColumn<bool>("notEquals");
360 QTest::addColumn<bool>("notEquals");
361 Domain* a;
361 Domain* a;
362 Domain* b;
362 Domain* b;
363 a = new Domain();
363 a = new Domain();
364 a->setRange(0, 100, 0, 100);
364 a->setRange(0, 100, 0, 100);
365 b = new Domain();
365 b = new Domain();
366 b->setRange(0, 100, 0, 100);
366 b->setRange(0, 100, 0, 100);
367 QTest::newRow("equals") << a << b << true << false;
367 QTest::newRow("equals") << a << b << true << false;
368 a = new Domain();
368 a = new Domain();
369 a->setRange(0, 100, 0, 100);
369 a->setRange(0, 100, 0, 100);
370 b = new Domain();
370 b = new Domain();
371 b->setRange(0, 100, 0, 1);
371 b->setRange(0, 100, 0, 1);
372 QTest::newRow("equals") << a << b << false << true;
372 QTest::newRow("equals") << a << b << false << true;
373 a = new Domain();
373 a = new Domain();
374 a->setRange(0, 100, 0, 100);
374 a->setRange(0, 100, 0, 100);
375 b = new Domain();
375 b = new Domain();
376 b->setRange(0, 1, 0, 100);
376 b->setRange(0, 1, 0, 100);
377 QTest::newRow("equals") << a << b << false << true;
377 QTest::newRow("equals") << a << b << false << true;
378
378
379 }
379 }
380
380
381 void tst_Domain::operatorEquals()
381 void tst_Domain::operatorEquals()
382 {
382 {
383 QFETCH(Domain*, domain1);
383 QFETCH(Domain*, domain1);
384 QFETCH(Domain*, domain2);
384 QFETCH(Domain*, domain2);
385 QFETCH(bool, equals);
385 QFETCH(bool, equals);
386 QFETCH(bool, notEquals);
386 QFETCH(bool, notEquals);
387
387
388 Domain domain;
388 Domain domain;
389
389
390 QSignalSpy spy0(&domain, SIGNAL(updated()));
390 QSignalSpy spy0(&domain, SIGNAL(updated()));
391 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
391 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
392 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
392 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
393
393
394 QCOMPARE(*domain1==*domain2, equals);
394 QCOMPARE(*domain1==*domain2, equals);
395 QCOMPARE(*domain1!=*domain2, notEquals);
395 QCOMPARE(*domain1!=*domain2, notEquals);
396
396
397 TRY_COMPARE(spy0.count(), 0);
397 TRY_COMPARE(spy0.count(), 0);
398 TRY_COMPARE(spy1.count(), 0);
398 TRY_COMPARE(spy1.count(), 0);
399 TRY_COMPARE(spy2.count(), 0);
399 TRY_COMPARE(spy2.count(), 0);
400 }
400 }
401
401
402 void tst_Domain::setRange_data()
402 void tst_Domain::setRange_data()
403 {
403 {
404 QTest::addColumn<qreal>("minX");
404 QTest::addColumn<qreal>("minX");
405 QTest::addColumn<qreal>("maxX");
405 QTest::addColumn<qreal>("maxX");
406 QTest::addColumn<qreal>("minY");
406 QTest::addColumn<qreal>("minY");
407 QTest::addColumn<qreal>("maxY");
407 QTest::addColumn<qreal>("maxY");
408 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
408 QTest::newRow("1,2,1,2") << 1.0 << 2.0 << 1.0 << 2.0;
409 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
409 QTest::newRow("1,3,1,3") << 1.0 << 3.0 << 1.0 << 3.0;
410 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
410 QTest::newRow("-1,5,-2,-1") << -1.0 << 5.0 << -2.0 << -1.0;
411 }
411 }
412
412
413 void tst_Domain::setRange()
413 void tst_Domain::setRange()
414 {
414 {
415 QFETCH(qreal, minX);
415 QFETCH(qreal, minX);
416 QFETCH(qreal, maxX);
416 QFETCH(qreal, maxX);
417 QFETCH(qreal, minY);
417 QFETCH(qreal, minY);
418 QFETCH(qreal, maxY);
418 QFETCH(qreal, maxY);
419
419
420 Domain domain;
420 Domain domain;
421
421
422 QSignalSpy spy0(&domain, SIGNAL(updated()));
422 QSignalSpy spy0(&domain, SIGNAL(updated()));
423 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
423 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
424 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
424 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
425
425
426 domain.setRange(minX, maxX, minY, maxY);
426 domain.setRange(minX, maxX, minY, maxY);
427
427
428 QCOMPARE(domain.minX(), minX);
428 QCOMPARE(domain.minX(), minX);
429 QCOMPARE(domain.maxX(), maxX);
429 QCOMPARE(domain.maxX(), maxX);
430 QCOMPARE(domain.minY(), minY);
430 QCOMPARE(domain.minY(), minY);
431 QCOMPARE(domain.maxY(), maxY);
431 QCOMPARE(domain.maxY(), maxY);
432
432
433 TRY_COMPARE(spy0.count(), 1);
433 TRY_COMPARE(spy0.count(), 1);
434 TRY_COMPARE(spy1.count(), 1);
434 TRY_COMPARE(spy1.count(), 1);
435 TRY_COMPARE(spy2.count(), 1);
435 TRY_COMPARE(spy2.count(), 1);
436
436
437 }
437 }
438
438
439 void tst_Domain::setRangeX_data()
439 void tst_Domain::setRangeX_data()
440 {
440 {
441 QTest::addColumn<qreal>("min");
441 QTest::addColumn<qreal>("min");
442 QTest::addColumn<qreal>("max");
442 QTest::addColumn<qreal>("max");
443 QTest::newRow("-1 1") << -1.0 << 1.0;
443 QTest::newRow("-1 1") << -1.0 << 1.0;
444 QTest::newRow("0 1") << 0.0 << 1.0;
444 QTest::newRow("0 1") << 0.0 << 1.0;
445 QTest::newRow("-1 0") << -1.0 << 0.0;
445 QTest::newRow("-1 0") << -1.0 << 0.0;
446 }
446 }
447
447
448 void tst_Domain::setRangeX()
448 void tst_Domain::setRangeX()
449 {
449 {
450 QFETCH(qreal, min);
450 QFETCH(qreal, min);
451 QFETCH(qreal, max);
451 QFETCH(qreal, max);
452
452
453 Domain domain;
453 Domain domain;
454
454
455 QSignalSpy spy0(&domain, SIGNAL(updated()));
455 QSignalSpy spy0(&domain, SIGNAL(updated()));
456 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
456 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
457 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
457 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
458
458
459 domain.setRangeX(min, max);
459 domain.setRangeX(min, max);
460
460
461 QVERIFY(qFuzzyIsNull(domain.minX() - min));
461 QVERIFY(qFuzzyIsNull(domain.minX() - min));
462 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
462 QVERIFY(qFuzzyIsNull(domain.maxX() - max));
463
463
464 QList<QVariant> arg1 = spy1.first();
464 QList<QVariant> arg1 = spy1.first();
465 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
465 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
466 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
466 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
467
467
468 TRY_COMPARE(spy0.count(), 1);
468 TRY_COMPARE(spy0.count(), 1);
469 TRY_COMPARE(spy1.count(), 1);
469 TRY_COMPARE(spy1.count(), 1);
470 TRY_COMPARE(spy2.count(), 0);
470 TRY_COMPARE(spy2.count(), 0);
471 }
471 }
472
472
473 void tst_Domain::setRangeY_data()
473 void tst_Domain::setRangeY_data()
474 {
474 {
475 QTest::addColumn<qreal>("min");
475 QTest::addColumn<qreal>("min");
476 QTest::addColumn<qreal>("max");
476 QTest::addColumn<qreal>("max");
477 QTest::newRow("-1 1") << -1.0 << 1.0;
477 QTest::newRow("-1 1") << -1.0 << 1.0;
478 QTest::newRow("0 1") << 0.0 << 1.0;
478 QTest::newRow("0 1") << 0.0 << 1.0;
479 QTest::newRow("-1 0") << -1.0 << 0.0;
479 QTest::newRow("-1 0") << -1.0 << 0.0;
480 }
480 }
481
481
482 void tst_Domain::setRangeY()
482 void tst_Domain::setRangeY()
483 {
483 {
484 QFETCH(qreal, min);
484 QFETCH(qreal, min);
485 QFETCH(qreal, max);
485 QFETCH(qreal, max);
486
486
487 Domain domain;
487 Domain domain;
488
488
489 QSignalSpy spy0(&domain, SIGNAL(updated()));
489 QSignalSpy spy0(&domain, SIGNAL(updated()));
490 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
490 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
491 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
491 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
492
492
493 domain.setRangeY(min, max);
493 domain.setRangeY(min, max);
494
494
495 QVERIFY(qFuzzyIsNull(domain.minY() - min));
495 QVERIFY(qFuzzyIsNull(domain.minY() - min));
496 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
496 QVERIFY(qFuzzyIsNull(domain.maxY() - max));
497
497
498 QList<QVariant> arg1 = spy2.first();
498 QList<QVariant> arg1 = spy2.first();
499 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
499 QVERIFY(qFuzzyIsNull(arg1.at(0).toReal() - min));
500 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
500 QVERIFY(qFuzzyIsNull(arg1.at(1).toReal() - max));
501
501
502 TRY_COMPARE(spy0.count(), 1);
502 TRY_COMPARE(spy0.count(), 1);
503 TRY_COMPARE(spy1.count(), 0);
503 TRY_COMPARE(spy1.count(), 0);
504 TRY_COMPARE(spy2.count(), 1);
504 TRY_COMPARE(spy2.count(), 1);
505 }
505 }
506
506
507 void tst_Domain::spanX_data()
507 void tst_Domain::spanX_data()
508 {
508 {
509 QTest::addColumn<qreal>("minX");
509 QTest::addColumn<qreal>("minX");
510 QTest::addColumn<qreal>("maxX");
510 QTest::addColumn<qreal>("maxX");
511 QTest::addColumn<qreal>("spanX");
511 QTest::addColumn<qreal>("spanX");
512 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
512 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
513 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
513 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
514 }
514 }
515
515
516 void tst_Domain::spanX()
516 void tst_Domain::spanX()
517 {
517 {
518 QFETCH(qreal, minX);
518 QFETCH(qreal, minX);
519 QFETCH(qreal, maxX);
519 QFETCH(qreal, maxX);
520 QFETCH(qreal, spanX);
520 QFETCH(qreal, spanX);
521
521
522 Domain domain;
522 Domain domain;
523
523
524 domain.setRangeX(minX, maxX);
524 domain.setRangeX(minX, maxX);
525
525
526 QSignalSpy spy0(&domain, SIGNAL(updated()));
526 QSignalSpy spy0(&domain, SIGNAL(updated()));
527 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
527 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
528 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
528 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
529
529
530 QCOMPARE(domain.spanX(), spanX);
530 QCOMPARE(domain.spanX(), spanX);
531
531
532 TRY_COMPARE(spy0.count(), 0);
532 TRY_COMPARE(spy0.count(), 0);
533 TRY_COMPARE(spy1.count(), 0);
533 TRY_COMPARE(spy1.count(), 0);
534 TRY_COMPARE(spy2.count(), 0);
534 TRY_COMPARE(spy2.count(), 0);
535 }
535 }
536
536
537 void tst_Domain::spanY_data()
537 void tst_Domain::spanY_data()
538 {
538 {
539 QTest::addColumn<qreal>("minY");
539 QTest::addColumn<qreal>("minY");
540 QTest::addColumn<qreal>("maxY");
540 QTest::addColumn<qreal>("maxY");
541 QTest::addColumn<qreal>("spanY");
541 QTest::addColumn<qreal>("spanY");
542 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
542 QTest::newRow("1 2 1") << 1.0 << 2.0 << 1.0;
543 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
543 QTest::newRow("0 2 2") << 1.0 << 2.0 << 1.0;
544 }
544 }
545
545
546 void tst_Domain::spanY()
546 void tst_Domain::spanY()
547 {
547 {
548 QFETCH(qreal, minY);
548 QFETCH(qreal, minY);
549 QFETCH(qreal, maxY);
549 QFETCH(qreal, maxY);
550 QFETCH(qreal, spanY);
550 QFETCH(qreal, spanY);
551
551
552 Domain domain;
552 Domain domain;
553
553
554 domain.setRangeY(minY, maxY);
554 domain.setRangeY(minY, maxY);
555
555
556 QSignalSpy spy0(&domain, SIGNAL(updated()));
556 QSignalSpy spy0(&domain, SIGNAL(updated()));
557 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
557 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
558 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
558 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
559
559
560 QCOMPARE(domain.spanY(), spanY);
560 QCOMPARE(domain.spanY(), spanY);
561
561
562 TRY_COMPARE(spy0.count(), 0);
562 TRY_COMPARE(spy0.count(), 0);
563 TRY_COMPARE(spy1.count(), 0);
563 TRY_COMPARE(spy1.count(), 0);
564 TRY_COMPARE(spy2.count(), 0);
564 TRY_COMPARE(spy2.count(), 0);
565 }
565 }
566
566
567 void tst_Domain::zoom_data()
567 void tst_Domain::zoom_data()
568 {
568 {
569 QTest::addColumn<QRectF>("rect0");
569 QTest::addColumn<QRectF>("rect0");
570 QTest::addColumn<QSizeF>("size0");
570 QTest::addColumn<QSizeF>("size0");
571 QTest::addColumn<QRectF>("rect1");
571 QTest::addColumn<QRectF>("rect1");
572 QTest::addColumn<QSizeF>("size1");
572 QTest::addColumn<QSizeF>("size1");
573 QTest::addColumn<QRectF>("rect2");
573 QTest::addColumn<QRectF>("rect2");
574 QTest::addColumn<QSizeF>("size2");
574 QTest::addColumn<QSizeF>("size2");
575 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
575 QTest::newRow("first") << QRectF(10, 10, 100, 100) << QSizeF(1000, 1000)
576 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
576 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
577 << QSizeF(1000, 1000);
577 << QSizeF(1000, 1000);
578 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
578 QTest::newRow("scound") << QRectF(10, 10, 50, 50) << QSizeF(1000, 1000)
579 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
579 << QRectF(20, 20, 100, 100) << QSizeF(1000, 1000) << QRectF(50, 50, 100, 100)
580 << QSizeF(1000, 1000);
580 << QSizeF(1000, 1000);
581 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
581 QTest::newRow("third") << QRectF(10, 10, 10, 10) << QSizeF(100, 100) << QRectF(20, 20, 20, 20)
582 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
582 << QSizeF(100, 100) << QRectF(50, 50, 50, 50) << QSizeF(100, 100);
583 }
583 }
584
584
585 void tst_Domain::zoom()
585 void tst_Domain::zoom()
586 {
586 {
587 QFETCH(QRectF, rect0);
587 QFETCH(QRectF, rect0);
588 QFETCH(QSizeF, size0);
588 QFETCH(QSizeF, size0);
589 QFETCH(QRectF, rect1);
589 QFETCH(QRectF, rect1);
590 QFETCH(QSizeF, size1);
590 QFETCH(QSizeF, size1);
591 QFETCH(QRectF, rect2);
591 QFETCH(QRectF, rect2);
592 QFETCH(QSizeF, size2);
592 QFETCH(QSizeF, size2);
593
593
594 Domain domain;
594 Domain domain;
595
595
596 domain.setRange(0, 1000, 0, 1000);
596 domain.setRange(0, 1000, 0, 1000);
597
597
598 QSignalSpy spy0(&domain, SIGNAL(updated()));
598 QSignalSpy spy0(&domain, SIGNAL(updated()));
599 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
599 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
600 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
600 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
601
601
602 Domain domain0;
602 Domain domain0;
603 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
603 domain0.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
604 domain.zoomIn(rect0, size0);
604 domain.zoomIn(rect0, size0);
605 Domain domain1;
605 Domain domain1;
606 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
606 domain1.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
607 domain.zoomIn(rect1, size1);
607 domain.zoomIn(rect1, size1);
608 Domain domain2;
608 Domain domain2;
609 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
609 domain2.setRange(domain.minX(), domain.maxX(), domain.minY(), domain.maxY());
610 domain.zoomIn(rect2, size2);
610 domain.zoomIn(rect2, size2);
611 domain.zoomOut(rect2, size2);
611 domain.zoomOut(rect2, size2);
612 QCOMPARE(domain == domain2, true);
612 QCOMPARE(domain == domain2, true);
613 domain.zoomOut(rect1, size1);
613 domain.zoomOut(rect1, size1);
614 QCOMPARE(domain == domain1, true);
614 QCOMPARE(domain == domain1, true);
615 domain.zoomOut(rect0, size0);
615 domain.zoomOut(rect0, size0);
616 QCOMPARE(domain == domain0, true);
616 QCOMPARE(domain == domain0, true);
617 TRY_COMPARE(spy0.count(), 6);
617 TRY_COMPARE(spy0.count(), 6);
618 TRY_COMPARE(spy1.count(), 6);
618 TRY_COMPARE(spy1.count(), 6);
619 TRY_COMPARE(spy2.count(), 6);
619 TRY_COMPARE(spy2.count(), 6);
620 }
620 }
621
621
622 void tst_Domain::move_data()
622 void tst_Domain::move_data()
623 {
623 {
624 QTest::addColumn<int>("dx");
624 QTest::addColumn<int>("dx");
625 QTest::addColumn<int>("dy");
625 QTest::addColumn<int>("dy");
626 QTest::addColumn<QSizeF>("size");
626 QTest::addColumn<QSizeF>("size");
627 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
627 QTest::newRow("dx 100, dy 0, size 1000x1000") << 100 << 0 << QSizeF(1000, 1000);
628 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
628 QTest::newRow("dx 0, dy 100, size 1000x1000") << 0 << 100 << QSizeF(1000, 1000);
629 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
629 QTest::newRow("dx -100, dy 0, size 1000x1000") << -100 << 0 << QSizeF(1000, 1000);
630 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
630 QTest::newRow("dx 0, dy -100, size 1000x1000") << 0 << -100 << QSizeF(1000, 1000);
631 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
631 QTest::newRow("dx 100, dy 100, size 1000x1000") << 100 << 100 << QSizeF(1000, 1000);
632 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
632 QTest::newRow("dx 100, dy 50, size 1000x1000") << 100 << 50 << QSizeF(1000, 1000);
633 }
633 }
634
634
635 void tst_Domain::move()
635 void tst_Domain::move()
636 {
636 {
637 QFETCH(int, dx);
637 QFETCH(int, dx);
638 QFETCH(int, dy);
638 QFETCH(int, dy);
639 QFETCH(QSizeF, size);
639 QFETCH(QSizeF, size);
640 Domain domain;
640 Domain domain;
641
641
642 domain.setRange(0, size.width(), 0, size.height());
642 domain.setRange(0, size.width(), 0, size.height());
643
643
644 QSignalSpy spy0(&domain, SIGNAL(updated()));
644 QSignalSpy spy0(&domain, SIGNAL(updated()));
645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
645 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
646 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
647
647
648 domain.move(dx, dy, size);
648 domain.move(dx, dy, size);
649
649
650 Domain result;
650 Domain result;
651 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
651 result.setRange(dx, size.width() + dx, dy, size.height() + dy);
652
652
653 QCOMPARE(domain == result, true);
653 QCOMPARE(domain == result, true);
654 TRY_COMPARE(spy0.count(), 1);
654 TRY_COMPARE(spy0.count(), 1);
655 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
655 TRY_COMPARE(spy1.count(), (dx != 0 ? 1 : 0));
656 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
656 TRY_COMPARE(spy2.count(), (dy != 0 ? 1 : 0));
657 }
657 }
658
658
659 /*
660 void tst_Domain::handleAxisXChanged_data()
661 {
662 QTest::addColumn<qreal>("min");
663 QTest::addColumn<qreal>("max");
664 QTest::addColumn<int>("tickCount");
665 QTest::addColumn<bool>("niceNumbers");
666 QTest::addColumn<qreal>("resultMin");
667 QTest::addColumn<qreal>("resultMax");
668 QTest::addColumn<int>("resultTickCount");
669 QTest::newRow("0,100,5,false") << 0.0 << 100.0 << 5 << false << 0.0 << 100.0 << 5;
670 QTest::newRow("0,100,5,true") << 0.0 << 100.0 << 5 << true << 0.0 << 100.0 << 6;
671 QTest::newRow("0.1,99,5,true") << 0.1 << 99.0 << 5 << true << 0.0 << 100.0 << 6;
672 QTest::newRow("5,93.5,true") << 5.0 << 93.5 << 5 << true << 0.0 << 100.0 << 6;
673 }
674
675 void tst_Domain::handleAxisXChanged()
676 {
677 QFETCH(qreal, min);
678 QFETCH(qreal, max);
679 QFETCH(int, tickCount);
680 QFETCH(bool, niceNumbers);
681 QFETCH(qreal, resultMin);
682 QFETCH(qreal, resultMax);
683 QFETCH(int, resultTickCount);
684
685 Domain domain;
686 QSignalSpy spy0(&domain, SIGNAL(updated()));
687 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
688 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
689
690 // domain.handleAxisXChanged(min, max, tickCount, niceNumbers);
691
692 QCOMPARE(resultMin, domain.minX());
693 QCOMPARE(resultMax, domain.maxX());
694 // QCOMPARE(resultTickCount, domain.tickXCount());
695 TRY_COMPARE(spy0.count(), 1);
696 TRY_COMPARE(spy1.count(), 1);
697 TRY_COMPARE(spy2.count(), 0);
698
699 }
700
701 void tst_Domain::handleAxisYChanged_data()
702 {
703 handleAxisXChanged_data();
704 }
705
706 void tst_Domain::handleAxisYChanged()
707 {
708 QFETCH(qreal, min);
709 QFETCH(qreal, max);
710 QFETCH(int, tickCount);
711 QFETCH(bool, niceNumbers);
712 QFETCH(qreal, resultMin);
713 QFETCH(qreal, resultMax);
714 QFETCH(int, resultTickCount);
715
716 Domain domain;
717 QSignalSpy spy0(&domain, SIGNAL(updated()));
718 QSignalSpy spy1(&domain, SIGNAL(rangeXChanged(qreal,qreal)));
719 QSignalSpy spy2(&domain, SIGNAL(rangeYChanged(qreal,qreal)));
720
721 // domain.handleAxisYChanged(min, max, tickCount, niceNumbers);
722
723 QCOMPARE(resultMin, domain.minY());
724 QCOMPARE(resultMax, domain.maxY());
725 // QCOMPARE(resultTickCount, domain.tickYCount());
726 TRY_COMPARE(spy0.count(), 1);
727 TRY_COMPARE(spy1.count(), 0);
728 TRY_COMPARE(spy2.count(), 1);
729 }
730 */
731 QTEST_MAIN(tst_Domain)
659 QTEST_MAIN(tst_Domain)
732 #include "tst_domain.moc"
660 #include "tst_domain.moc"
733
661
@@ -1,432 +1,351
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
38
39 void max_raw_data();
40 void max_raw();
39 void max_data();
41 void max_data();
40 void max();
42 void max();
43 void max_animation_data();
44 void max_animation();
45 void min_raw_data();
46 void min_raw();
41 void min_data();
47 void min_data();
42 void min();
48 void min();
49 void min_animation_data();
50 void min_animation();
43 void niceNumbersEnabled_data();
51 void niceNumbersEnabled_data();
44 void niceNumbersEnabled();
52 void niceNumbersEnabled();
45 void setNiceNumbersEnabled_data();
53 void range_raw_data();
46 void setNiceNumbersEnabled();
54 void range_raw();
47 void setRange_data();
55 void range_data();
48 void setRange();
56 void range();
49 void setTicksCount_data();
57 void range_animation_data();
50 void setTicksCount();
58 void range_animation();
51 void ticksCount_data();
59 void ticksCount_data();
52 void ticksCount();
60 void ticksCount();
53 void type_data();
54 void type();
55 void maxChanged_data();
56 void maxChanged();
57 void minChanged_data();
58 void minChanged();
59 void rangeChanged_data();
60 void rangeChanged();
61
61
62 private:
62 private:
63 QValuesAxis* m_valuesaxis;
63 QValuesAxis* m_valuesaxis;
64 QLineSeries* m_series;
64 QLineSeries* m_series;
65 };
65 };
66
66
67
68 void tst_QValuesAxis::initTestCase()
67 void tst_QValuesAxis::initTestCase()
69 {
68 {
70 }
69 }
71
70
72
73 void tst_QValuesAxis::cleanupTestCase()
71 void tst_QValuesAxis::cleanupTestCase()
74 {
72 {
75 }
73 }
76
74
77
78 void tst_QValuesAxis::init()
75 void tst_QValuesAxis::init()
79 {
76 {
80 m_valuesaxis = new QValuesAxis();
77 m_valuesaxis = new QValuesAxis();
81 tst_QAbstractAxis::init(m_valuesaxis);
78 tst_QAbstractAxis::init(m_valuesaxis);
82 m_series = new QLineSeries();
79 m_series = new QLineSeries();
83 *m_series << QPointF(-100,-100) << QPointF(0,0) << QPointF(100,100);
80 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
84 m_chart->addSeries(m_series);
81 m_chart->addSeries(m_series);
85 m_chart->createDefaultAxes();
82 m_chart->createDefaultAxes();
86 }
83 }
87
84
88 void tst_QValuesAxis::cleanup()
85 void tst_QValuesAxis::cleanup()
89 {
86 {
90 delete m_series;
87 delete m_series;
91 delete m_valuesaxis;
88 delete m_valuesaxis;
92 m_series = 0;
89 m_series = 0;
93 m_valuesaxis = 0 ;
90 m_valuesaxis = 0;
94 tst_QAbstractAxis::cleanup();
91 tst_QAbstractAxis::cleanup();
95 }
92 }
96
93
97 void tst_QValuesAxis::qvaluesaxis_data()
94 void tst_QValuesAxis::qvaluesaxis_data()
98 {
95 {
99 }
96 }
100
97
101 void tst_QValuesAxis::qvaluesaxis()
98 void tst_QValuesAxis::qvaluesaxis()
102 {
99 {
103 qabstractaxis();
100 qabstractaxis();
104
101
105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
102 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
103 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
104 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
105 QCOMPARE(m_valuesaxis->ticksCount(), 5);
109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
106 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
110
107
111 m_chart->setAxisX(m_valuesaxis,m_series);
108 m_chart->setAxisX(m_valuesaxis, m_series);
112 m_view->show();
109 m_view->show();
113 QTest::qWaitForWindowShown(m_view);
110 QTest::qWaitForWindowShown(m_view);
114
111
115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
112 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
113 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
114 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
115 QCOMPARE(m_valuesaxis->ticksCount(), 5);
119 }
116 }
120
117
121 void tst_QValuesAxis::max_data()
118 void tst_QValuesAxis::max_raw_data()
122 {
119 {
123 QTest::addColumn<qreal>("max");
120 QTest::addColumn<qreal>("max");
124 QTest::newRow("null") << 0.0;
121 QTest::newRow("1.0") << 1.0;
122 QTest::newRow("50.0") << 50.0;
123 QTest::newRow("101.0") << 101.0;
125 }
124 }
126
125
127 // public qreal max() const
126 void tst_QValuesAxis::max_raw()
128 void tst_QValuesAxis::max()
129 {
127 {
130 #if 0
131 QFETCH(qreal, max);
128 QFETCH(qreal, max);
132
129
133 SubQValuesAxis axis;
130 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
134
131 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
135 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
132 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
136 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
137 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
138
133
139 QCOMPARE(axis.max(), max);
134 m_valuesaxis->setMax(max);
135 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
140
136
141 QCOMPARE(spy0.count(), 0);
137 QCOMPARE(spy0.count(), 1);
142 QCOMPARE(spy1.count(), 0);
138 QCOMPARE(spy1.count(), 0);
143 QCOMPARE(spy2.count(), 0);
139 QCOMPARE(spy2.count(), 1);
144 #endif
145 QSKIP("Test is not implemented.", SkipAll);
146 }
147
148 void tst_QValuesAxis::min_data()
149 {
150 QTest::addColumn<qreal>("min");
151 QTest::newRow("null") << 0.0;
152 }
153
154 // public qreal min() const
155 void tst_QValuesAxis::min()
156 {
157 #if 0
158 QFETCH(qreal, min);
159
160 SubQValuesAxis axis;
161
140
162 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
163 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
164 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
165
166 QCOMPARE(axis.min(), min);
167
168 QCOMPARE(spy0.count(), 0);
169 QCOMPARE(spy1.count(), 0);
170 QCOMPARE(spy2.count(), 0);
171 #endif
172 QSKIP("Test is not implemented.", SkipAll);
173 }
141 }
174
142
175 void tst_QValuesAxis::niceNumbersEnabled_data()
143 void tst_QValuesAxis::max_data()
176 {
144 {
177 QTest::addColumn<bool>("niceNumbersEnabled");
145 max_raw_data();
178 QTest::newRow("true") << true;
179 QTest::newRow("false") << false;
180 }
146 }
181
147
182 // public bool niceNumbersEnabled() const
148 void tst_QValuesAxis::max()
183 void tst_QValuesAxis::niceNumbersEnabled()
184 {
149 {
185 #if 0
150 m_chart->setAxisX(m_valuesaxis, m_series);
186 QFETCH(bool, niceNumbersEnabled);
151 m_view->show();
187
152 QTest::qWaitForWindowShown(m_view);
188 SubQValuesAxis axis;
153 max_raw();
189
190 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
191 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
192 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
193
194 QCOMPARE(axis.niceNumbersEnabled(), niceNumbersEnabled);
195
196 QCOMPARE(spy0.count(), 0);
197 QCOMPARE(spy1.count(), 0);
198 QCOMPARE(spy2.count(), 0);
199 #endif
200 QSKIP("Test is not implemented.", SkipAll);
201 }
154 }
202
155
203
156 void tst_QValuesAxis::max_animation_data()
204 void tst_QValuesAxis::setNiceNumbersEnabled_data()
205 {
157 {
206 QTest::addColumn<bool>("enable");
158 max_data();
207 QTest::newRow("true") << true;
208 QTest::newRow("false") << false;
209 }
159 }
210
160
211 // public void setNiceNumbersEnabled(bool enable = true)
161 void tst_QValuesAxis::max_animation()
212 void tst_QValuesAxis::setNiceNumbersEnabled()
213 {
162 {
214 #if 0
163 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
215 QFETCH(bool, enable);
164 max();
216
217 SubQValuesAxis axis;
218
219 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
220 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
221 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
222
223 axis.setNiceNumbersEnabled(enable);
224
225 QCOMPARE(spy0.count(), 0);
226 QCOMPARE(spy1.count(), 0);
227 QCOMPARE(spy2.count(), 0);
228 #endif
229 QSKIP("Test is not implemented.", SkipAll);
230 }
165 }
231
166
232 void tst_QValuesAxis::setRange_data()
167 void tst_QValuesAxis::min_raw_data()
233 {
168 {
234 QTest::addColumn<qreal>("min");
169 QTest::addColumn<qreal>("min");
235 QTest::addColumn<qreal>("max");
170 QTest::newRow("-1.0") << -1.0;
236 QTest::newRow("null") << 0.0 << 0.0;
171 QTest::newRow("-50.0") << -50.0;
172 QTest::newRow("-101.0") << -101.0;
237 }
173 }
238
174
239 // public void setRange(qreal min, qreal max)
175 void tst_QValuesAxis::min_raw()
240 void tst_QValuesAxis::setRange()
241 {
176 {
242 #if 0
243 QFETCH(qreal, min);
177 QFETCH(qreal, min);
244 QFETCH(qreal, max);
245
178
246 SubQValuesAxis axis;
179 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
180 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
181 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
247
182
248 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
183 m_valuesaxis->setMin(min);
249 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
184 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
250 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
251
252 axis.setRange(min, max);
253
185
254 QCOMPARE(spy0.count(), 0);
186 QCOMPARE(spy0.count(), 0);
255 QCOMPARE(spy1.count(), 0);
187 QCOMPARE(spy1.count(), 1);
256 QCOMPARE(spy2.count(), 0);
188 QCOMPARE(spy2.count(), 1);
257 #endif
258 QSKIP("Test is not implemented.", SkipAll);
259 }
189 }
260
190
261 void tst_QValuesAxis::setTicksCount_data()
191 void tst_QValuesAxis::min_data()
262 {
192 {
263 QTest::addColumn<int>("count");
193 min_raw_data();
264 QTest::newRow("0") << 0;
265 QTest::newRow("-1") << -1;
266 }
194 }
267
195
268 // public void setTicksCount(int count)
196 void tst_QValuesAxis::min()
269 void tst_QValuesAxis::setTicksCount()
270 {
197 {
271 #if 0
198 m_chart->setAxisX(m_valuesaxis, m_series);
272 QFETCH(int, count);
199 m_view->show();
273
200 QTest::qWaitForWindowShown(m_view);
274 SubQValuesAxis axis;
201 min_raw();
275
276 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
277 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
278 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
279
280 axis.setTicksCount(count);
281
282 QCOMPARE(spy0.count(), 0);
283 QCOMPARE(spy1.count(), 0);
284 QCOMPARE(spy2.count(), 0);
285 #endif
286 QSKIP("Test is not implemented.", SkipAll);
287 }
202 }
288
203
289 void tst_QValuesAxis::ticksCount_data()
204 void tst_QValuesAxis::min_animation_data()
290 {
205 {
291 QTest::addColumn<int>("ticksCount");
206 min_data();
292 QTest::newRow("0") << 0;
293 QTest::newRow("-1") << -1;
294 }
207 }
295
208
296 // public int ticksCount() const
209 void tst_QValuesAxis::min_animation()
297 void tst_QValuesAxis::ticksCount()
298 {
210 {
299 #if 0
211 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
300 QFETCH(int, ticksCount);
212 min();
301
302 SubQValuesAxis axis;
303
304 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
305 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
306 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
307
308 QCOMPARE(axis.ticksCount(), ticksCount);
309
310 QCOMPARE(spy0.count(), 0);
311 QCOMPARE(spy1.count(), 0);
312 QCOMPARE(spy2.count(), 0);
313 #endif
314 QSKIP("Test is not implemented.", SkipAll);
315 }
213 }
316
214
317 Q_DECLARE_METATYPE(QAbstractAxis::AxisType)
215 void tst_QValuesAxis::niceNumbersEnabled_data()
318 void tst_QValuesAxis::type_data()
319 {
216 {
320 #if 0
217 QTest::addColumn<bool>("niceNumbersEnabled");
321 QTest::addColumn<AxisType>("type");
218 QTest::addColumn<qreal>("min");
322 QTest::newRow("null") << AxisType();
219 QTest::addColumn<qreal>("max");
323 #endif
220 QTest::addColumn<int>("ticks");
221 QTest::addColumn<qreal>("expectedMin");
222 QTest::addColumn<qreal>("expectedMax");
223 QTest::addColumn<int>("expectedTicks");
224 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
225 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
226 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
227 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
228 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
229 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
324 }
230 }
325
231
326 // public AxisType type() const
232 void tst_QValuesAxis::niceNumbersEnabled()
327 void tst_QValuesAxis::type()
328 {
233 {
329 #if 0
234 QFETCH(bool, niceNumbersEnabled);
330 QFETCH(AxisType, type);
235 QFETCH(qreal, min);
331
236 QFETCH(qreal, max);
332 SubQValuesAxis axis;
237 QFETCH(int, ticks);
238 QFETCH(qreal, expectedMin);
239 QFETCH(qreal, expectedMax);
240 QFETCH(int, expectedTicks);
333
241
334 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
242 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
335 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
243 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
336 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
244 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
337
245
338 QCOMPARE(axis.type(), type);
246 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
247 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
339
248
340 QCOMPARE(spy0.count(), 0);
249 QCOMPARE(spy0.count(), 0);
341 QCOMPARE(spy1.count(), 0);
250 QCOMPARE(spy1.count(), 0);
342 QCOMPARE(spy2.count(), 0);
251 QCOMPARE(spy2.count(), 0);
343 #endif
252
344 QSKIP("Test is not implemented.", SkipAll);
253 m_valuesaxis->setTicksCount(ticks);
254 m_valuesaxis->setRange(min, max);
255 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
256 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
257 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
258
259 QCOMPARE(spy0.count(), 1);
260 QCOMPARE(spy1.count(), 1);
261 QCOMPARE(spy2.count(), 1);
262
345 }
263 }
346
264
347 void tst_QValuesAxis::maxChanged_data()
265 void tst_QValuesAxis::range_raw_data()
348 {
266 {
267 QTest::addColumn<qreal>("min");
349 QTest::addColumn<qreal>("max");
268 QTest::addColumn<qreal>("max");
350 QTest::newRow("null") << 0.0;
269 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
270 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
271 QTest::newRow("101.0") << 40.0 << 60.0;
351 }
272 }
352
273
353 // protected void maxChanged(qreal max)
274 void tst_QValuesAxis::range_raw()
354 void tst_QValuesAxis::maxChanged()
355 {
275 {
356 #if 0
276 QFETCH(qreal, min);
357 QFETCH(qreal, max);
277 QFETCH(qreal, max);
358
278
359 SubQValuesAxis axis;
279 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
360
280 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
361 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
281 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
362 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
363 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
364
282
365 axis.call_maxChanged(max);
283 m_valuesaxis->setRange(min, max);
284 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
285 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
366
286
367 QCOMPARE(spy0.count(), 0);
287 QCOMPARE(spy0.count(), 1);
368 QCOMPARE(spy1.count(), 0);
288 QCOMPARE(spy1.count(), 1);
369 QCOMPARE(spy2.count(), 0);
289 QCOMPARE(spy2.count(), 1);
370 #endif
371 QSKIP("Test is not implemented.", SkipAll);
372 }
290 }
373
291
374 void tst_QValuesAxis::minChanged_data()
292 void tst_QValuesAxis::range_data()
375 {
293 {
376 QTest::addColumn<qreal>("min");
294 range_raw_data();
377 QTest::newRow("null") << 0.0;
378 }
295 }
379
296
380 // protected void minChanged(qreal min)
297 void tst_QValuesAxis::range()
381 void tst_QValuesAxis::minChanged()
382 {
298 {
383 #if 0
299 m_chart->setAxisX(m_valuesaxis, m_series);
384 QFETCH(qreal, min);
300 m_view->show();
385
301 QTest::qWaitForWindowShown(m_view);
386 SubQValuesAxis axis;
302 range_raw();
387
303 }
388 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
389 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
390 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
391
392 axis.call_minChanged(min);
393
304
394 QCOMPARE(spy0.count(), 0);
305 void tst_QValuesAxis::range_animation_data()
395 QCOMPARE(spy1.count(), 0);
306 {
396 QCOMPARE(spy2.count(), 0);
307 range_data();
397 #endif
398 QSKIP("Test is not implemented.", SkipAll);
399 }
308 }
400
309
401 void tst_QValuesAxis::rangeChanged_data()
310 void tst_QValuesAxis::range_animation()
402 {
311 {
403 QTest::addColumn<qreal>("min");
312 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
404 QTest::addColumn<qreal>("max");
313 range();
405 QTest::newRow("null") << 0.0 << 0.0;
406 }
314 }
407
315
408 // protected void rangeChanged(qreal min, qreal max)
316 void tst_QValuesAxis::ticksCount_data()
409 void tst_QValuesAxis::rangeChanged()
410 {
317 {
411 #if 0
318 QTest::addColumn<int>("ticksCount");
412 QFETCH(qreal, min);
319 QTest::addColumn<int>("expectedCount");
413 QFETCH(qreal, max);
320 QTest::newRow("0") << 2;
321 QTest::newRow("1") << 2;
322 QTest::newRow("2") << 2;
323 QTest::newRow("3") << 3;
324 QTest::newRow("-1") << 2;
325 }
414
326
415 SubQValuesAxis axis;
327 void tst_QValuesAxis::ticksCount()
328 {
329 QFETCH(int, ticksCount);
416
330
417 QSignalSpy spy0(&axis, SIGNAL(maxChanged(qreal)));
331 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
418 QSignalSpy spy1(&axis, SIGNAL(minChanged(qreal)));
332 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
419 QSignalSpy spy2(&axis, SIGNAL(rangeChanged(qreal, qreal)));
333 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
420
334
421 axis.call_rangeChanged(min, max);
335 m_valuesaxis->setTicksCount(ticksCount);
336 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
422
337
423 QCOMPARE(spy0.count(), 0);
338 QCOMPARE(spy0.count(), 0);
424 QCOMPARE(spy1.count(), 0);
339 QCOMPARE(spy1.count(), 0);
425 QCOMPARE(spy2.count(), 0);
340 QCOMPARE(spy2.count(), 0);
426 #endif
341
427 QSKIP("Test is not implemented.", SkipAll);
342 m_chart->setAxisX(m_valuesaxis, m_series);
343 m_view->show();
344 QTest::qWaitForWindowShown(m_view);
345
346 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
428 }
347 }
429
348
430 QTEST_MAIN(tst_QValuesAxis)
349 QTEST_MAIN(tst_QValuesAxis)
431 #include "tst_qvaluesaxis.moc"
350 #include "tst_qvaluesaxis.moc"
432
351
General Comments 0
You need to be logged in to leave comments. Login now