@@ -1,157 +0,0 @@
1−/*
2− * Copyright 2013 Canonical Ltd.
3− *
4− * This program is free software; you can redistribute it and/or modify
5− * it under the terms of the GNU General Public License as published by
6− * the Free Software Foundation; version 3.
7− *
8− * This program is distributed in the hope that it will be useful,
9− * but WITHOUT ANY WARRANTY; without even the implied warranty of
10− * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11− * GNU General Public License for more details.
12− *
13− * You should have received a copy of the GNU General Public License
14− * along with this program. If not, see <http://www.gnu.org/licenses/>.
15− */
16−
17−import QtQuick 2.4
18−import QtTest 1.0
19−import ".."
20−import "../../../qml/Components"
21−import Ubuntu.Components.ListItems 1.3 as ListItem
22−import Ubuntu.Components 1.3
23−import Unity.Test 0.1 as UT
24−
25−Item {
26− width: gridRect.width + controls.width
27− height: units.gu(80)
28−
29− Column {
30− id: controls
31− width: units.gu(40)
32− height: parent.height
33− anchors.top: parent.top
34− anchors.right: parent.right
35− ListItem.ValueSelector {
36− id: minHSpacingSelector
37− text: "minHorizontalSpacing"
38− values: [0,units.gu(2),units.gu(8),units.gu(25)]
39− selectedIndex: 0
40− }
41− }
42−
43− ListModel {
44− id: fakeModel
45− ListElement { name: "A" }
46− ListElement { name: "B" }
47− ListElement { name: "C" }
48− ListElement { name: "D" }
49− ListElement { name: "E" }
50− ListElement { name: "F" }
51− ListElement { name: "G" }
52− ListElement { name: "H" }
53− ListElement { name: "I" }
54− ListElement { name: "J" }
55− ListElement { name: "K" }
56− ListElement { name: "L" }
57− ListElement { name: "M" }
58− ListElement { name: "N" }
59− ListElement { name: "O" }
60− ListElement { name: "P" }
61− ListElement { name: "Q" }
62− ListElement { name: "R" }
63− ListElement { name: "S" }
64− ListElement { name: "T" }
65− ListElement { name: "U" }
66− }
67−
68− Rectangle {
69− id: gridRect
70− width: units.gu(80)
71− height: parent.height
72− color: "grey"
73− anchors.top: parent.top
74− anchors.left: parent.left
75−
76− ResponsiveGridView {
77− id: grid
78− anchors.fill: parent
79− model: fakeModel
80− minimumHorizontalSpacing:
81− minHSpacingSelector.values[minHSpacingSelector.selectedIndex]
82− verticalSpacing: units.gu(2)
83− delegateWidth: units.gu(6)
84− delegateHeight: units.gu(6)
85−
86− delegate: Rectangle {
87− // So that it can be identified by test code
88− property bool isGridDelegate: true
89− color: "grey"
90− border.color: "red"
91− border.width: 1
92−
93− // IMPORTANT: always use grid's cellWidth and cellHeight here to get
94− // ResponsiveGridView's intended result
95− width: grid.cellWidth
96− height: grid.cellHeight
97−
98− Rectangle {
99− color: "green"
100− anchors.centerIn: parent
101− width: units.gu(6)
102− height: units.gu(6)
103− Text {
104− anchors.centerIn: parent
105− text: name
106− }
107− }
108−
109− Text { x:0; y:0; text:"(" + parent.x + ", " + parent.y + ")"}
110− }
111− }
112− }
113−
114− UT.UnityTestCase {
115− name: "ResponsiveGridView"
116− when: windowShown
117−
118− function test_minimumHorizontalSpacing_data() {
119− var data = new Array()
120−
121− data.push({selectedIndex: 0, minHSpacing:0, columnCount: 13})
122− data.push({selectedIndex: 1, minHSpacing:units.gu(2), columnCount: 10})
123− data.push({selectedIndex: 2, minHSpacing:units.gu(8), columnCount: 5})
124− data.push({selectedIndex: 3, minHSpacing:units.gu(25), columnCount: 2})
125−
126− return data
127− }
128−
129− /* Change ResponsiveGridView's minimumHorizontalSpacing property and check
130− that the resulting number of columns matches expectations */
131− function test_minimumHorizontalSpacing(data) {
132− // sanity checks
133− compare(minHSpacingSelector.values[data.selectedIndex], data.minHSpacing)
134−
135− minHSpacingSelector.selectedIndex = data.selectedIndex
136− tryCompareFunction(countGridDelegatesOnFirstRow, data.columnCount);
137− compare(grid.columns, data.columnCount)
138− }
139−
140−
141− function countGridDelegatesOnFirstRow() {
142− return __countGridDelegatesOnFirstRow(grid.visibleChildren, 0)
143− }
144−
145− function __countGridDelegatesOnFirstRow(objList, total) {
146− for (var i = 0; i < objList.length; ++i) {
147− var child = objList[i];
148− if (child.isGridDelegate !== undefined && child.y === 0) {
149− ++total;
150− } else {
151− total = __countGridDelegatesOnFirstRow(child.visibleChildren, total)
152− }
153− }
154− return total
155− }
156− }
157−}