HListView: add checkedIndice property

This commit is contained in:
miruka 2020-06-26 03:47:55 -04:00
parent a22c8ba3ad
commit d40852a11c

View File

@ -63,6 +63,7 @@ ListView {
property int currentItemHeight: currentItem ? currentItem.height : 0 property int currentItemHeight: currentItem ? currentItem.height : 0
property var checked: ({}) property var checked: ({})
property var checkedIndice: new Set()
property int lastCheckedDelegateIndex: 0 property int lastCheckedDelegateIndex: 0
property int selectedCount: Object.keys(checked).length property int selectedCount: Object.keys(checked).length
@ -71,10 +72,12 @@ ListView {
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
checked[model.id] = model checked[model.id] = model
checkedIndice.add(i)
} }
lastCheckedDelegateIndex = indices.slice(-1)[0] lastCheckedDelegateIndex = indices.slice(-1)[0]
checkedChanged() checkedChanged()
checkedIndiceChanged()
} }
function checkFromLastToHere(here) { function checkFromLastToHere(here) {
@ -86,29 +89,34 @@ ListView {
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
delete checked[model.id] delete checked[model.id]
checkedIndice.delete(i)
} }
checkedChanged() checkedChanged()
checkedIndiceChanged()
} }
function toggleCheck(...indices) { function toggleCheck(...indices) {
const checkedIndices = [] const checkedNow = []
for (const i of indices) { for (const i of indices) {
const model = listView.model.get(i) const model = listView.model.get(i)
if (model.id in checked) { if (model.id in checked) {
delete checked[model.id] delete checked[model.id]
checkedIndice.delete(i)
} else { } else {
checked[model.id] = model checked[model.id] = model
checkedIndices.push(i) checkedNow.push(i)
checkedIndice.add(i)
} }
} }
if (checkedIndices.length > 0) if (checkedNow.length > 0)
lastCheckedDelegateIndex = checkedIndices.slice(-1)[0] lastCheckedDelegateIndex = checkedNow.slice(-1)[0]
checkedChanged() checkedChanged()
checkedIndiceChanged()
} }
function getSortedChecked() { function getSortedChecked() {