1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the Qt Charts module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:GPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU
19** General Public License version 3 or (at your option) any later version
20** approved by the KDE Free Qt Foundation. The licenses are as published by
21** the Free Software Foundation and appearing in the file LICENSE.GPL3
22** included in the packaging of this file. Please review the following
23** information to ensure the GNU General Public License requirements will
24** be met: https://www.gnu.org/licenses/gpl-3.0.html.
25**
26** $QT_END_LICENSE$
27**
28****************************************************************************/
29
30#include "../qabstractaxis/tst_qabstractaxis.h"
31#include <QtCharts/QLogValueAxis>
32#include <QtCharts/QLineSeries>
33#include <QtCore/QDebug>
34
35class tst_QLogValueAxis: public tst_QAbstractAxis
36{
37Q_OBJECT
38
39public slots:
40 void init();
41 void cleanup() override;
42
43private slots:
44 void qlogvalueaxis_data();
45 void qlogvalueaxis();
46 void max_raw_data();
47 void max_raw();
48 void max_data();
49 void max();
50 void max_animation_data();
51 void max_animation();
52 void min_raw_data();
53 void min_raw();
54 void min_data();
55 void min();
56 void min_animation_data();
57 void min_animation();
58 void range_raw_data();
59 void range_raw();
60 void range_data();
61 void range();
62 void range_before_show_data();
63 void range_before_show();
64 void range_animation_data();
65 void range_animation();
66 void noautoscale_data();
67 void noautoscale();
68 void autoscale_data();
69 void autoscale();
70 void zoom();
71 void reverse();
72
73private:
74 QLogValueAxis* m_logvaluesaxis;
75 QLineSeries* m_series;
76};
77
78void tst_QLogValueAxis::init()
79{
80 m_logvaluesaxis = new QLogValueAxis();
81 m_series = new QLineSeries();
82 *m_series << QPointF(1, 1) << QPointF(100, 100);
83 tst_QAbstractAxis::initAxes(axis: m_logvaluesaxis, series: m_series);
84 m_chart->addSeries(series: m_series);
85 m_chart->createDefaultAxes();
86}
87
88void tst_QLogValueAxis::cleanup()
89{
90 delete m_series;
91 delete m_logvaluesaxis;
92 m_series = 0;
93 m_logvaluesaxis = 0;
94 tst_QAbstractAxis::cleanup();
95}
96
97void tst_QLogValueAxis::qlogvalueaxis_data()
98{
99}
100
101void tst_QLogValueAxis::qlogvalueaxis()
102{
103 qabstractaxis();
104
105 QCOMPARE(m_logvaluesaxis->max(), (qreal)1);
106 QCOMPARE(m_logvaluesaxis->min(), (qreal)1);
107 QCOMPARE(m_logvaluesaxis->type(), QAbstractAxis::AxisTypeLogValue);
108
109 const auto oldXAxes = m_chart->axes(orientation: Qt::Horizontal);
110 for (auto oldXAxis : oldXAxes)
111 m_chart->removeAxis(axis: oldXAxis);
112
113 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
114 m_series->attachAxis(axis: m_logvaluesaxis);
115 m_view->show();
116 QVERIFY(QTest::qWaitForWindowExposed(m_view));
117
118 QCOMPARE(m_logvaluesaxis->max(), (qreal)100);
119 QCOMPARE(m_logvaluesaxis->min(), (qreal)1);
120
121 QCOMPARE(m_logvaluesaxis->isReverse(), false);
122}
123
124void tst_QLogValueAxis::max_raw_data()
125{
126 QTest::addColumn<qreal>(name: "max");
127 QTest::addColumn<qreal>(name: "expected");
128 QTest::addColumn<bool>(name: "minChanged");
129 QTest::addColumn<bool>(name: "maxChanged");
130 QTest::newRow(dataTag: "-1.0") << (qreal)-1.0 << (qreal)1.0 << false << false;
131 QTest::newRow(dataTag: "0.0") << (qreal)0.0 << (qreal)1.0 << false << false;
132 QTest::newRow(dataTag: "0.5") << (qreal)0.5 << (qreal)0.5 << true << true;
133 QTest::newRow(dataTag: "101.0") << (qreal)101.0 << (qreal)101.0 << false << true;
134}
135
136void tst_QLogValueAxis::max_raw()
137{
138 QFETCH(qreal, max);
139 QFETCH(qreal, expected);
140 QFETCH(bool, minChanged);
141 QFETCH(bool, maxChanged);
142
143 // setting the axis in max() changes the max to value other than 1
144 // set it back to 1
145 m_logvaluesaxis->setMax((qreal)1);
146
147 QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal)));
148 QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal)));
149 QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal)));
150
151 m_logvaluesaxis->setMax(max);
152 QCOMPARE(m_logvaluesaxis->max(), expected);
153
154 QCOMPARE(spy0.count(), (int)maxChanged);
155 QCOMPARE(spy1.count(), (int)minChanged);
156 QCOMPARE(spy2.count(), (int)maxChanged);
157
158}
159
160void tst_QLogValueAxis::max_data()
161{
162 max_raw_data();
163}
164
165void tst_QLogValueAxis::max()
166{
167 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
168 m_series->attachAxis(axis: m_logvaluesaxis);
169 m_view->show();
170 QVERIFY(QTest::qWaitForWindowExposed(m_view));
171 max_raw();
172}
173
174void tst_QLogValueAxis::max_animation_data()
175{
176 max_data();
177}
178
179void tst_QLogValueAxis::max_animation()
180{
181 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
182 max();
183}
184
185void tst_QLogValueAxis::min_raw_data()
186{
187 QTest::addColumn<qreal>(name: "min");
188 QTest::addColumn<qreal>(name: "expected");
189 QTest::addColumn<bool>(name: "minChanged");
190 QTest::addColumn<bool>(name: "maxChanged");
191 QTest::newRow(dataTag: "-1.0") << (qreal)-1.0 << (qreal)1.0 << false << false;
192 QTest::newRow(dataTag: "0.0") << (qreal)0.0 << (qreal)1.0 << false << false;
193 QTest::newRow(dataTag: "0.5") << (qreal)0.5 << (qreal)0.5 << true << false;
194 QTest::newRow(dataTag: "101.0") << (qreal)101.0 << (qreal)101.0 << true << true;
195}
196
197void tst_QLogValueAxis::min_raw()
198{
199 QFETCH(qreal, min);
200 QFETCH(qreal, expected);
201 QFETCH(bool, minChanged);
202 QFETCH(bool, maxChanged);
203
204 QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal)));
205 QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal)));
206 QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal)));
207
208 m_logvaluesaxis->setMin(min);
209 QCOMPARE(m_logvaluesaxis->min(), expected);
210
211 QCOMPARE(spy0.count(), (int)maxChanged);
212 QCOMPARE(spy1.count(), (int)minChanged);
213 QCOMPARE(spy2.count(), (int)minChanged);
214}
215
216void tst_QLogValueAxis::min_data()
217{
218 min_raw_data();
219}
220
221void tst_QLogValueAxis::min()
222{
223 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
224 m_series->attachAxis(axis: m_logvaluesaxis);
225 m_view->show();
226 QVERIFY(QTest::qWaitForWindowExposed(m_view));
227 min_raw();
228}
229
230void tst_QLogValueAxis::min_animation_data()
231{
232 min_data();
233}
234
235void tst_QLogValueAxis::min_animation()
236{
237 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
238 min();
239}
240
241void tst_QLogValueAxis::range_raw_data()
242{
243 QTest::addColumn<qreal>(name: "min");
244 QTest::addColumn<qreal>(name: "max");
245 QTest::addColumn<qreal>(name: "expectedMin");
246 QTest::addColumn<qreal>(name: "expectedMax");
247 QTest::addColumn<bool>(name: "minChanged");
248 QTest::addColumn<bool>(name: "maxChanged");
249 QTest::newRow(dataTag: "-1.0 - 101.0") << (qreal)-1.0 << (qreal)101.0 << (qreal)1.0 << (qreal)1.0 << false << false;
250 QTest::newRow(dataTag: "1.0 - 101.0") << (qreal)1.0 << (qreal)101.0 << (qreal)1.0 << (qreal)101.0 << false << true;
251 QTest::newRow(dataTag: "0.1 - 1.0") << (qreal)0.1 << (qreal)1.0 << (qreal)0.1 << (qreal)1.0 << true << false;
252 QTest::newRow(dataTag: "25.0 - 75.0") << (qreal)25.0 << (qreal)75.0 << (qreal)25.0 << (qreal)75.0 << true << true;
253 QTest::newRow(dataTag: "10.0 - 5.0") << (qreal)10.0 << (qreal)5.0 << (qreal)1.0 << (qreal)1.0 << false << false;
254 QTest::newRow(dataTag: "2.0 - 7.0") << (qreal)2.0 << (qreal)7.0 << (qreal)2.0 << (qreal)7.0 << true << true;
255}
256
257void tst_QLogValueAxis::range_raw()
258{
259 QFETCH(qreal, min);
260 QFETCH(qreal, max);
261 QFETCH(qreal, expectedMin);
262 QFETCH(qreal, expectedMax);
263 QFETCH(bool, minChanged);
264 QFETCH(bool, maxChanged);
265
266 m_logvaluesaxis->setRange(min: (qreal)1, max: (qreal)1);
267
268 QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal)));
269 QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal)));
270 QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal)));
271
272 m_logvaluesaxis->setRange(min, max);
273 QCOMPARE(m_logvaluesaxis->min(), expectedMin);
274 QCOMPARE(m_logvaluesaxis->max(), expectedMax);
275
276 QCOMPARE(spy0.count(), (int)maxChanged);
277 QCOMPARE(spy1.count(), (int)minChanged);
278 QCOMPARE(spy2.count(), (int)(minChanged || maxChanged));
279}
280
281void tst_QLogValueAxis::range_data()
282{
283 range_raw_data();
284}
285
286void tst_QLogValueAxis::range()
287{
288 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
289 m_series->attachAxis(axis: m_logvaluesaxis);
290 m_view->show();
291 QVERIFY(QTest::qWaitForWindowExposed(m_view));
292 range_raw();
293}
294
295void tst_QLogValueAxis::range_before_show_data()
296{
297 range_raw_data();
298}
299
300void tst_QLogValueAxis::range_before_show()
301{
302 range_raw();
303
304 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
305 m_series->attachAxis(axis: m_logvaluesaxis);
306 m_view->show();
307 QVERIFY(QTest::qWaitForWindowExposed(m_view));
308}
309
310void tst_QLogValueAxis::range_animation_data()
311{
312 range_data();
313}
314
315void tst_QLogValueAxis::range_animation()
316{
317 m_chart->setAnimationOptions(QChart::GridAxisAnimations);
318 range();
319}
320
321void tst_QLogValueAxis::noautoscale_data()
322{
323 QTest::addColumn<qreal>(name: "min");
324 QTest::addColumn<qreal>(name: "max");
325 QTest::newRow(dataTag: "0.1 - 101.0") << (qreal)0.1 << (qreal)101.0;
326 QTest::newRow(dataTag: "25.0 - 75.0") << (qreal)25.0 << (qreal)75.0;
327}
328
329void tst_QLogValueAxis::noautoscale()
330{
331 QFETCH(qreal, min);
332 QFETCH(qreal, max);
333
334 QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal)));
335 QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal)));
336 QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal)));
337
338 m_logvaluesaxis->setRange(min, max);
339 QCOMPARE(m_logvaluesaxis->min(), min);
340 QCOMPARE(m_logvaluesaxis->max(), max);
341
342 QCOMPARE(spy0.count(), 1);
343 QCOMPARE(spy1.count(), 1);
344 QCOMPARE(spy2.count(), 1);
345 m_view->show();
346 QVERIFY(QTest::qWaitForWindowExposed(m_view));
347 QCOMPARE(m_logvaluesaxis->min(), min);
348 QCOMPARE(m_logvaluesaxis->max(), max);
349}
350
351void tst_QLogValueAxis::autoscale_data()
352{
353
354}
355
356void tst_QLogValueAxis::autoscale()
357{
358 QSignalSpy spy0(m_logvaluesaxis, SIGNAL(maxChanged(qreal)));
359 QSignalSpy spy1(m_logvaluesaxis, SIGNAL(minChanged(qreal)));
360 QSignalSpy spy2(m_logvaluesaxis, SIGNAL(rangeChanged(qreal,qreal)));
361
362 QCOMPARE(m_logvaluesaxis->min(), (qreal)1);
363 QCOMPARE(m_logvaluesaxis->max(), (qreal)1);
364 const auto oldXAxes = m_chart->axes(orientation: Qt::Horizontal);
365 for (auto oldXAxis : oldXAxes)
366 m_chart->removeAxis(axis: oldXAxis);
367 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
368 m_series->attachAxis(axis: m_logvaluesaxis);
369
370 QCOMPARE(spy0.count(), 1);
371 QCOMPARE(spy1.count(), 0);
372 QCOMPARE(spy2.count(), 1);
373
374 m_view->show();
375 QVERIFY(QTest::qWaitForWindowExposed(m_view));
376 QCOMPARE(m_logvaluesaxis->min(), (qreal)1);
377 QCOMPARE(m_logvaluesaxis->max(), (qreal)100);
378}
379
380void tst_QLogValueAxis::zoom()
381{
382 const auto oldXAxes = m_chart->axes(orientation: Qt::Horizontal);
383 for (auto oldXAxis : oldXAxes)
384 m_chart->removeAxis(axis: oldXAxis);
385 m_chart->addAxis(axis: m_logvaluesaxis, alignment: Qt::AlignBottom);
386 m_series->attachAxis(axis: m_logvaluesaxis);
387 m_view->show();
388 QVERIFY(QTest::qWaitForWindowExposed(m_view));
389 m_logvaluesaxis->setBase(2);
390 m_logvaluesaxis->setRange(min: 0.5, max: 2);
391
392 QCOMPARE(m_logvaluesaxis->min(), (qreal)0.5);
393 QCOMPARE(m_logvaluesaxis->max(), (qreal)2.0);
394
395 m_chart->zoomOut();
396
397 QCOMPARE(m_logvaluesaxis->min(), (qreal)0.25);
398 QCOMPARE(m_logvaluesaxis->max(), (qreal)4.0);
399
400 m_chart->zoomIn();
401
402 QCOMPARE(m_logvaluesaxis->min(), (qreal)0.5);
403 QCOMPARE(m_logvaluesaxis->max(), (qreal)2.0);
404
405 m_logvaluesaxis->setRange(min: 0.5, max: 1024);
406 m_chart->zoom(factor: 11.0);
407
408 QCOMPARE(m_logvaluesaxis->min(), (qreal)16.0);
409 QCOMPARE(m_logvaluesaxis->max(), (qreal)32.0);
410
411 m_logvaluesaxis->setRange(min: 16, max: 64);
412 m_chart->zoom(factor: 1/3.0);
413
414 QCOMPARE(m_logvaluesaxis->min(), (qreal)4);
415 QCOMPARE(m_logvaluesaxis->max(), (qreal)256.0);
416
417}
418
419void tst_QLogValueAxis::reverse()
420{
421 QSignalSpy spy(m_logvaluesaxis, SIGNAL(reverseChanged(bool)));
422 QCOMPARE(m_logvaluesaxis->isReverse(), false);
423
424 m_logvaluesaxis->setReverse();
425 QCOMPARE(m_logvaluesaxis->isReverse(), true);
426 QCOMPARE(spy.count(), 1);
427
428 m_view->show();
429 QVERIFY(QTest::qWaitForWindowExposed(m_view));
430 QCOMPARE(m_logvaluesaxis->isReverse(), true);
431}
432
433QTEST_MAIN(tst_QLogValueAxis)
434#include "tst_qlogvalueaxis.moc"
435
436

source code of qtcharts/tests/auto/qlogvalueaxis/tst_qlogvalueaxis.cpp