915
975
verify(panel, "Selection panel not found, wrong attached property target?");
978
function test_dragmode_availability_data() {
980
{tag: "Attached to Column", item: testColumn, lookupOn: testItem, xfail: true},
981
{tag: "Attached to ListView", item: listView, lookupOn: findChild(listView, "listItem0"), xfail: false},
984
function test_dragmode_availability(data) {
986
ignoreWarning(warningFormat(80, 5, "QML Column: dragging mode requires ListView"));
988
data.item.ViewItems.dragMode = true;
990
var panel = findChild(data.lookupOn, "drag_panel0");
992
expectFailContinue(data.tag, "There should be no drag handler shown!")
994
verify(panel, "No drag handler found!");
997
function test_drag_data() {
999
{tag: "Live 0->1 OK", live: true, from: 0, to: 1, count: 1, accept: true, indices:[1,0,2,3,4]},
1000
{tag: "Live 0->2 OK", live: true, from: 0, to: 2, count: 2, accept: true, indices:[1,2,0,3,4]},
1001
{tag: "Live 0->3 OK", live: true, from: 0, to: 3, count: 3, accept: true, indices:[1,2,3,0,4]},
1002
{tag: "Live 3->0 OK", live: true, from: 3, to: 0, count: 3, accept: true, indices:[3,0,1,2,4]},
1003
// do not accept moves
1004
{tag: "Live 0->1 NOK", live: true, from: 0, to: 1, count: 0, accept: false, indices:[0,1,2,3,4]},
1005
{tag: "Live 0->2 NOK", live: true, from: 0, to: 2, count: 0, accept: false, indices:[0,1,2,3,4]},
1006
{tag: "Live 0->3 NOK", live: true, from: 0, to: 3, count: 0, accept: false, indices:[0,1,2,3,4]},
1007
{tag: "Live 3->0 NOK", live: true, from: 3, to: 0, count: 0, accept: false, indices:[0,1,2,3,4]},
1010
{tag: "Drop 0->1 OK", live: false, from: 0, to: 1, count: 1, accept: true, indices:[1,0,2,3,4]},
1011
{tag: "Drop 0->2 OK", live: false, from: 0, to: 2, count: 1, accept: true, indices:[1,2,0,3,4]},
1012
{tag: "Drop 0->3 OK", live: false, from: 0, to: 3, count: 1, accept: true, indices:[1,2,3,0,4]},
1013
{tag: "Drop 3->0 OK", live: false, from: 3, to: 0, count: 1, accept: true, indices:[3,0,1,2,4]},
1014
// do not accept moves
1015
{tag: "Drop 0->1 NOK", live: false, from: 0, to: 1, count: 0, accept: false, indices:[0,1,2,3,4]},
1016
{tag: "Drop 0->2 NOK", live: false, from: 0, to: 2, count: 0, accept: false, indices:[0,1,2,3,4]},
1017
{tag: "Drop 0->3 NOK", live: false, from: 0, to: 3, count: 0, accept: false, indices:[0,1,2,3,4]},
1018
{tag: "Drop 3->0 NOK", live: false, from: 3, to: 0, count: 0, accept: false, indices:[0,1,2,3,4]},
1022
function test_drag(data) {
1024
function liveUpdate(event) {
1025
if (event.status == ListItemDrag.Started) {
1030
listView.model.move(event.from, event.to, 1);
1032
event.accept = data.accept;
1034
function singleDrop(event) {
1035
if (event.status == ListItemDrag.Dropped) {
1038
listView.model.move(event.from, event.to, 1);
1040
event.accept = data.accept;
1041
} else if (event.status == ListItemDrag.Moving) {
1042
event.accept = false;
1046
objectModel.reset();
1047
waitForRendering(listView);
1048
listView.positionViewAtBeginning();
1049
var func = data.live ? liveUpdate : singleDrop;
1050
listView.ViewItems.dragUpdated.connect(func);
1053
toggleDragMode(listView, true);
1054
drag(listView, data.from, data.to);
1055
compare(moveCount, data.count, "Move did not happen or more than one item was moved");
1056
// compare array indices
1057
for (var i in data.indices) {
1058
compare(listView.model.get(i).data, data.indices[i], "data at index " + i + " is not the expected one");
1062
listView.ViewItems.dragUpdated.disconnect(func);
1063
toggleDragMode(listView, false);
1067
// the first 2 items cannot be dragged anywhere, nothing can be dropped in this area
1068
// the 3-> items can be interchanged in between, cannot be dragged outside
1069
function test_drag_restricted_data() {
1071
{tag: "[0,1] locked, drag 0->1 NOK", from: 0, to: 1, count: 0, indices: [0,1,2,3,4]},
1072
{tag: "[0,1] locked, drag 1->2 NOK", from: 1, to: 2, count: 0, indices: [0,1,2,3,4]},
1073
{tag: "[0,1] locked, drag 2->1 NOK", from: 2, to: 1, count: 0, indices: [0,1,2,3,4]},
1074
{tag: "[0,1] locked, drag 2->0 NOK", from: 2, to: 0, count: 0, indices: [0,1,2,3,4]},
1076
{tag: "[0,1] locked, drag 2->3 OK", from: 2, to: 3, count: 1, indices: [0,1,3,2,4]},
1079
function test_drag_restricted(data) {
1081
function updateHandler(event) {
1082
if (event.status == ListItemDrag.Started) {
1083
if (event.from < 2) {
1084
event.accept = false;
1086
event.minimumIndex = 2;
1088
} else if (event.status == ListItemDrag.Moving) {
1089
listView.model.move(event.from, event.to, 1);
1094
objectModel.reset();
1095
waitForRendering(listView);
1096
listView.positionViewAtBeginning();
1097
listView.ViewItems.dragUpdated.connect(updateHandler);
1100
toggleDragMode(listView, true);
1101
drag(listView, data.from, data.to);
1102
compare(moveCount, data.count, "Move did not happen or more than one item was moved");
1103
// compare array indices
1104
for (var i in data.indices) {
1105
compare(listView.model.get(i).data, data.indices[i], "data at index " + i + " is not the expected one");
1109
listView.ViewItems.dragUpdated.disconnect(updateHandler);
1110
toggleDragMode(listView, false);
1113
function test_drag_keeps_selected_indexes_data() {
1115
{tag: "[0,1,2] selected, move 0->3, live", selected: [0,1,2], from: 0, to: 3, expected: [0,1,3], live: true},
1116
{tag: "[1,2] selected, move 3->2, live", selected: [1,2], from: 3, to: 2, expected: [1,3], live: true},
1117
{tag: "[1,2] selected, move 0->3, live", selected: [1,2], from: 0, to: 3, expected: [0,1], live: true},
1118
{tag: "[1,2] selected, move 3->0, live", selected: [1,2], from: 3, to: 0, expected: [2,3], live: true},
1120
{tag: "[0,1,2] selected, move 0->3, non-live", selected: [0,1,2], from: 0, to: 3, expected: [0,1,3], live: false},
1121
{tag: "[1,2] selected, move 3->2, non-live", selected: [1,2], from: 3, to: 2, expected: [1,3], live: false},
1122
{tag: "[1,2] selected, move 0->3, non-live", selected: [1,2], from: 0, to: 3, expected: [0,1], live: false},
1123
{tag: "[1,2] selected, move 3->0, non-live", selected: [1,2], from: 3, to: 0, expected: [2,3], live: false},
1126
function test_drag_keeps_selected_indexes(data) {
1127
function updateHandler(event) {
1128
if (event.status == ListItemDrag.Started) {
1131
if (data.live || event.status == ListItemDrag.Dropped) {
1132
listView.model.move(event.from, event.to, 1);
1134
event.accept = false;
1137
objectModel.reset();
1138
waitForRendering(listView);
1139
listView.ViewItems.selectedIndices = data.selected;
1140
listView.ViewItems.dragUpdated.connect(updateHandler);
1141
toggleDragMode(listView, true);
1142
drag(listView, data.from, data.to);
1143
listView.ViewItems.dragUpdated.disconnect(updateHandler);
1144
toggleDragMode(listView, false);
1146
// NOTE: the selected indexes order is arbitrar and cannot be predicted by the test
1147
// therefore we check the selected indexes presence in the expected list.
1148
compare(listView.ViewItems.selectedIndices.length, data.expected.length, "The selected indexes and expected list size differs");
1149
for (var i = 0; i < listView.ViewItems.selectedIndices.length; i++) {
1150
var index = data.expected.indexOf(listView.ViewItems.selectedIndices[i]);
1151
verify(index >= 0, "Index " + listView.ViewItems.selectedIndices[i] + " is not expected to be selected!");
1155
// must run this immediately after the defaults are checked otherwise drag handler connected check will fail
1156
function test_1_warn_missing_dragUpdated_signal_handler() {
1157
ignoreWarning(warningFormat(116, 9, "QML ListView: ListView has no ViewItems.dragUpdated() signal handler implemented. No dragging will be possible."));
1158
toggleDragMode(listView, true);
1159
drag(listView, 0, 1);
1160
toggleDragMode(listView, true);
1165
delegate: ListItem {
1166
objectName: "listItem" + index
1167
Label { text: modelData }
1175
objectName: "listItem" + index
1176
Label { text: modelData }
1180
function test_warn_model_data() {
1181
var list = [1,2,3,4,5,6,7,8,9,10];
1183
{tag: "number", model: 20, warning: "not all features of dragging will be possible on this model."},
1184
{tag: "list", model: list, warning: "not all features of dragging will be possible on this model."},
1185
{tag: "objectModel", model: objectModel, warning: ""},
1186
{tag: "DelegateModel with number", model: delegateModel, modelModel: 20, warning: "not all features of dragging will be possible on this DelegateModel.model."},
1187
{tag: "DelegateModel with list", model: delegateModel, modelModel: [1,2,3,4,5,6,7,8,9,10], warning: "not all features of dragging will be possible on this DelegateModel.model."},
1188
{tag: "DelegateModel with objectModel", model: delegateModel, modelModel: objectModel, warning: ""},
1189
{tag: "ObjectModel", model: objectModel2, warning: ""},
1192
function test_warn_model(data) {
1193
function dummyFunc() {}
1194
if (data.warning !== "") {
1195
ignoreWarning(warningFormat(116, 9, "QML ListView: " + data.warning));
1197
listView.model = data.model;
1198
if (typeof data.modelModel !== "undefined") {
1199
listView.model.model = data.modelModel;
1201
waitForRendering(listView, 500);
1202
listView.ViewItems.dragUpdated.connect(dummyFunc);
1203
toggleDragMode(listView, true);
1204
toggleDragMode(listView, false);
1205
listView.ViewItems.dragUpdated.disconnect(dummyFunc);