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 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229
|
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick
import QtTest
import QtQuick.Controls
import Qt.labs.qmlmodels
TestCase {
id: testCase
width: 200
height: 200
visible: true
when: windowShown
name: "SelectionRectangle"
property real cellWidth: 50
property real cellHeight: 20
property Item topLeftHandle: null
property Item bottomRightHandle: null
property bool handleWasDragged: false
Component {
id: defaultSelectionRectangle
SelectionRectangle {}
}
Component {
id: topLeftHandleComp
Rectangle {
id: handle
width: 28
height: width
radius: width / 2
property bool dragging: SelectionRectangle.dragging
property Item control: SelectionRectangle.control
border.width: 1
border.color: "red"
visible: SelectionRectangle.control.active
SelectionRectangle.onDraggingChanged: {
if (SelectionRectangle.dragging)
testCase.handleWasDragged = true
}
Component.onCompleted: testCase.topLeftHandle = handle
Component.onDestruction: testCase.topLeftHandle = null
}
}
Component {
id: bottomRightHandleComp
Rectangle {
id: handle
width: 28
height: width
radius: width / 2
property bool dragging: SelectionRectangle.dragging
property Item control: SelectionRectangle.control
border.width: 1
border.color: "green"
visible: SelectionRectangle.control.active
SelectionRectangle.onDraggingChanged: {
if (SelectionRectangle.dragging)
testCase.handleWasDragged = true
}
Component.onCompleted: testCase.bottomRightHandle = handle
Component.onDestruction: testCase.bottomRightHandle = null
}
}
Component {
id: delegateWithTapHandlerComp
Rectangle {
implicitWidth: 100
implicitHeight: 50
color: selected ? "lightblue" : "transparent"
border.width: 1
required property bool selected
TapHandler {
// This tap handler will block the tap handler in
// QQuickTableView from being called.
}
}
}
TableModel {
id: tableModel
TableModelColumn { display: "c1" }
TableModelColumn { display: "c2" }
TableModelColumn { display: "c3" }
TableModelColumn { display: "c4" }
TableModelColumn { display: "c5" }
TableModelColumn { display: "c6" }
TableModelColumn { display: "c7" }
TableModelColumn { display: "c8" }
rows: [
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" },
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" }
]
}
Component {
id: tableviewComp
TableView {
id: tableView
clip: true
anchors.fill: parent
model: tableModel
delegate: Rectangle {
required property bool selected
implicitWidth: cellWidth
implicitHeight: cellHeight
color: selected ? "lightblue" : "gray"
Text { text: row + "," + column }
}
selectionModel: ItemSelectionModel {
model: tableView.model
}
property alias selectionRectangle: selectionRectangle
SelectionRectangle {
id: selectionRectangle
target: tableView
}
}
}
Component {
id: noDelegateTableViewComp
TableView {
id: tableView
anchors.fill: parent
interactive: false
selectionModel: itemSelectionModel
property alias selectionRectangle: selectionRectangle
ItemSelectionModel {
id: itemSelectionModel
model: tableModel
}
SelectionRectangle {
id: selectionRectangle
target: tableView
}
}
}
Component {
id: headerviewComp
HorizontalHeaderView {
id: headerView
clip: true
anchors.fill: parent
model: TableModel {
TableModelColumn { display: "c1" }
TableModelColumn { display: "c2" }
TableModelColumn { display: "c3" }
TableModelColumn { display: "c4" }
TableModelColumn { display: "c5" }
TableModelColumn { display: "c6" }
TableModelColumn { display: "c7" }
TableModelColumn { display: "c8" }
rows: [
{ "c1": "v1", "c2":"v2", "c3":"v3", "c4": "v4", "c5": "v5", "c6":"v6", "c7":"v7", "c8": "v8" }
]
}
delegate: Rectangle {
required property bool selected
implicitWidth: cellWidth
implicitHeight: cellHeight
color: selected ? "lightblue" : "gray"
Text { text: row + "," + column }
}
selectionModel: ItemSelectionModel { }
property alias selectionRectangle: selectionRectangle
SelectionRectangle {
id: selectionRectangle
target: headerView
}
}
}
Component {
id: signalSpy
SignalSpy { }
}
function init() {
failOnWarning(/.?/)
}
function test_defaults() {
let control = createTemporaryObject(defaultSelectionRectangle, testCase)
verify(control)
}
function test_set_target() {
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
compare(selectionRectangle.target, tableView)
selectionRectangle.target = null
compare(selectionRectangle.target, null)
selectionRectangle.target = tableView
compare(selectionRectangle.target, tableView)
}
function test_set_selectionMode() {
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
// Default selection mode should be Auto
compare(selectionRectangle.selectionMode, SelectionRectangle.Auto)
selectionRectangle.selectionMode = SelectionRectangle.Drag
compare(selectionRectangle.selectionMode, SelectionRectangle.Drag)
selectionRectangle.selectionMode = SelectionRectangle.PressAndHold
compare(selectionRectangle.selectionMode, SelectionRectangle.PressAndHold)
selectionRectangle.selectionMode = SelectionRectangle.Auto
compare(selectionRectangle.selectionMode, SelectionRectangle.Auto)
}
function test_set_handles() {
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.topLeftHandle = null
compare(selectionRectangle.topLeftHandle, null)
selectionRectangle.bottomRightHandle = null
compare(selectionRectangle.bottomRightHandle, null)
selectionRectangle.topLeftHandle = topLeftHandleComp
compare(selectionRectangle.topLeftHandle, topLeftHandleComp)
selectionRectangle.bottomRightHandle = bottomRightHandleComp
compare(selectionRectangle.bottomRightHandle, bottomRightHandleComp)
}
function test_drag_data() {
return [
{ tag: "resize enabled (tableview with delegate)", resizeEnabled: true, viewComp: tableviewComp, hasDelegate: true },
{ tag: "resize disabled (tableview with delegate)", resizeEnabled: false, viewComp: tableviewComp, hasDelegate: true },
{ tag: "resize enabled (tableview no delegate)", resizeEnabled: true, viewComp: noDelegateTableViewComp, hasDelegate: false },
{ tag: "resize disabled (tableview no delegate)", resizeEnabled: false, viewComp: noDelegateTableViewComp, hasDelegate: false },
{ tag: "resize enabled (headerview)", resizeEnabled: true, viewComp: headerviewComp, hasDelegate: true },
{ tag: "resize disabled (headerview)", resizeEnabled: false, viewComp: headerviewComp, hasDelegate: true },
]
}
function test_drag(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
// Check that we can start a selection from the middle of a cell, even
// if a drag or tap on the edge of the cell would resize it.
tableView.resizableRows = data.resizeEnabled
tableView.resizableColumns = data.resizeEnabled
selectionRectangle.selectionMode = SelectionRectangle.Drag
let activeSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "activeChanged"})
let draggingSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "draggingChanged"})
verify(activeSpy.valid)
verify(draggingSpy.valid)
verify(!tableView.selectionModel.hasSelection)
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1)))
compare(activeSpy.count, 1)
compare(draggingSpy.count, 2)
} else {
compare(activeSpy.count, 0)
compare(draggingSpy.count, 0)
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Remove selection
mouseClick(tableView, tableView.width - 1, tableView.height - 1, Qt.LeftButton)
verify(!tableView.selectionModel.hasSelection)
if (data.hasDelegate) {
compare(draggingSpy.count, 2)
compare(activeSpy.count, 2)
} else {
compare(draggingSpy.count, 0)
compare(activeSpy.count, 0)
}
// Ensure that a press and hold doesn't start a selection
mousePress(tableView, 1, 1, Qt.LeftButton)
mouseRelease(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000)
verify(!tableView.selectionModel.hasSelection)
}
function test_tableView_singleSelection_data() {
return [
{ tag: "tableView no delegate", viewComp: noDelegateTableViewComp, hasDelegate: false },
{ tag: "tableView with delegate", viewComp: tableviewComp, hasDelegate: true },
{ tag: "headerView", viewComp: headerviewComp, hasDelegate: true },
]
}
function test_tableView_singleSelection(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
tableView.selectionMode = TableView.SingleSelection
// Try to select two cells by dragging. Only one cell should be selected.
verify(!tableView.selectionModel.hasSelection)
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 0)))
}
// A control click should clear the current selection and select a new cell
mouseClick(tableView, (cellWidth * 2) - 1, 1, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1)))
}
// A shift click is a no-op, and doesn't change the current selection
mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.selectionModel.model.index(0, 1)))
}
}
function test_tableView_contiguousSelection_data() {
return [
{ tag: "Dont startFromCurrent (with delegate)", viewComp: tableviewComp, hasDelegate: true, startFromCurrentIndex: false },
{ tag: "startFromCurrent (with delegate)", viewComp: tableviewComp, hasDelegate: true, startFromCurrentIndex: true },
{ tag: "Dont startFromCurrent (no delegate)", viewComp: noDelegateTableViewComp, hasDelegate: false, startFromCurrentIndex: false },
{ tag: "startFromCurrent (no delegate)", viewComp: noDelegateTableViewComp, hasDelegate: false, startFromCurrentIndex: true },
]
}
function test_tableView_contiguousSelection(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
tableView.selectionMode = TableView.ContiguousSelection
if (data.startFromCurrentIndex) {
// Click on a cell to set current index, but set no selection.
// A later shift-click should then start a new selection from the
// current cell.
mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier)
verify(!tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.currentIndex, tableView.index(0, 0))
} else {
// Start a new selection by dragging on two cells
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
// A shift click should extend the selection
mouseClick(tableView, (cellWidth * 4) - 3, 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A shift click closer to the first selected cell should shrink it again
mouseClick(tableView, (cellWidth * 3) - 2, 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 3)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A control click should clear the selection, and select a new cell
mouseClick(tableView, 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A control drag should clear the selection, and select new cells
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function init_delegate_data_tag() {
return [
{ tag: "with delegate", viewComp: tableviewComp, hasDelegate: true },
{ tag: "no delegate", viewComp: noDelegateTableViewComp, hasDelegate: false },
]
}
function test_tableView_extendedSelection_data() {
return init_delegate_data_tag()
}
function test_tableView_extendedSelection(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
// ExtendedSelection should be the default selection mode
compare(tableView.selectionMode, TableView.ExtendedSelection)
// Select two cells by dragging
verify(!tableView.selectionModel.hasSelection)
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A shift click should extend the selection
mouseClick(tableView, (cellWidth * 3) - 2, 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 3)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A control click should add a new cell to the selection
mouseClick(tableView, 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2)))
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// A shift click should further extend the selection from the last cell selected
mouseClick(tableView, (cellWidth * 3) - 2, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 6)
for (let r = 0; r < 2; ++r)
for (let c = 0; c < 3; ++c)
verify(tableView.selectionModel.isSelected(tableView.model.index(r, c)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Shift click the second selection so that it overlaps with the first
mouseClick(tableView, 1, 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 2)))
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Shift click the selection back again. The first selection on
// row 0 should still be present, even if the second selection
// no longer overlaps it.
mouseClick(tableView, (cellWidth * 3) - 2, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ShiftModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 6)
for (let r = 0; r < 2; ++r)
for (let c = 0; c < 3; ++c)
verify(tableView.selectionModel.isSelected(tableView.model.index(r, c)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_unselect_click_data() {
return init_delegate_data_tag()
}
function test_unselect_click(data) {
// Check at a ctrl click on top a selected cell
// will cause the cell to be unselected.
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
// Select some cells
tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(0, 1), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(0, 3), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(1, 0), ItemSelectionModel.Select)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Do a ctrl-click on top of a selected cell. This
// should cause the cell to be unselected.
mouseClick(tableView, cellWidth / 2, cellHeight / 2, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 3)
verify(!tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3)))
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0)))
verify(selectionRectangle.active)
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_unselect_drag_data() {
return init_delegate_data_tag()
}
function test_unselect_drag(data) {
// Check at a ctrl drag on top a selected cell
// will cause the dragged-over cells to be unselected.
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
// Select some cells
tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(0, 1), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(0, 3), ItemSelectionModel.Select)
tableView.selectionModel.select(tableView.index(1, 0), ItemSelectionModel.Select)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Do a ctrl-drag on top of the selected cells. This
// should cause all the cells to be unselected.
mousePress(tableView.contentItem, cellWidth / 2, cellHeight / 2, Qt.LeftButton, Qt.ControlModifier)
mouseMove(tableView.contentItem, cellWidth * 4, cellHeight * 2, 0, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.selectedIndexes.length, 0)
// Move the mouse back to cell 2, and release the mouse. Only
// the top left cells will then be unselected
mouseMove(tableView.contentItem, (cellWidth * 2) - 1, (cellHeight * 2) - 1, 0, Qt.LeftButton, Qt.ControlModifier)
mouseRelease(tableView.contentItem, (cellWidth * 2) - 1, (cellHeight * 2) - 1, Qt.LeftButton, Qt.ControlModifier)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 3)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_handle_position() {
// Check that the handles end up at the corner of the selection
// even if if we resize some rows and column while they have
// been flicked out of the viewport.
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.topLeftHandle = topLeftHandleComp
selectionRectangle.bottomRightHandle = bottomRightHandleComp
selectionRectangle.selectionMode = SelectionRectangle.Drag
tableView.animate = false
verify(waitForItemPolished(tableView))
// Select a cell
let selectedCell = Qt.point(1, 1)
let selectedItem = tableView.itemAtCell(selectedCell)
verify(selectedItem)
mouseDrag(tableView.contentItem, selectedItem.x, selectedItem.y, 10, 10, Qt.LeftButton)
verify(tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(topLeftHandle)
verify(bottomRightHandle)
// Check that the handles are placed at the corners of the selected cell
compare(topLeftHandle.x, selectedItem.x - (topLeftHandle.width / 2))
compare(topLeftHandle.y, selectedItem.y - (topLeftHandle.height / 2))
compare(bottomRightHandle.x, selectedItem.x + selectedItem.width - (bottomRightHandle.width / 2))
compare(bottomRightHandle.y, selectedItem.y + selectedItem.height - (bottomRightHandle.height / 2))
// Resize some of the rows and columns that will
// affect the position of the handles.
tableView.setColumnWidth(0, cellWidth + 5)
tableView.setRowHeight(0, cellHeight + 5)
tableView.setColumnWidth(1, cellWidth + 5)
tableView.setRowHeight(1, cellHeight + 5)
verify(waitForItemPolished(tableView))
// Check that the handles are still placed at
// the corners of the selected cell.
compare(topLeftHandle.x, selectedItem.x - (topLeftHandle.width / 2))
compare(topLeftHandle.y, selectedItem.y - (topLeftHandle.height / 2))
compare(bottomRightHandle.x, selectedItem.x + selectedItem.width - (bottomRightHandle.width / 2))
compare(bottomRightHandle.y, selectedItem.y + selectedItem.height - (bottomRightHandle.height / 2))
// Move the selected cell out of the
// viewport (together with the selection handles).
tableView.positionViewAtCell(Qt.point(4, 4), TableView.AlignLeft | TableView.AlignTop)
verify(waitForItemPolished(tableView))
// Resize some of the rows and columns that will
// affect the position of the handles.
tableView.setColumnWidth(0, cellWidth + 10)
tableView.setRowHeight(0, cellHeight + 10)
tableView.setColumnWidth(1, cellWidth + 10)
tableView.setRowHeight(1, cellHeight + 10)
verify(waitForItemPolished(tableView))
// Flick the selected cell back into the viewport
tableView.positionViewAtCell(Qt.point(0, 0), TableView.AlignLeft | TableView.AlignTop)
verify(waitForItemPolished(tableView))
// Check that the handles are still placed around the selected cell
selectedItem = tableView.itemAtCell(selectedCell)
verify(selectedItem)
verify(topLeftHandle)
verify(bottomRightHandle)
compare(topLeftHandle.x, selectedItem.x - (topLeftHandle.width / 2))
compare(topLeftHandle.y, selectedItem.y - (topLeftHandle.height / 2))
compare(bottomRightHandle.x, selectedItem.x + selectedItem.width - (bottomRightHandle.width / 2))
compare(bottomRightHandle.y, selectedItem.y + selectedItem.height - (bottomRightHandle.height / 2))
// Remove the selection, and check that the handles end up hidden
mouseClick(tableView, tableView.width - 1, tableView.height - 1, Qt.LeftButton)
verify(!tableView.selectionModel.hasSelection)
verify(!topLeftHandle.visible)
verify(!bottomRightHandle.visible)
}
function test_delegateWithTapHandler() {
// Check that we clear the current selection if you start a new
// mouse drag selection on top of a delegate with a tap handler.
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
tableView.delegate = delegateWithTapHandlerComp;
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
tableView.selectionMode = TableView.ExtendedSelection
verify(waitForItemPolished(tableView))
let item0_0 = tableView.itemAtIndex(tableView.index(0, 0))
let item1_1 = tableView.itemAtIndex(tableView.index(1, 1))
verify(item0_0)
verify(item1_1)
tableView.selectionModel.select(tableView.index(0, 0), ItemSelectionModel.Select)
compare(tableView.selectionModel.selectedIndexes.length, 1)
compare(tableView.selectionModel.selectedIndexes[0], tableView.index(0, 0))
// A drag should clear the current selection and select a new cell
mouseDrag(tableView.contentItem, item1_1.x, item1_1.y, 10, 10, Qt.LeftButton)
compare(tableView.selectionModel.selectedIndexes.length, 1)
compare(tableView.selectionModel.selectedIndexes[0], tableView.index(1, 1))
// Verify that a PressAndHold works as well
selectionRectangle.selectionMode = SelectionRectangle.PressAndHold
mousePress(tableView, item0_0.x, item0_0.y, Qt.LeftButton)
mouseRelease(tableView, item0_0.x, item0_0.y, Qt.LeftButton, Qt.NoModifier, 2000)
compare(tableView.selectionModel.selectedIndexes.length, 1)
compare(tableView.selectionModel.selectedIndexes[0], tableView.index(0, 0))
}
// TODO: enable this test when mouseDrag sends modifiers for all mouse events
// (including mouseMove)
// function test_multi_selection() {
// let tableView = createTemporaryObject(tableviewComp, testCase)
// verify(tableView)
// let selectionRectangle = tableView.selectionRectangle
// verify(selectionRectangle)
// verify(!tableView.selectionModel.hasSelection)
// selectionRectangle.selectionMode = SelectionRectangle.Drag
// mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
// verify(tableView.selectionModel.hasSelection)
// compare(tableView.selectionModel.selectedIndexes.length, 2)
// verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
// verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
// // Hold down control, and drag again to do a multi-selection
// mouseDrag(tableView, 1, cellHeight + 5, (cellWidth * 2) - 2, 1, Qt.LeftButton, Qt.ControlModifier)
// verify(tableView.selectionModel.hasSelection)
// compare(tableView.selectionModel.selectedIndexes.length, 4)
// verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
// verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
// verify(tableView.selectionModel.isSelected(tableView.model.index(1, 0)))
// verify(tableView.selectionModel.isSelected(tableView.model.index(1, 1)))
// }
function test_pressAndHold_data() {
return [
{ tag: "resize enabled (with delegate)", resizeEnabled: true, viewComp: tableviewComp, hasDelegate: true },
{ tag: "resize disabled (with delegate)", resizeEnabled: false, viewComp: tableviewComp, hasDelegate: true },
{ tag: "resize enabled (no delegate)", resizeEnabled: true, viewComp: noDelegateTableViewComp, hasDelegate: false },
{ tag: "resize disabled (no delegate)", resizeEnabled: false, viewComp: noDelegateTableViewComp, hasDelegate: false },
]
}
function test_pressAndHold(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
// Check that we can start a selection from the middle of a cell, even
// if a drag or tap on the edge of the cell would resize it.
tableView.resizableRows = data.resizeEnabled
tableView.resizableColumns = data.resizeEnabled
selectionRectangle.selectionMode = SelectionRectangle.PressAndHold
let activeSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "activeChanged"})
let draggingSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "draggingChanged"})
verify(activeSpy.valid)
verify(draggingSpy.valid)
verify(!tableView.selectionModel.hasSelection)
// Do a press and hold
mousePress(tableView, 1, 1, Qt.LeftButton)
mouseRelease(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 1000)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
compare(draggingSpy.count, 0)
compare(activeSpy.count, 1)
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
compare(draggingSpy.count, 0)
compare(activeSpy.count, 0)
}
// Remove selection
mouseClick(tableView, 100, 100, Qt.LeftButton)
verify(!tableView.selectionModel.hasSelection)
compare(draggingSpy.count, 0)
if (data.hasDelegate)
compare(activeSpy.count, 2)
else
compare(activeSpy.count, 0)
// Ensure that a drag doesn't start a selection
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
verify(!tableView.selectionModel.hasSelection)
}
function test_pressAndHoldPlussShift_data() {
return init_delegate_data_tag()
}
function test_pressAndHoldPlussShift(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
const invalidIndex = tableView.index(-1, -1)
verify(!tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.currentIndex, invalidIndex)
// select cell 0,0
mouseClick(tableView, 1, 1, Qt.LeftButton)
if (data.hasDelegate)
compare(tableView.selectionModel.currentIndex, tableView.index(0, 0))
else
compare(tableView.selectionModel.currentIndex, invalidIndex)
// do a long press on cell 1,0 while holding down Shift. This will
// select both cells.
mousePress(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier)
mouseRelease(tableView, cellWidth + 1, 1, Qt.LeftButton, Qt.ShiftModifier, 2000)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 1)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_pressAndHold_on_top_of_handle() {
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.PressAndHold
let activeSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "activeChanged"})
let draggingSpy = signalSpy.createObject(selectionRectangle, {target: selectionRectangle, signalName: "draggingChanged"})
verify(activeSpy.valid)
verify(draggingSpy.valid)
verify(!tableView.selectionModel.hasSelection)
// Do a press and hold
mousePress(tableView, 1, 1, Qt.LeftButton)
mouseRelease(tableView, 1, 1, Qt.LeftButton, Qt.NoModifier, 2000)
verify(tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
compare(draggingSpy.count, 0)
compare(activeSpy.count, 1)
// Do another press and hold on top the part of the bottom right handle that
// also covers cell 1, 1. Without any handles, this would start a new selection
// on top of that cell. But when the handles are in front, they should block it.
mousePress(tableView, cellWidth + 1, cellHeight + 1, Qt.LeftButton)
mouseRelease(tableView, cellWidth + 1, cellHeight + 1, Qt.LeftButton, Qt.NoModifier, 2000)
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(0, 0)))
}
function test_handleDragTopLeft_data() {
return init_delegate_data_tag()
}
function test_handleDragTopLeft(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
verify(!tableView.selectionModel.hasSelection)
// Select four cells in the middle
mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
for (let x = 1; x < 3; ++x) {
for (let y = 1; y < 3; ++y) {
verify(tableView.selectionModel.isSelected(tableView.model.index(x, y)))
}
}
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Drag on the top left handle, so that the selection extends to cell 0, 0
mouseDrag(tableView, cellWidth, cellHeight, -cellWidth / 2, -cellHeight / 2, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 9)
for (let x = 0; x < 3; ++x) {
for (let y = 0; y < 3; ++y) {
verify(tableView.selectionModel.isSelected(tableView.model.index(x, y)))
}
}
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_handleDragBottomRight_shrink_data() {
return init_delegate_data_tag()
}
function test_handleDragBottomRight_shrink(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
verify(!tableView.selectionModel.hasSelection)
// Select four cells in the middle
mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
for (let x = 1; x < 3; ++x) {
for (let y = 1; y < 3; ++y) {
verify(tableView.selectionModel.isSelected(tableView.model.index(x, y)))
}
}
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Drag on the bottom right handle, so that the selection shrinks to cell 1, 1
mouseDrag(tableView, (cellWidth * 3) - 1, (cellHeight * 3) - 1, -cellWidth, -cellHeight, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 1)
verify(tableView.selectionModel.isSelected(tableView.model.index(1, 1)))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_handleDragBottomRight_expand_data() {
return init_delegate_data_tag()
}
function test_handleDragBottomRight_expand(data) {
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
verify(!tableView.selectionModel.hasSelection)
// Select four cells in the middle
mouseDrag(tableView, cellWidth + 1, cellHeight + 1, (cellWidth * 2) - 2, (cellHeight * 2) - 2, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 4)
for (let x = 1; x < 3; ++x) {
for (let y = 1; y < 3; ++y) {
verify(tableView.selectionModel.isSelected(tableView.model.index(x, y)))
}
}
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
// Drag on the bottom right handle, so that the selection expands to cell 9 cells
mouseDrag(tableView, cellWidth * 3, cellHeight * 3, 10, 10, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 9)
for (let x = 1; x < 4; ++x) {
for (let y = 1; y < 4; ++y) {
verify(tableView.selectionModel.isSelected(tableView.model.index(x, y)))
}
}
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_programmatic_unselect_data() {
return init_delegate_data_tag()
}
function test_programmatic_unselect(data) {
// Check that the SelectionRectangle will be deactivated if the
// selection is changed programatically.
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.selectionMode = SelectionRectangle.Drag
verify(!tableView.selectionModel.hasSelection)
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(selectionRectangle.active)
} else {
verify(!selectionRectangle.active)
}
tableView.selectionModel.clearSelection()
verify(!selectionRectangle.active)
}
function test_extend_using_keyboard_data() {
return init_delegate_data_tag()
}
function test_extend_using_keyboard(data) {
// Check that the bottom-right selection handle will move if an
// acitve selection is extended with the keyboard
let tableView = createTemporaryObject(data.viewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.bottomRightHandle = bottomRightHandleComp
selectionRectangle.selectionMode = SelectionRectangle.Drag
tableView.forceActiveFocus()
verify(!tableView.selectionModel.hasSelection)
mouseDrag(tableView, 1, 1, (cellWidth * 2) - 2, 1, Qt.LeftButton)
compare(tableView.selectionModel.hasSelection, data.hasDelegate)
if (tableView.selectionModel.hasSelection) {
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(selectionRectangle.active)
verify(bottomRightHandle)
compare(bottomRightHandle.x, (cellWidth * 2) - (bottomRightHandle.width / 2))
compare(bottomRightHandle.y, cellHeight - (bottomRightHandle.height / 2))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
keyPress(Qt.Key_Down, Qt.ShiftModifier)
keyRelease(Qt.Key_Down, Qt.ShiftModifier)
keyPress(Qt.Key_Right, Qt.ShiftModifier)
keyRelease(Qt.Key_Right, Qt.ShiftModifier)
if (data.hasDelegate) {
verify(selectionRectangle.active)
compare(tableView.selectionModel.selectedIndexes.length, 6)
compare(bottomRightHandle.x, (cellWidth * 3) - (bottomRightHandle.width / 2))
compare(bottomRightHandle.y, (cellHeight * 2) - (bottomRightHandle.height / 2))
} else {
verify(!selectionRectangle.active)
verify(!topLeftHandle)
verify(!bottomRightHandle)
}
}
function test_inactive_after_unselecting_last_cell_data() {
const mouse_ctrl_click = (item, x, y) => {
mouseClick(item, x, y, Qt.LeftButton, Qt.ControlModifier)
}
const mouse_ctrl_press_and_hold = (item, x, y) => {
const holdInterval = Qt.styleHints.mousePressAndHoldInterval + 1
mousePress(item, x, y, Qt.LeftButton, Qt.ControlModifier)
mouseRelease(item, x, y, Qt.LeftButton, Qt.ControlModifier, holdInterval)
}
return [
{ tag: "controlClick", doMouseEvent: mouse_ctrl_click },
{ tag: "pressAndHold", doMouseEvent: mouse_ctrl_press_and_hold },
]
}
function test_inactive_after_unselecting_last_cell(data) {
// Deselecting the only selected cell should
// make the selection rectangle inactive
let tableView = createTemporaryObject(tableviewComp, testCase)
verify(tableView)
let selectionRectangle = tableView.selectionRectangle
verify(selectionRectangle)
selectionRectangle.topLeftHandle = topLeftHandleComp
selectionRectangle.bottomRightHandle = bottomRightHandleComp
selectionRectangle.selectionMode = SelectionRectangle.Drag
const index_0_0 = tableView.model.index(0, 0)
const index_0_1 = tableView.model.index(0, 1)
const do_mouse_event_on = (index) => {
const item = tableView.itemAtIndex(index)
data.doMouseEvent(tableView, item.x + cellWidth / 2, item.y + 1)
}
do_mouse_event_on(index_0_0)
do_mouse_event_on(index_0_1)
verify(tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.selectedIndexes.length, 2)
verify(tableView.selectionModel.isSelected(index_0_0))
verify(tableView.selectionModel.isSelected(index_0_1))
verify(selectionRectangle.active)
verify(topLeftHandle && topLeftHandle.visible)
verify(bottomRightHandle && bottomRightHandle.visible)
do_mouse_event_on(index_0_0)
do_mouse_event_on(index_0_1)
verify(!tableView.selectionModel.hasSelection)
compare(tableView.selectionModel.selectedIndexes.length, 0)
verify(!selectionRectangle.active)
verify(!topLeftHandle || !topLeftHandle.visible)
verify(!bottomRightHandle || !bottomRightHandle.visible)
}
}
|