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