Debian Codegraph @

src/app/qml/components/MultiSelectListView.qml

raw
1 /*
2 * Copyright (C) 2013, 2014, 2015, 2017
3 * Andrew Hayzen <[email protected]>
4 * Daniel Holm <[email protected]>
5 * Victor Thompson <[email protected]>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 3.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 import QtQuick 2.12
21 import Lomiri.Components 1.3
22
23 WeatherListView {
24 // Can't access ViewItems externally
25 // so we need to expose if in multiselect mode for the header states
26 state: ViewItems.selectMode ? "multiselectable" : "default"
27
28 signal clearSelection()
29 signal closeSelection()
30 signal reorder(int from, int to)
31 signal selectAll()
32
33 onClearSelection: ViewItems.selectedIndices = []
34 onCloseSelection: {
35 clearSelection()
36 ViewItems.selectMode = false
37 ViewItems.dragMode = false
38 }
39 onSelectAll: {
40 var tmp = []
41
42 for (var i=0; i < model.count; i++) {
43 tmp.push(i)
44 }
45
46 ViewItems.selectedIndices = tmp
47 }
48
49 // Can't access ViewItems externally
50 // so for the header actions we need to expose the selectedIndices
51 function getSelectedIndices() {
52 var indicies = ViewItems.selectedIndices.slice();
53
54 indicies.sort(); // ensure indicies are in-order
55
56 return indicies;
57 }
58
59 ViewItems.selectMode: false
60 ViewItems.dragMode: false
61 ViewItems.onDragUpdated: {
62 // Only update the model when the listitem is dropped, not 'live'
63 if (event.status == ListItemDrag.Moving) {
64 event.accept = false
65 } else if (event.status == ListItemDrag.Dropped) {
66 model.move(event.from, event.to, 1);
67
68 reorder(event.from, event.to)
69 }
70 }
71 }