Debian Codegraph @

tests/auto/qml-qtquicktest/data/tst_valueaxis.qml

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.0
5 import QtTest 1.0
6 import QtCharts 2.1
7
8 Rectangle {
9 width: 400
10 height: 300
11
12 TestCase {
13 id: tc1
14 name: "tst_qml-qtquicktest ValueAxis"
15 when: windowShown
16
17 // test functions are run in alphabetical order, the name has 'a' so that it
18 // will be the first function to execute.
19 function test_a_properties() {
20 // Default properties
21 verify(axisX.min < 0, "AxisX min");
22 verify(axisX.max > 0, "AxisX max");
23 verify(axisY.min < 0, "AxisY min");
24 verify(axisY.max > 0, "AxisY max");
25 verify(axisX.tickCount == 5, "AxisX tick count");
26 verify(axisY.tickCount == 5, "AxisY tick count");
27 verify(axisX.labelFormat == "", "label format");
28 verify(axisX.reverse == false, "AxisX reverse");
29 verify(axisY.reverse == false, "AxisY reverse");
30
31 // Modify properties
32 axisX.tickCount = 3;
33 verify(axisX.tickCount == 3, "set tick count");
34 axisX.reverse = true;
35 verify(axisX.reverse == true, "AxisX reverse");
36 axisX.reverse = false;
37 verify(axisX.reverse == false, "AxisX reverse");
38 }
39
40 function test_functions() {
41 // Set the axis ranges to not "nice" ones...
42 var min = 0.032456456;
43 var max = 10.67845634;
44 axisX.min = min;
45 axisX.max = max;
46 axisY.min = min;
47 axisY.max = max;
48
49 // ...And then apply nice numbers and verify the range was changed
50 axisX.applyNiceNumbers();
51 axisY.applyNiceNumbers();
52 verify(axisX.min != min);
53 verify(axisX.max != max);
54 verify(axisY.min != min);
55 verify(axisY.max != max);
56 }
57
58 function test_signals() {
59 minChangedSpy.clear();
60 maxChangedSpy.clear();
61 reverseChangedSpy.clear();
62
63 axisX.min = 2;
64 compare(minChangedSpy.count, 1, "onMinChanged");
65 compare(maxChangedSpy.count, 0, "onMaxChanged");
66
67 axisX.max = 8;
68 compare(minChangedSpy.count, 1, "onMinChanged");
69 compare(maxChangedSpy.count, 1, "onMaxChanged");
70
71 axisX.reverse = true;
72 compare(reverseChangedSpy.count, 1, "onReverseChanged");
73
74 // restore original values
75 axisX.min = 0;
76 axisX.max = 10;
77 axisX.reverse = false;
78 compare(minChangedSpy.count, 2, "onMinChanged");
79 compare(maxChangedSpy.count, 2, "onMaxChanged");
80 compare(reverseChangedSpy.count, 2, "onReverseChanged");
81 }
82 }
83
84 ChartView {
85 id: chartView
86 anchors.fill: parent
87
88 LineSeries {
89 id: lineSeries1
90 axisX: ValueAxis {
91 id: axisX
92 }
93 axisY: ValueAxis {
94 id: axisY
95 }
96 XYPoint { x: -1; y: -1 }
97 XYPoint { x: 0; y: 0 }
98 XYPoint { x: 5; y: 5 }
99 }
100
101 SignalSpy {
102 id: minChangedSpy
103 target: axisX
104 signalName: "minChanged"
105 }
106 SignalSpy {
107 id: maxChangedSpy
108 target: axisX
109 signalName: "maxChanged"
110 }
111 SignalSpy {
112 id: reverseChangedSpy
113 target: axisX
114 signalName: "reverseChanged"
115 }
116 }
117 }