on xenial help sign in
Remove unused ResponsiveGridView
commitac396ae2b07d52a6ab0570db89a134196837801d authorRodney Dawes <dobey@ubports.com> dateThu 6 Aug 2020, 12:28 (6 years ago) parent0a9395e
3 files changed−256
qml/Components/ResponsiveGridView.qml−98 tests/qmltests/CMakeLists.txt−1 tests/qmltests/Components/tst_ResponsiveGridView.qml−157
qml/Components/ResponsiveGridView.qmldeleted−98
@@ -1,98 +0,0 @@
1−/*
2− * Copyright (C) 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 Ubuntu.Components 1.3
19−import "."
20−
21−/*
22− Essentially a GridView
23− */
24−Item {
25− property int minimumHorizontalSpacing: units.gu(0.5)
26− readonly property int columns: gridView.columns
27− property alias verticalSpacing: gridView.verticalSpacing
28− readonly property alias margins: gridView.margin
29− property int delegateWidth
30− property int delegateHeight
31− property alias model: gridView.model
32− property alias delegate: gridView.delegate
33− readonly property int cellWidth: gridView.cellWidth
34− readonly property int cellHeight: gridView.cellHeight
35− readonly property int totalContentHeight: {
36− if (gridView.model) {
37− return contentHeightForRows(Math.ceil(gridView.model.count / columns), cellHeight)
38− } else {
39− return 0;
40− }
41− }
42− property alias interactive: gridView.interactive
43− readonly property alias flicking: gridView.flicking
44− readonly property alias moving: gridView.moving
45− readonly property alias pressDelay: gridView.pressDelay
46− readonly property alias originY: gridView.originY
47− property alias displayMarginBeginning: gridView.displayMarginBeginning
48− property alias displayMarginEnd: gridView.displayMarginEnd
49− property alias highlightIndex: gridView.highlightIndex
50− property alias cacheBuffer: gridView.cacheBuffer
51− readonly property alias currentItem: gridView.currentItem
52−
53− function contentHeightForRows(rows, height) {
54− return rows * height
55− }
56−
57− GridView {
58− id: gridView
59− objectName: "responsiveGridViewGrid"
60− anchors {
61− fill: parent
62− leftMargin: margin/2
63− rightMargin: margin/2
64− }
65− clip: parent.height != totalContentHeight
66−
67− function pixelToGU(value) {
68− return Math.floor(value / units.gu(1));
69− }
70−
71− function spacingForColumns(columns) {
72− // spacing between columns as an integer number of GU, the remainder goes in the margins
73− var spacingGU = pixelToGU(allocatableHorizontalSpace / columns);
74− return units.gu(spacingGU);
75− }
76−
77− function columnsForSpacing(spacing) {
78− // minimum margin is half of the spacing
79− return Math.max(1, Math.floor(parent.width / (delegateWidth + spacing)));
80− }
81−
82− property real allocatableHorizontalSpace: parent.width - columns * delegateWidth
83− property int columns: columnsForSpacing(minimumHorizontalSpacing)
84− property real horizontalSpacing: spacingForColumns(columns)
85− property real verticalSpacing: horizontalSpacing
86− property int margin: allocatableHorizontalSpace - columns * horizontalSpacing
87− property int highlightIndex: -1
88−
89− cellWidth: delegateWidth + horizontalSpacing
90− cellHeight: delegateHeight + verticalSpacing
91−
92− onHighlightIndexChanged: {
93− if (highlightIndex != -1) {
94− currentIndex = highlightIndex
95− }
96− }
97− }
98−}
tests/qmltests/CMakeLists.txt−1
@@ -20,7 +20,6 @@ add_unity8_qmltest(Components MediaServices)
2020add_unity8_qmltest(Components ModeSwitchWarningDialog)
2121add_unity8_qmltest(Components PhysicalKeysMapper)
2222add_unity8_qmltest(Components Rating)
23−add_unity8_qmltest(Components ResponsiveGridView)
2423add_unity8_qmltest(Components SharingPicker)
2524add_unity8_qmltest(Components Showable)
2625add_unity8_qmltest(Components VirtualTouchPad)
tests/qmltests/Components/tst_ResponsiveGridView.qmldeleted−157
@@ -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−}