##// END OF EJS Templates
Add autoscale testcases to tst_qvaluesaxis
Michal Klocek -
r1705:253f5c2017da
parent child
Show More
@@ -1,368 +1,367
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 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 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 Q_Q(QValuesAxis);
313 314 if(qFuzzyCompare(m_max,m_min)) {
314 315 if(m_orientation==Qt::Vertical){
315 m_min = domain->minY();
316 m_max = domain->maxY();
316 q->setRange(domain->minY(),domain->maxY());
317 317 }else{
318 m_min = domain->minX();
319 m_max = domain->maxX();
318 q->setRange(domain->minX(), domain->maxX());
320 319 }
321 320 } else {
322 321 if(m_orientation==Qt::Vertical){
323 322 domain->setRangeY(m_min, m_max);
324 323 }else{
325 324 domain->setRangeX(m_min, m_max);
326 325 }
327 326 }
328 327 }
329 328
330 329 //algorithm defined by Paul S.Heckbert GraphicalGems I
331 330
332 331 void QValuesAxisPrivate::looseNiceNumbers(qreal &min, qreal &max, int &ticksCount) const
333 332 {
334 333 qreal range = niceNumber(max-min,true); //range with ceiling
335 334 qreal step = niceNumber(range/(ticksCount-1),false);
336 335 min = floor(min/step);
337 336 max = ceil(max/step);
338 337 ticksCount = int(max-min) +1;
339 338 min*=step;
340 339 max*=step;
341 340 }
342 341
343 342 //nice numbers can be expressed as form of 1*10^n, 2* 10^n or 5*10^n
344 343
345 344 qreal QValuesAxisPrivate::niceNumber(qreal x,bool ceiling) const
346 345 {
347 346 qreal z = pow(10,floor(log10(x))); //find corresponding number of the form of 10^n than is smaller than x
348 347 qreal q = x/z;//q<10 && q>=1;
349 348
350 349 if(ceiling) {
351 350 if(q <= 1.0) q=1;
352 351 else if(q <= 2.0) q=2;
353 352 else if(q <= 5.0) q=5;
354 353 else q=10;
355 354 }
356 355 else {
357 356 if(q < 1.5) q=1;
358 357 else if(q < 3.0) q=2;
359 358 else if(q < 7.0) q=5;
360 359 else q=10;
361 360 }
362 361 return q*z;
363 362 }
364 363
365 364 #include "moc_qvaluesaxis.cpp"
366 365 #include "moc_qvaluesaxis_p.cpp"
367 366
368 367 QTCOMMERCIALCHART_END_NAMESPACE
@@ -1,351 +1,412
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 "../qabstractaxis/tst_qabstractaxis.h"
22 22 #include "qvaluesaxis.h"
23 23 #include <qlineseries.h>
24 24
25 25 class tst_QValuesAxis: public tst_QAbstractAxis
26 26 {
27 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
39 38 void max_raw_data();
40 39 void max_raw();
41 40 void max_data();
42 41 void max();
43 42 void max_animation_data();
44 43 void max_animation();
45 44 void min_raw_data();
46 45 void min_raw();
47 46 void min_data();
48 47 void min();
49 48 void min_animation_data();
50 49 void min_animation();
51 50 void niceNumbersEnabled_data();
52 51 void niceNumbersEnabled();
53 52 void range_raw_data();
54 53 void range_raw();
55 54 void range_data();
56 55 void range();
57 56 void range_animation_data();
58 57 void range_animation();
59 58 void ticksCount_data();
60 59 void ticksCount();
60 void noautoscale_data();
61 void noautoscale();
62 void autoscale_data();
63 void autoscale();
61 64
62 65 private:
63 66 QValuesAxis* m_valuesaxis;
64 67 QLineSeries* m_series;
65 68 };
66 69
67 70 void tst_QValuesAxis::initTestCase()
68 71 {
69 72 }
70 73
71 74 void tst_QValuesAxis::cleanupTestCase()
72 75 {
73 76 }
74 77
75 78 void tst_QValuesAxis::init()
76 79 {
77 80 m_valuesaxis = new QValuesAxis();
78 81 m_series = new QLineSeries();
79 82 *m_series << QPointF(-100, -100) << QPointF(0, 0) << QPointF(100, 100);
80 83 tst_QAbstractAxis::init(m_valuesaxis,m_series);
81 84 m_chart->addSeries(m_series);
82 85 m_chart->createDefaultAxes();
83 86 }
84 87
85 88 void tst_QValuesAxis::cleanup()
86 89 {
87 90 delete m_series;
88 91 delete m_valuesaxis;
89 92 m_series = 0;
90 93 m_valuesaxis = 0;
91 94 tst_QAbstractAxis::cleanup();
92 95 }
93 96
94 97 void tst_QValuesAxis::qvaluesaxis_data()
95 98 {
96 99 }
97 100
98 101 void tst_QValuesAxis::qvaluesaxis()
99 102 {
100 103 qabstractaxis();
101 104
102 105 QVERIFY(qFuzzyIsNull(m_valuesaxis->max()));
103 106 QVERIFY(qFuzzyIsNull(m_valuesaxis->min()));
104 107 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
105 108 QCOMPARE(m_valuesaxis->ticksCount(), 5);
106 109 QCOMPARE(m_valuesaxis->type(), QAbstractAxis::AxisTypeValues);
107 110
108 111 m_chart->setAxisX(m_valuesaxis, m_series);
109 112 m_view->show();
110 113 QTest::qWaitForWindowShown(m_view);
111 114
112 115 QVERIFY(!qFuzzyIsNull(m_valuesaxis->max()));
113 116 QVERIFY(!qFuzzyIsNull(m_valuesaxis->min()));
114 117 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), false);
115 118 QCOMPARE(m_valuesaxis->ticksCount(), 5);
116 119 }
117 120
118 121 void tst_QValuesAxis::max_raw_data()
119 122 {
120 123 QTest::addColumn<qreal>("max");
121 124 QTest::newRow("1.0") << 1.0;
122 125 QTest::newRow("50.0") << 50.0;
123 126 QTest::newRow("101.0") << 101.0;
124 127 }
125 128
126 129 void tst_QValuesAxis::max_raw()
127 130 {
128 131 QFETCH(qreal, max);
129 132
130 133 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
131 134 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
132 135 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
133 136
134 137 m_valuesaxis->setMax(max);
135 138 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Not equal");
136 139
137 140 QCOMPARE(spy0.count(), 1);
138 141 QCOMPARE(spy1.count(), 0);
139 142 QCOMPARE(spy2.count(), 1);
140 143
141 144 }
142 145
143 146 void tst_QValuesAxis::max_data()
144 147 {
145 148 max_raw_data();
146 149 }
147 150
148 151 void tst_QValuesAxis::max()
149 152 {
150 153 m_chart->setAxisX(m_valuesaxis, m_series);
151 154 m_view->show();
152 155 QTest::qWaitForWindowShown(m_view);
153 156 max_raw();
154 157 }
155 158
156 159 void tst_QValuesAxis::max_animation_data()
157 160 {
158 161 max_data();
159 162 }
160 163
161 164 void tst_QValuesAxis::max_animation()
162 165 {
163 166 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
164 167 max();
165 168 }
166 169
167 170 void tst_QValuesAxis::min_raw_data()
168 171 {
169 172 QTest::addColumn<qreal>("min");
170 173 QTest::newRow("-1.0") << -1.0;
171 174 QTest::newRow("-50.0") << -50.0;
172 175 QTest::newRow("-101.0") << -101.0;
173 176 }
174 177
175 178 void tst_QValuesAxis::min_raw()
176 179 {
177 180 QFETCH(qreal, min);
178 181
179 182 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
180 183 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
181 184 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
182 185
183 186 m_valuesaxis->setMin(min);
184 187 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Not equal");
185 188
186 189 QCOMPARE(spy0.count(), 0);
187 190 QCOMPARE(spy1.count(), 1);
188 191 QCOMPARE(spy2.count(), 1);
189 192 }
190 193
191 194 void tst_QValuesAxis::min_data()
192 195 {
193 196 min_raw_data();
194 197 }
195 198
196 199 void tst_QValuesAxis::min()
197 200 {
198 201 m_chart->setAxisX(m_valuesaxis, m_series);
199 202 m_view->show();
200 203 QTest::qWaitForWindowShown(m_view);
201 204 min_raw();
202 205 }
203 206
204 207 void tst_QValuesAxis::min_animation_data()
205 208 {
206 209 min_data();
207 210 }
208 211
209 212 void tst_QValuesAxis::min_animation()
210 213 {
211 214 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
212 215 min();
213 216 }
214 217
215 218 void tst_QValuesAxis::niceNumbersEnabled_data()
216 219 {
217 220 QTest::addColumn<bool>("niceNumbersEnabled");
218 221 QTest::addColumn<qreal>("min");
219 222 QTest::addColumn<qreal>("max");
220 223 QTest::addColumn<int>("ticks");
221 224 QTest::addColumn<qreal>("expectedMin");
222 225 QTest::addColumn<qreal>("expectedMax");
223 226 QTest::addColumn<int>("expectedTicks");
224 227 QTest::newRow("true 0.1 , 99.0 , 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
225 228 QTest::newRow("true 1 , 10.0 , 5") << true << 1.0 << 10.0 << 5 << 0.0 << 10.0 << 6;
226 229 QTest::newRow("true 0.1 , 6.6 , 5") << true << 0.1 << 6.6 << 5 << 0.0 << 8.0 << 5;
227 230 QTest::newRow("false 0.1 , 6.6 , 5") << false << 0.1 << 6.6 << 5 << 0.1 << 6.6 << 5;
228 231 QTest::newRow("true 0.1, 99, 5") << true << 0.1 << 99.0 << 5 << 0.0 << 100.0 << 6;
229 232 QTest::newRow("true 5, 93.5 , 5") << true << 5.0 << 93.5 << 5 << 0.0 << 100.0 << 6;
230 233 }
231 234
232 235 void tst_QValuesAxis::niceNumbersEnabled()
233 236 {
234 237 QFETCH(bool, niceNumbersEnabled);
235 238 QFETCH(qreal, min);
236 239 QFETCH(qreal, max);
237 240 QFETCH(int, ticks);
238 241 QFETCH(qreal, expectedMin);
239 242 QFETCH(qreal, expectedMax);
240 243 QFETCH(int, expectedTicks);
241 244
242 245 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
243 246 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
244 247 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
245 248
246 249 m_valuesaxis->setNiceNumbersEnabled(niceNumbersEnabled);
247 250 QCOMPARE(m_valuesaxis->niceNumbersEnabled(), niceNumbersEnabled);
248 251
249 252 QCOMPARE(spy0.count(), 0);
250 253 QCOMPARE(spy1.count(), 0);
251 254 QCOMPARE(spy2.count(), 0);
252 255
253 256 m_valuesaxis->setTicksCount(ticks);
254 257 m_valuesaxis->setRange(min, max);
255 258 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - expectedMin), "Min not equal");
256 259 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - expectedMax), "Max not equal");
257 260 QCOMPARE(m_valuesaxis->ticksCount(), expectedTicks);
258 261
259 262 QCOMPARE(spy0.count(), 1);
260 263 QCOMPARE(spy1.count(), 1);
261 264 QCOMPARE(spy2.count(), 1);
262 265
263 266 }
264 267
265 268 void tst_QValuesAxis::range_raw_data()
266 269 {
267 270 QTest::addColumn<qreal>("min");
268 271 QTest::addColumn<qreal>("max");
269 272 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
270 273 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
271 274 QTest::newRow("101.0") << 40.0 << 60.0;
272 275 }
273 276
274 277 void tst_QValuesAxis::range_raw()
275 278 {
276 279 QFETCH(qreal, min);
277 280 QFETCH(qreal, max);
278 281
279 282 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
280 283 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
281 284 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
282 285
283 286 m_valuesaxis->setRange(min, max);
284 287 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
285 288 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
286 289
287 290 QCOMPARE(spy0.count(), 1);
288 291 QCOMPARE(spy1.count(), 1);
289 292 QCOMPARE(spy2.count(), 1);
290 293 }
291 294
292 295 void tst_QValuesAxis::range_data()
293 296 {
294 297 range_raw_data();
295 298 }
296 299
297 300 void tst_QValuesAxis::range()
298 301 {
299 302 m_chart->setAxisX(m_valuesaxis, m_series);
300 303 m_view->show();
301 304 QTest::qWaitForWindowShown(m_view);
302 305 range_raw();
303 306 }
304 307
305 308 void tst_QValuesAxis::range_animation_data()
306 309 {
307 310 range_data();
308 311 }
309 312
310 313 void tst_QValuesAxis::range_animation()
311 314 {
312 315 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
313 316 range();
314 317 }
315 318
316 319 void tst_QValuesAxis::ticksCount_data()
317 320 {
318 321 QTest::addColumn<int>("ticksCount");
319 322 QTest::addColumn<int>("expectedCount");
320 323 QTest::newRow("0") << 2;
321 324 QTest::newRow("1") << 2;
322 325 QTest::newRow("2") << 2;
323 326 QTest::newRow("3") << 3;
324 327 QTest::newRow("-1") << 2;
325 328 }
326 329
327 330 void tst_QValuesAxis::ticksCount()
328 331 {
329 332 QFETCH(int, ticksCount);
330 333
331 334 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
332 335 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
333 336 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
334 337
335 338 m_valuesaxis->setTicksCount(ticksCount);
336 339 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
337 340
338 341 QCOMPARE(spy0.count(), 0);
339 342 QCOMPARE(spy1.count(), 0);
340 343 QCOMPARE(spy2.count(), 0);
341 344
342 345 m_chart->setAxisX(m_valuesaxis, m_series);
343 346 m_view->show();
344 347 QTest::qWaitForWindowShown(m_view);
345 348
346 349 QCOMPARE(m_valuesaxis->ticksCount(), ticksCount);
347 350 }
348 351
352 void tst_QValuesAxis::noautoscale_data()
353 {
354 QTest::addColumn<qreal>("min");
355 QTest::addColumn<qreal>("max");
356 QTest::newRow("1.0 - 101.0") << -1.0 << 101.0;
357 QTest::newRow("25.0 - 75.0") << 25.0 << 75.0;
358 QTest::newRow("101.0") << 40.0 << 60.0;
359 }
360
361 void tst_QValuesAxis::noautoscale()
362 {
363 QFETCH(qreal, min);
364 QFETCH(qreal, max);
365
366 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
367 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
368 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
369
370 m_valuesaxis->setRange(min, max);
371 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
372 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
373
374 QCOMPARE(spy0.count(), 1);
375 QCOMPARE(spy1.count(), 1);
376 QCOMPARE(spy2.count(), 1);
377
378 m_chart->setAxisX(m_valuesaxis, m_series);
379 m_view->show();
380 QTest::qWaitForWindowShown(m_view);
381 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() - min), "Min not equal");
382 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - max), "Max not equal");
383 }
384
385 void tst_QValuesAxis::autoscale_data()
386 {
387
388 }
389
390 void tst_QValuesAxis::autoscale()
391 {
392 QSignalSpy spy0(m_valuesaxis, SIGNAL(maxChanged(qreal)));
393 QSignalSpy spy1(m_valuesaxis, SIGNAL(minChanged(qreal)));
394 QSignalSpy spy2(m_valuesaxis, SIGNAL(rangeChanged(qreal, qreal)));
395
396 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min()), "Min not equal");
397 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max()), "Max not equal");
398 m_chart->setAxisX(m_valuesaxis, m_series);
399
400 QCOMPARE(spy0.count(), 1);
401 QCOMPARE(spy1.count(), 1);
402 QCOMPARE(spy2.count(), 1);
403
404 m_view->show();
405 QTest::qWaitForWindowShown(m_view);
406 QVERIFY2(qFuzzyIsNull(m_valuesaxis->min() + 100), "Min not equal");
407 QVERIFY2(qFuzzyIsNull(m_valuesaxis->max() - 100), "Max not equal");
408 }
409
349 410 QTEST_MAIN(tst_QValuesAxis)
350 411 #include "tst_qvaluesaxis.moc"
351 412
General Comments 0
You need to be logged in to leave comments. Login now