| 1 |
import QtQml 2.15 |
| 2 |
import QtQml.Models 2.15 |
| 3 |
|
| 4 |
QtObject { |
| 5 |
function swapCorpses() { |
| 6 |
const lhsData = getModelData(lhsButtonListModel); |
| 7 |
const rhsData = getModelData(rhsButtonListModel); |
| 8 |
|
| 9 |
lhsButtonListModel.clear(); |
| 10 |
rhsButtonListModel.clear(); |
| 11 |
|
| 12 |
addToModel(lhsButtonListModel, rhsData); |
| 13 |
addToModel(rhsButtonListModel, lhsData); |
| 14 |
} |
| 15 |
|
| 16 |
property ListModel l1: ListModel { |
| 17 |
id: lhsButtonListModel |
| 18 |
} |
| 19 |
|
| 20 |
property ListModel l2: ListModel { |
| 21 |
id: rhsButtonListModel |
| 22 |
} |
| 23 |
|
| 24 |
Component.onCompleted: { |
| 25 |
lhsButtonListModel.append({ "ident": 1, "buttonText": "B 1"}); |
| 26 |
lhsButtonListModel.append({ "ident": 2, "buttonText": "B 2"}); |
| 27 |
lhsButtonListModel.append({ "ident": 3, "buttonText": "B 3"}); |
| 28 |
|
| 29 |
rhsButtonListModel.append({ "ident": 4, "buttonText": "B 4"}); |
| 30 |
rhsButtonListModel.append({ "ident": 5, "buttonText": "B 5"}); |
| 31 |
rhsButtonListModel.append({ "ident": 6, "buttonText": "B 6"}); |
| 32 |
} |
| 33 |
|
| 34 |
function getModelData(model) { |
| 35 |
var dataList = [] |
| 36 |
for (var i = 0; i < model.count; ++i) |
| 37 |
dataList.push(model.get(i)); |
| 38 |
|
| 39 |
return dataList; |
| 40 |
} |
| 41 |
|
| 42 |
function addToModel(model, buttonData) { |
| 43 |
for (var i = 0; i < buttonData.length; ++i) |
| 44 |
model.append(buttonData[i]); |
| 45 |
} |
| 46 |
} |