Debian Codegraph @

tests/auto/qml-qtquicktest/data/tst_barcategoryaxis_1_4.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 1.4
7
8 Rectangle {
9 width: 400
10 height: 300
11
12 TestCase {
13 id: tc1
14 name: "tst_qml-qtquicktest BarCategoryAxis 1.4"
15 when: windowShown
16
17 function test_minMax() {
18 compare(barSeries1.axisX.min, "Jan", "AxisX min");
19 compare(barSeries1.axisX.max, "Jun", "AxisX max");
20 compare(barSeries1.axisY.min, 0, "AxisY min");
21 compare(barSeries1.axisY.max, 10, "AxisY max");
22 }
23
24 function test_categories() {
25 compare(barSeries1.axisX.count, 6, "AxisX count");
26 categoriesCountChangedSpy.clear();
27 categoriesChangedSpy.clear();
28
29 // Replace categories
30 barSeries1.axisX.categories = ["Tam", "Hel", "Maa", "Huh"];
31 compare(barSeries1.axisX.count, 4, "AxisX count");
32 compare(categoriesCountChangedSpy.count, 1, "onCountChanged");
33 compare(categoriesChangedSpy.count, 1, "onCategoriesChanged");
34
35 // Reset the original categories
36 barSeries1.axisX.categories = ["Jan", "Feb", "Mar", "Apr", "May", "Jun"]
37 compare(barSeries1.axisX.count, 6, "AxisX count");
38 compare(categoriesCountChangedSpy.count, 2, "onCountChanged");
39 compare(categoriesChangedSpy.count, 2, "onCategoriesChanged");
40 }
41
42 function test_minMaxChanged() {
43 axisY.min = -1;
44 compare(minChangedSpy.count, 1, "onMinChanged");
45 compare(maxChangedSpy.count, 0, "onMaxChanged");
46 axisY.max = 12;
47 compare(minChangedSpy.count, 1, "onMinChanged");
48 compare(maxChangedSpy.count, 1, "onMaxChanged");
49 }
50
51 function test_seriesAxisClear() {
52 verify(barSeries1.axisX.min !== "", "barSeries1.axisX.min");
53 verify(barSeries1.axisX.max !== "", "barSeries1.axisX.max");
54 verify(barSeries1.axisX.count !== 0, "barSeries1.axisX.count"); // category count
55 barSeries1.axisX.clear();
56 verify(barSeries1.axisX.min === "", "barSeries1.axisX.min");
57 verify(barSeries1.axisX.max === "", "barSeries1.axisX.max");
58 verify(barSeries1.axisX.count === 0);
59 }
60
61 }
62
63 ChartView {
64 id: chartView
65 anchors.fill: parent
66
67 BarSeries {
68 id: barSeries1
69 axisX: BarCategoryAxis {
70 id: axisX
71 categories: ["Jan", "Feb", "Mar", "Apr", "May", "Jun" ]
72 }
73 axisY: ValueAxis {
74 id: axisY
75 min: 0
76 max: 10
77 }
78 }
79
80 SignalSpy {
81 id: categoriesCountChangedSpy
82 target: axisX
83 signalName: "countChanged"
84 }
85 SignalSpy {
86 id: categoriesChangedSpy
87 target: axisX
88 signalName: "categoriesChanged"
89 }
90 SignalSpy {
91 id: minChangedSpy
92 target: axisY
93 signalName: "minChanged"
94 }
95 SignalSpy {
96 id: maxChangedSpy
97 target: axisY
98 signalName: "maxChanged"
99 }
100 }
101 }