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
|
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the test suite of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:BSD$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** BSD License Usage
** Alternatively, you may use this file under the terms of the BSD license
** as follows:
**
** "Redistribution and use in source and binary forms, with or without
** modification, are permitted provided that the following conditions are
** met:
** * Redistributions of source code must retain the above copyright
** notice, this list of conditions and the following disclaimer.
** * Redistributions in binary form must reproduce the above copyright
** notice, this list of conditions and the following disclaimer in
** the documentation and/or other materials provided with the
** distribution.
** * Neither the name of The Qt Company Ltd nor the names of its
** contributors may be used to endorse or promote products derived
** from this software without specific prior written permission.
**
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
** $QT_END_LICENSE$
**
****************************************************************************/
import QtQuick 2.4
import QtTest 1.0
import QtQuick.Controls 1.4
import QtQuick.Controls.Private 1.0
import QtQuickControlsTests 1.0
Item {
id: container
width: 400
height: 400
TestCase {
id: testCase
name: "Tests_TreeView"
when:windowShown
width:400
height:400
objectName: "testCase"
SignalSpy {
id: spy
}
Component {
id: newColumn
TableViewColumn {
role: "name"
title: "Name"
}
}
property var instance_selectionModel: 'import QtQml.Models 2.2; ItemSelectionModel {}'
property var semiIndent: 20/2 // PM_TreeViewIndentation 20 in commonStyle
function cleanup()
{
// Make sure to delete all children even when the test has failed.
for (var child in container.children) {
if (container.children[child].objectName !== "testCase")
container.children[child].destroy()
}
}
function test_basic_setup()
{
var test_instanceStr =
'import QtQuick 2.4; \
import QtQuick.Controls 1.4; \
import QtQuickControlsTests 1.0;\
TreeView { \
model: TreeModel {} \
TableViewColumn { \
role: "display"; \
title: "Default"; \
} \
}'
var tree = Qt.createQmlObject(test_instanceStr, container, '')
verify(!tree.currentIndex.valid)
compare(tree.columnCount, 1)
tree.addColumn(newColumn)
compare(tree.columnCount, 2)
}
function test_clicked_signals()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
tree.forceActiveFocus()
verify(!tree.currentIndex.valid)
spy.clear()
spy.target = tree
spy.signalName = "clicked"
compare(spy.count, 0)
mouseClick(tree, semiIndent + 50, 120, Qt.LeftButton, Qt.NoModifier, 10)
compare(spy.count, 1)
var clickedItem = spy.signalArguments[0][0]
verify(clickedItem.valid)
compare(clickedItem.row, 1)
compare(tree.currentIndex.row, 1)
compare(clickedItem.internalId, tree.currentIndex.internalId)
spy.clear()
spy.target = tree
spy.signalName = "doubleClicked"
compare(spy.count, 0)
mouseDoubleClickSequence(tree, semiIndent + 50, 220, Qt.LeftButton)
compare(spy.count, 1)
clickedItem = spy.signalArguments[0][0]
verify(clickedItem.valid)
compare(clickedItem.row, 3)
compare(clickedItem.internalId, tree.currentIndex.internalId)
spy.clear()
spy.target = tree
spy.signalName = "activated"
compare(spy.count, 0)
if (!tree.__activateItemOnSingleClick)
mouseDoubleClickSequence(tree, semiIndent + 50 , 120, Qt.LeftButton)
else
mouseClick(tree, semiIndent + 50, 120, Qt.LeftButton)
compare(spy.count, 1)
clickedItem = spy.signalArguments[0][0]
verify(clickedItem.valid)
compare(clickedItem.row, 1)
compare(clickedItem.internalId, tree.currentIndex.internalId)
}
function test_headerHidden()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
tree.headerVisible = false
tree.forceActiveFocus()
verify(!tree.currentIndex.valid)
spy.clear()
spy.target = tree
spy.signalName = "clicked"
compare(spy.count, 0)
mouseClick(tree, semiIndent + 50, 20, Qt.LeftButton)
compare(spy.count, 1)
verify(spy.signalArguments[0][0].valid)
compare(spy.signalArguments[0][0].row, 0)
compare(tree.currentIndex.row, 0)
}
function test_expand_collapse()
{
if (Settings.hasTouchScreen)
skip("Fails with touch screens");
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
tree.forceActiveFocus()
spy.clear()
spy.target = tree
spy.signalName = "expanded"
// expanded on click
compare(spy.count, 0)
mouseClick(tree, semiIndent, 70, Qt.LeftButton, Qt.NoModifier, 10)
compare(spy.count, 1)
var expandedIndex = spy.signalArguments[0][0]
verify(expandedIndex.valid)
compare(expandedIndex.row, 0)
compare(tree.isExpanded(expandedIndex), true)
// expand first child on click
mouseClick(tree, semiIndent * 3, 120, Qt.LeftButton)
compare(spy.count, 2)
var childIndex = spy.signalArguments[1][0]
verify(childIndex.valid)
compare(childIndex.row, 0)
compare(tree.isExpanded(childIndex), true)
compare(childIndex.parent.internalId, expandedIndex.internalId)
spy.clear()
spy.signalName = "collapsed"
// collapsed on click top item
compare(spy.count, 0)
mouseClick(tree, semiIndent, 70, Qt.LeftButton)
compare(spy.count, 1)
var collapsedIndex = spy.signalArguments[0][0]
verify(collapsedIndex.valid)
compare(collapsedIndex.row, 0)
compare(tree.isExpanded(collapsedIndex), false)
compare(expandedIndex.internalId, collapsedIndex.internalId)
// check hidden child is still expanded
compare(tree.isExpanded(childIndex), true)
// collapse child with function
tree.collapse(childIndex)
compare(tree.isExpanded(childIndex), false)
compare(spy.count, 2)
compare(spy.signalArguments[1][0].row, 0)
spy.clear()
spy.signalName = "expanded"
compare(spy.count, 0)
// expand child with function
tree.expand(expandedIndex)
compare(tree.isExpanded(expandedIndex), true)
compare(spy.count, 1)
compare(spy.signalArguments[0][0].row, 0)
}
function test_pressAndHold()
{
if (Settings.hasTouchScreen)
skip("Fails with touch screens");
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
tree.forceActiveFocus()
var styleIndent = !!tree.style.indentation ? tree.style.indentation/2 : 6
verify(!tree.currentIndex.valid)
spy.clear()
spy.target = tree
spy.signalName = "pressAndHold"
compare(spy.count, 0)
mousePress(tree, styleIndent + 50, 70, Qt.LeftButton, Qt.NoModifier, 10)
mouseRelease(tree, styleIndent + 50, 70, Qt.LeftButton, Qt.NoModifier, 1000)
wait(20)
compare(spy.count, 1)
verify(spy.signalArguments[0][0].valid)
compare(spy.signalArguments[0][0].row, 0)
compare(tree.currentIndex.row, 0)
}
function test_keys_navigation()
{
var component = Qt.createComponent("treeview/treeview_2.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
tree.forceActiveFocus()
// select second item with no children
verify(!tree.currentIndex.valid)
mouseClick(tree, semiIndent + 50, 120, Qt.LeftButton, Qt.NoModifier, 10)
var secondTopItem = tree.currentIndex
verify(secondTopItem.valid)
verify(!secondTopItem.parent.valid)
compare(secondTopItem.row, 1)
// Press right (selected item is non expandable)
compare(tree.collapsedCount, 0)
compare(tree.expandedCount, 0)
keyClick(Qt.Key_Right)
compare(tree.collapsedCount, 0)
compare(tree.expandedCount, 0)
compare(tree.currentIndex, secondTopItem)
// Going down
keyClick(Qt.Key_Down)
var thirdTopItem = tree.currentIndex
compare(thirdTopItem.row, 2)
verify(!thirdTopItem.parent.valid)
// Press right - expand - go down - go up - collapse
keyClick(Qt.Key_Right)
compare(tree.collapsedCount, 0)
compare(tree.expandedCount, 1)
compare(tree.isExpanded(thirdTopItem), true)
keyClick(Qt.Key_Down)
var firstChild_thirdTopItem = tree.currentIndex
compare(firstChild_thirdTopItem.row, 0)
verify(firstChild_thirdTopItem.parent.valid)
compare(firstChild_thirdTopItem.parent.row, 2)
compare(firstChild_thirdTopItem.parent.internalId, thirdTopItem.internalId)
keyClick(Qt.Key_Up)
verify(!tree.currentIndex.parent.valid)
compare(tree.currentIndex.internalId, thirdTopItem.internalId)
compare(tree.currentIndex.row, 2)
compare(tree.isExpanded(tree.currentIndex), true)
keyClick(Qt.Key_Left)
compare(tree.isExpanded(tree.currentIndex), false)
compare(tree.collapsedCount, 1)
compare(tree.expandedCount, 1)
}
function test_selection_singleSelection()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
// Collect some model index
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton, Qt.NoModifier, 30)
var firstItem = tree.currentIndex
verify(firstItem.valid)
compare(firstItem.row, 0)
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton, Qt.NoModifier, 10)
var secondItem = tree.currentIndex
verify(secondItem.valid)
compare(secondItem.row, 1)
mouseClick(tree, semiIndent + 50, 20 + 3*50, Qt.LeftButton, Qt.NoModifier, 10)
var thirdItem = tree.currentIndex
verify(thirdItem.valid)
compare(thirdItem.row, 2)
mouseClick(tree, semiIndent + 50, 20 + 4*50, Qt.LeftButton, Qt.NoModifier, 10)
var fourthItem = tree.currentIndex
verify(fourthItem.valid)
compare(fourthItem.row, 3)
mouseClick(tree, semiIndent + 50, 20 + 5*50, Qt.LeftButton, Qt.NoModifier, 10)
var fifthItem = tree.currentIndex
verify(fifthItem.valid)
compare(fifthItem.row, 4)
mouseClick(tree, semiIndent + 50, 20 + 6*50, Qt.LeftButton, Qt.NoModifier, 10)
var sixthItem = tree.currentIndex
verify(sixthItem.valid)
compare(sixthItem.row, 5)
compare(tree.selection, null)
tree.selection = selectionModel
compare(tree.selection, selectionModel)
tree.selection.clear()
compare(tree.selection.hasSelection, false)
//// Single selectionModel
compare(tree.selectionMode, SelectionMode.SingleSelection)
verify(!tree.selection.currentIndex.valid)
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton, Qt.NoModifier, 10)
verify(tree.selection.currentIndex.valid)
compare(secondItem.internalId, tree.currentIndex.internalId)
compare(secondItem.internalId, tree.selection.currentIndex.internalId)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.hasSelection, true)
var list = tree.selection.selectedIndexes
compare(list.length, 1)
if (list.length === 1) {
compare(list[0].internalId, secondItem.internalId)
compare(tree.selection.isSelected(secondItem), true)
}
keyClick(Qt.Key_Down, Qt.ShiftModifier)
compare(thirdItem.internalId, tree.currentIndex.internalId)
compare(thirdItem.internalId, tree.selection.currentIndex.internalId)
keyClick(Qt.Key_Down, Qt.ControlModifier)
compare(fourthItem.internalId, tree.currentIndex.internalId)
expectFailContinue('', 'BUG selected state not updated with Command/Control when SingleSelection')
compare(fourthItem.internalId, tree.selection.currentIndex.internalId)
expectFailContinue('', 'BUG selected state not updated with Command/Control when SingleSelection')
compare(tree.selection.isSelected(fourthItem), true)
}
function test_selection_noSelection()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
// Collect some model index
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton)
var firstItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton)
var secondItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 3*50, Qt.LeftButton)
var thirdItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 4*50, Qt.LeftButton)
var fourthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 5*50, Qt.LeftButton)
var fifthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 6*50, Qt.LeftButton)
var sixthItem = tree.currentIndex
compare(tree.selection, null)
tree.selection = selectionModel
compare(tree.selection, selectionModel)
tree.selection.clear()
compare(tree.selection.hasSelection, false)
//// No selection
tree.selectionMode = SelectionMode.NoSelection
compare(tree.selectionMode, SelectionMode.NoSelection)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
compare(secondItem.internalId, tree.currentIndex.internalId)
verify(!tree.selection.currentIndex.valid)
compare(tree.selection.hasSelection, false)
compare(tree.selection.isSelected(secondItem), false)
keyClick(Qt.Key_Down, Qt.ShiftModifier)
verify(!tree.selection.currentIndex.valid)
compare(tree.selection.hasSelection, false)
compare(tree.selection.isSelected(thirdItem), false)
keyClick(Qt.Key_Down, Qt.ControlModifier)
verify(!tree.selection.currentIndex.valid)
compare(tree.selection.hasSelection, false)
}
function test_selection_multiSelection()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
// Collect some model index
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton, Qt.NoModifier0, 10)
var firstItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton, Qt.NoModifier, 10)
var secondItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 3*50, Qt.LeftButton, Qt.NoModifier, 10)
var thirdItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 4*50, Qt.LeftButton, Qt.NoModifier, 10)
var fourthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 5*50, Qt.LeftButton, Qt.NoModifier, 10)
var fifthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 6*50, Qt.LeftButton, Qt.NoModifier, 10)
var sixthItem = tree.currentIndex
compare(tree.selection, null)
tree.selection = selectionModel
compare(tree.selection, selectionModel)
tree.selection.clear()
compare(tree.selection.hasSelection, false)
////// Multi selection
tree.selectionMode = SelectionMode.MultiSelection
compare(tree.selectionMode, SelectionMode.MultiSelection)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton, Qt.NoModifier, 10)
compare(secondItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
var listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 1)
compare(listIndexes[0].internalId, secondItem.internalId)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, secondItem.internalId)
mouseClick(tree, semiIndent + 50, 70+150, Qt.LeftButton)
compare(fourthItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(fourthItem), true)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 2)
compare(listIndexes[0].internalId, secondItem.internalId)
compare(listIndexes[1].internalId, fourthItem.internalId)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, fourthItem.internalId)
keyPress(Qt.Key_Shift)
mouseClick(tree, semiIndent + 50, 70+250, Qt.LeftButton)
keyRelease(Qt.Key_Shift)
compare(sixthItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(fifthItem), false)
compare(tree.selection.isSelected(sixthItem), true)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 3)
compare(listIndexes[0].internalId, secondItem.internalId)
compare(listIndexes[1].internalId, fourthItem.internalId)
compare(listIndexes[2].internalId, sixthItem.internalId)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, sixthItem.internalId)
mouseClick(tree, semiIndent + 50, 70+150, Qt.LeftButton)
compare(fourthItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(fourthItem), false)
compare(tree.selection.isSelected(sixthItem), true)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 2)
compare(listIndexes[0].internalId, secondItem.internalId)
compare(listIndexes[1].internalId, sixthItem.internalId)
verify(tree.selection.currentIndex.valid)
mouseClick(tree, semiIndent + 50, 70+150, Qt.LeftButton)
compare(fourthItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(sixthItem), true)
keyPress(Qt.Key_Shift)
keyClick(Qt.Key_Down)
keyClick(Qt.Key_Down)
keyClick(Qt.Key_Down)
keyRelease(Qt.Key_Shift)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(fifthItem), true)
compare(tree.selection.isSelected(sixthItem), false)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 4)
}
function test_selection_extendedSelection()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
// Collect some model index
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton, Qt.NoModifier, 10)
var firstItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton, Qt.NoModifier, 10)
var secondItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 3*50, Qt.LeftButton, Qt.NoModifier, 10)
var thirdItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 4*50, Qt.LeftButton, Qt.NoModifier, 10)
var fourthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 5*50, Qt.LeftButton, Qt.NoModifier, 10)
var fifthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 6*50, Qt.LeftButton, Qt.NoModifier, 10)
var sixthItem = tree.currentIndex
compare(tree.selection, null)
tree.selection = selectionModel
compare(tree.selection, selectionModel)
tree.selection.clear()
compare(tree.selection.hasSelection, false)
////// Extended selection
tree.selectionMode = SelectionMode.ExtendedSelection
compare(tree.selectionMode, SelectionMode.ExtendedSelection)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton, Qt.NoModifier, 10)
compare(secondItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
var listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 1)
compare(listIndexes[0].internalId, secondItem.internalId)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, secondItem.internalId)
// Re-click does not deselect
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
// Ctrl/Cmd click deselect
mouseClick(tree, semiIndent + 50, 70+52, Qt.LeftButton, Qt.ControlModifier)
compare(tree.selection.hasSelection, false)
compare(tree.selection.isSelected(secondItem), false)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 0)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
keyPress(Qt.Key_Down, Qt.ShiftModifier)
keyPress(Qt.Key_Down, Qt.ShiftModifier)
keyClick(Qt.Key_Down, Qt.ShiftModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 4)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(thirdItem), true)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(fifthItem), true)
mouseClick(tree, semiIndent + 50, 70+300, Qt.LeftButton, Qt.ShiftModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 6)
mouseClick(tree, semiIndent + 50, 70+150, Qt.LeftButton, Qt.ControlModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 5)
compare(tree.selection.isSelected(fourthItem), false)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(thirdItem), true)
compare(tree.selection.isSelected(sixthItem), true)
compare(tree.selection.isSelected(fifthItem), true)
}
function test_selection_contiguousSelection()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
// Collect some model index
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton)
var firstItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 2*50, Qt.LeftButton)
var secondItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 3*50, Qt.LeftButton)
var thirdItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 4*50, Qt.LeftButton)
var fourthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 5*50, Qt.LeftButton)
var fifthItem = tree.currentIndex
mouseClick(tree, semiIndent + 50, 20 + 6*50, Qt.LeftButton)
var sixthItem = tree.currentIndex
compare(tree.selection, null)
tree.selection = selectionModel
compare(tree.selection, selectionModel)
tree.selection.clear()
compare(tree.selection.hasSelection, false)
////// Contiguous selection
tree.selectionMode = SelectionMode.ContiguousSelection
compare(tree.selectionMode, SelectionMode.ContiguousSelection)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
compare(secondItem.internalId, tree.currentIndex.internalId)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
var listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 1)
compare(listIndexes[0].internalId, secondItem.internalId)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, secondItem.internalId)
// Re-click does not deselect
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
// Ctrl/Cmd click deselect all, selects current
mouseClick(tree, semiIndent + 50, 70+52, Qt.LeftButton, Qt.ControlModifier)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 1)
mouseClick(tree, semiIndent + 50, 70+50, Qt.LeftButton)
keyPress(Qt.Key_Down, Qt.ShiftModifier)
keyPress(Qt.Key_Down, Qt.ShiftModifier)
keyClick(Qt.Key_Down, Qt.ShiftModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 4)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(thirdItem), true)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(fifthItem), true)
verify(tree.selection.currentIndex.valid)
if (tree.selection.currentIndex.valid)
compare(tree.selection.currentIndex.internalId, fifthItem.internalId)
mouseClick(tree, semiIndent + 50, 70+300, Qt.LeftButton, Qt.ShiftModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 6)
mouseClick(tree, semiIndent + 50, 70+150, Qt.LeftButton, Qt.ShiftModifier)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 3)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(secondItem), true)
compare(tree.selection.isSelected(thirdItem), true)
compare(tree.selection.isSelected(fourthItem), true)
compare(tree.selection.isSelected(fifthItem), false)
compare(tree.selection.isSelected(sixthItem), false)
mouseClick(tree, semiIndent + 50, 70+100, Qt.LeftButton)
listIndexes = tree.selection.selectedIndexes
compare(listIndexes.length, 1)
compare(tree.selection.hasSelection, true)
compare(tree.selection.isSelected(thirdItem), true)
}
function test_indexAt() {
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
verify(waitForRendering(tree), "TreeView did not render on time")
var model = tree.model
wait(50)
// Sample each row and test
for (var row = 0; row < tree.__listView.count; row++) {
for (var x = 1; x < tree.getColumn(0).width; x += 10) {
var treeIndex = tree.indexAt(x, 50 * (row + 1) + 1) // offset by header height
var modelIndex = model.index(row, 0)
if (treeIndex.row !== modelIndex.row
|| treeIndex.column !== modelIndex.column
|| treeIndex.internalId !== modelIndex.internalId) {
console.log("Test about to fail: row = " + row + ", __listView.count =" + tree.__listView.count)
console.log(" . . . . . . . . . x =" + x + ", getColumn(0).width =" + tree.getColumn(0).width)
console.log("pairs of should-be-equal values: ",
treeIndex.row, modelIndex.row,
treeIndex.column, modelIndex.column,
treeIndex.internalId, modelIndex.internalId)
}
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
}
}
// Hide header, test again
tree.headerVisible = false
for (row = 0; row < tree.__listView.count; row++) {
for (x = 1; x < tree.getColumn(0).width; x += 10) {
treeIndex = tree.indexAt(x, 50 * row + 1)
modelIndex = model.index(row, 0)
if (treeIndex.row !== modelIndex.row
|| treeIndex.column !== modelIndex.column
|| treeIndex.internalId !== modelIndex.internalId) {
console.log("Test about to fail: row = " + row + ", __listView.count =" + __listView.count)
console.log(" . . . . . . . . . x =" + x + ", getColumn(0).width =" + getColumn(0).width)
}
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
}
}
// Test outside the view content area
modelIndex = model.index(-1,-1)
treeIndex = tree.indexAt(-10, 55)
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
treeIndex = tree.indexAt(-10, tree.getColumn(0).width + 10)
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
treeIndex = tree.indexAt(10, -10)
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
treeIndex = tree.indexAt(10, tree.__listView.contentHeight + 10)
compare(treeIndex.row, modelIndex.row)
compare(treeIndex.column, modelIndex.column)
compare(treeIndex.internalId, modelIndex.internalId)
}
function test_QTBUG_46891_selection_collapse_parent()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
var model = tree.model
model.removeRows(1, 9)
model.removeRows(1, 9, model.index(0, 0))
waitForRendering(tree)
var selectionModel = Qt.createQmlObject(testCase.instance_selectionModel, container, '')
selectionModel.model = tree.model
tree.selection = selectionModel
tree.selectionMode = SelectionMode.ExtendedSelection
var parentItem = tree.model.index(0, 0)
tree.expand(parentItem)
verify(tree.isExpanded(parentItem))
wait(100)
mouseClick(tree, semiIndent + 50, 20 + 100, Qt.LeftButton)
verify(selectionModel.isSelected(tree.currentIndex))
tree.collapse(parentItem)
mouseClick(tree, semiIndent + 50, 20 + 50, Qt.LeftButton)
verify(selectionModel.isSelected(parentItem))
}
function test_QTBUG_53097_currentIndex_on_model_reset()
{
var component = Qt.createComponent("treeview/treeview_1.qml")
compare(component.status, Component.Ready)
var tree = component.createObject(container);
verify(tree !== null, "tree created is null")
tree.headerVisible = false
var model = tree.model
waitForRendering(tree)
/* Select the first row */
verify(!tree.currentIndex.valid)
mouseClick(tree, semiIndent + 50, 20, Qt.LeftButton)
compare(tree.currentIndex.row, 0)
spy.clear()
spy.target = tree
spy.signalName = "currentIndexChanged"
compare(spy.count, 0)
/* delete the row: the currentIndex must be updated */
model.removeRows(0, 1)
compare(spy.count, 1)
}
}
}
|