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