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 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
|
/****************************************************************************
**
** Copyright (C) 2017 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.12
import QtTest 1.0
import QtQuick.Controls 2.12
TestCase {
id: testCase
width: 200
height: 200
visible: true
when: windowShown
name: "StackView"
Item { id: item }
Component { id: textField; TextField { } }
Component { id: component; Item { } }
Component {
id: stackView
StackView { }
}
Component {
id: signalSpy
SignalSpy { }
}
function test_initialItem() {
var control1 = createTemporaryObject(stackView, testCase)
verify(control1)
compare(control1.currentItem, null)
control1.destroy()
var control2 = createTemporaryObject(stackView, testCase, {initialItem: item})
verify(control2)
compare(control2.currentItem, item)
control2.destroy()
var control3 = createTemporaryObject(stackView, testCase, {initialItem: component})
verify(control3)
verify(control3.currentItem)
control3.destroy()
}
function test_currentItem() {
var control = createTemporaryObject(stackView, testCase, {initialItem: item})
verify(control)
compare(control.currentItem, item)
control.push(component)
verify(control.currentItem !== item)
control.pop(StackView.Immediate)
compare(control.currentItem, item)
}
function test_busy() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
compare(control.busy, false)
var busyCount = 0
var busySpy = signalSpy.createObject(control, {target: control, signalName: "busyChanged"})
verify(busySpy.valid)
control.push(component)
compare(control.busy, false)
compare(busySpy.count, busyCount)
control.push(component)
compare(control.busy, true)
compare(busySpy.count, ++busyCount)
tryCompare(control, "busy", false)
compare(busySpy.count, ++busyCount)
control.replace(component)
compare(control.busy, true)
compare(busySpy.count, ++busyCount)
tryCompare(control, "busy", false)
compare(busySpy.count, ++busyCount)
control.pop()
compare(control.busy, true)
compare(busySpy.count, ++busyCount)
tryCompare(control, "busy", false)
compare(busySpy.count, ++busyCount)
control.pushEnter = null
control.pushExit = null
control.push(component)
compare(control.busy, false)
compare(busySpy.count, busyCount)
control.replaceEnter = null
control.replaceExit = null
control.replace(component)
compare(control.busy, false)
compare(busySpy.count, busyCount)
control.popEnter = null
control.popExit = null
control.pop()
compare(control.busy, false)
compare(busySpy.count, busyCount)
}
function test_status() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = component.createObject(control)
compare(item1.StackView.status, StackView.Inactive)
control.push(item1)
compare(item1.StackView.status, StackView.Active)
var item2 = component.createObject(control)
compare(item2.StackView.status, StackView.Inactive)
control.push(item2)
compare(item2.StackView.status, StackView.Activating)
compare(item1.StackView.status, StackView.Deactivating)
tryCompare(item2.StackView, "status", StackView.Active)
tryCompare(item1.StackView, "status", StackView.Inactive)
control.pop()
compare(item2.StackView.status, StackView.Deactivating)
compare(item1.StackView.status, StackView.Activating)
tryCompare(item2.StackView, "status", StackView.Inactive)
tryCompare(item1.StackView, "status", StackView.Active)
}
function test_index() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = component.createObject(control)
compare(item1.StackView.index, -1)
control.push(item1, StackView.Immediate)
compare(item1.StackView.index, 0)
var item2 = component.createObject(control)
compare(item2.StackView.index, -1)
control.push(item2, StackView.Immediate)
compare(item2.StackView.index, 1)
compare(item1.StackView.index, 0)
control.pop(StackView.Immediate)
compare(item2.StackView.index, -1)
compare(item1.StackView.index, 0)
}
function test_view() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = component.createObject(control)
compare(item1.StackView.view, null)
control.push(item1, StackView.Immediate)
compare(item1.StackView.view, control)
var item2 = component.createObject(control)
compare(item2.StackView.view, null)
control.push(item2, StackView.Immediate)
compare(item2.StackView.view, control)
compare(item1.StackView.view, control)
control.pop(StackView.Immediate)
compare(item2.StackView.view, null)
compare(item1.StackView.view, control)
}
function test_depth() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var depthChanges = 0
var emptyChanges = 0
var depthSpy = signalSpy.createObject(control, {target: control, signalName: "depthChanged"})
var emptySpy = signalSpy.createObject(control, {target: control, signalName: "emptyChanged"})
verify(depthSpy.valid)
verify(emptySpy.valid)
compare(control.depth, 0)
compare(control.empty, true)
control.push(item, StackView.Immediate)
compare(control.depth, 1)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, false)
compare(emptySpy.count, ++emptyChanges)
control.clear()
compare(control.depth, 0)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, true)
compare(emptySpy.count, ++emptyChanges)
control.push(component, StackView.Immediate)
compare(control.depth, 1)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, false)
compare(emptySpy.count, ++emptyChanges)
control.push(component, StackView.Immediate)
compare(control.depth, 2)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, false)
compare(emptySpy.count, emptyChanges)
control.replace(component, StackView.Immediate)
compare(control.depth, 2)
compare(depthSpy.count, depthChanges)
compare(control.empty, false)
compare(emptySpy.count, emptyChanges)
control.replace([component, component], StackView.Immediate)
compare(control.depth, 3)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, false)
compare(emptySpy.count, emptyChanges)
control.pop(null, StackView.Immediate)
compare(control.depth, 1)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, false)
compare(emptySpy.count, emptyChanges)
control.pop(StackView.Immediate) // ignored
compare(control.depth, 1)
compare(depthSpy.count, depthChanges)
compare(control.empty, false)
compare(emptySpy.count, emptyChanges)
control.clear()
compare(control.depth, 0)
compare(depthSpy.count, ++depthChanges)
compare(control.empty, true)
compare(emptySpy.count, ++emptyChanges)
control.clear()
compare(control.depth, 0)
compare(depthSpy.count, depthChanges)
compare(control.empty, true)
compare(emptySpy.count, emptyChanges)
}
function test_size() {
var container = createTemporaryObject(component, testCase, {width: 200, height: 200})
verify(container)
var control = stackView.createObject(container, {width: 100, height: 100})
verify(control)
container.width += 10
container.height += 20
compare(control.width, 100)
compare(control.height, 100)
control.push(item, StackView.Immediate)
compare(item.width, control.width)
compare(item.height, control.height)
control.width = 200
control.height = 200
compare(item.width, control.width)
compare(item.height, control.height)
control.clear()
control.width += 10
control.height += 20
verify(item.width !== control.width)
verify(item.height !== control.height)
control.push(item, StackView.Immediate)
compare(item.width, control.width)
compare(item.height, control.height)
}
function test_focus_data() {
return [
{ tag: "true", focus: true, forceActiveFocus: false },
{ tag: "false", focus: false, forceActiveFocus: false },
{ tag: "forceActiveFocus()", focus: false, forceActiveFocus: true },
]
}
function test_focus(data) {
var control = createTemporaryObject(stackView, testCase, {initialItem: item, width: 200, height: 200})
verify(control)
if (data.focus)
control.focus = true
if (data.forceActiveFocus)
control.forceActiveFocus()
compare(control.activeFocus, data.focus || data.forceActiveFocus)
var page = control.push(textField, StackView.Immediate)
verify(page)
compare(control.currentItem, page)
compare(page.activeFocus, control.activeFocus)
control.pop(StackView.Immediate)
compare(control.currentItem, item)
compare(item.activeFocus, data.focus || data.forceActiveFocus)
verify(!page.activeFocus)
}
function test_find() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = component.createObject(control, {objectName: "1"})
var item2 = component.createObject(control, {objectName: "2"})
var item3 = component.createObject(control, {objectName: "3"})
control.push(item1, StackView.Immediate)
control.push(item2, StackView.Immediate)
control.push(item3, StackView.Immediate)
compare(control.find(function(item, index) { return index === 0 }), item1)
compare(control.find(function(item) { return item.objectName === "1" }), item1)
compare(control.find(function(item, index) { return index === 1 }), item2)
compare(control.find(function(item) { return item.objectName === "2" }), item2)
compare(control.find(function(item, index) { return index === 2 }), item3)
compare(control.find(function(item) { return item.objectName === "3" }), item3)
compare(control.find(function() { return false }), null)
compare(control.find(function() { return true }), item3)
}
function test_get() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
control.push([item, component, component], StackView.Immediate)
verify(control.get(0, StackView.DontLoad))
compare(control.get(0, StackView.ForceLoad), item)
verify(!control.get(1, StackView.DontLoad))
verify(control.get(2, StackView.DontLoad))
verify(control.get(2, StackView.ForceLoad))
}
function test_push() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
// missing arguments
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: missing arguments")
compare(control.push(), null)
// nothing to push
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: nothing to push")
compare(control.push(StackView.Immediate), null)
// unsupported type
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: QtObject is not supported. Must be Item or Component.")
control.push(Qt.createQmlObject('import QtQml 2.0; QtObject { }', control))
// push(item)
var item1 = component.createObject(control, {objectName:"1"})
compare(control.push(item1, StackView.Immediate), item1)
compare(control.depth, 1)
compare(control.currentItem, item1)
// push([item])
var item2 = component.createObject(control, {objectName:"2"})
compare(control.push([item2], StackView.Immediate), item2)
compare(control.depth, 2)
compare(control.currentItem, item2)
// push(item, {properties})
var item3 = component.createObject(control)
compare(control.push(item3, {objectName:"3"}, StackView.Immediate), item3)
compare(item3.objectName, "3")
compare(control.depth, 3)
compare(control.currentItem, item3)
// push([item, {properties}])
var item4 = component.createObject(control)
compare(control.push([item4, {objectName:"4"}], StackView.Immediate), item4)
compare(item4.objectName, "4")
compare(control.depth, 4)
compare(control.currentItem, item4)
// push(component, {properties})
var item5 = control.push(component, {objectName:"5"}, StackView.Immediate)
compare(item5.objectName, "5")
compare(control.depth, 5)
compare(control.currentItem, item5)
// push([component, {properties}])
var item6 = control.push([component, {objectName:"6"}], StackView.Immediate)
compare(item6.objectName, "6")
compare(control.depth, 6)
compare(control.currentItem, item6)
}
function test_pop() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var items = []
for (var i = 0; i < 7; ++i)
items.push(component.createObject(control, {objectName:i}))
control.push(items, StackView.Immediate)
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: pop: too many arguments")
compare(control.pop(1, 2, 3), null)
// pop the top most item
compare(control.pop(StackView.Immediate), items[6])
compare(control.depth, 6)
compare(control.currentItem, items[5])
// pop down to the current item
compare(control.pop(control.currentItem, StackView.Immediate), null)
compare(control.depth, 6)
compare(control.currentItem, items[5])
// pop down to (but not including) the Nth item
compare(control.pop(items[3], StackView.Immediate), items[5])
compare(control.depth, 4)
compare(control.currentItem, items[3])
// pop the top most item
compare(control.pop(undefined, StackView.Immediate), items[3])
compare(control.depth, 3)
compare(control.currentItem, items[2])
// don't pop non-existent item
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: pop: unknown argument: " + testCase)
compare(control.pop(testCase, StackView.Immediate), null)
compare(control.depth, 3)
compare(control.currentItem, items[2])
// pop all items down to (but not including) the 1st item
control.pop(null, StackView.Immediate)
compare(control.depth, 1)
compare(control.currentItem, items[0])
}
function test_replace() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
// missing arguments
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: replace: missing arguments")
compare(control.replace(), null)
// nothing to push
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: replace: nothing to push")
compare(control.replace(StackView.Immediate), null)
// unsupported type
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: replace: QtObject is not supported. Must be Item or Component.")
compare(control.replace(Qt.createQmlObject('import QtQml 2.0; QtObject { }', control)), null)
// replace(item)
var item1 = component.createObject(control, {objectName:"1"})
compare(control.replace(item1, StackView.Immediate), item1)
compare(control.depth, 1)
compare(control.currentItem, item1)
// replace([item])
var item2 = component.createObject(control, {objectName:"2"})
compare(control.replace([item2], StackView.Immediate), item2)
compare(control.depth, 1)
compare(control.currentItem, item2)
// replace(item, {properties})
var item3 = component.createObject(control)
compare(control.replace(item3, {objectName:"3"}, StackView.Immediate), item3)
compare(item3.objectName, "3")
compare(control.depth, 1)
compare(control.currentItem, item3)
// replace([item, {properties}])
var item4 = component.createObject(control)
compare(control.replace([item4, {objectName:"4"}], StackView.Immediate), item4)
compare(item4.objectName, "4")
compare(control.depth, 1)
compare(control.currentItem, item4)
// replace(component, {properties})
var item5 = control.replace(component, {objectName:"5"}, StackView.Immediate)
compare(item5.objectName, "5")
compare(control.depth, 1)
compare(control.currentItem, item5)
// replace([component, {properties}])
var item6 = control.replace([component, {objectName:"6"}], StackView.Immediate)
compare(item6.objectName, "6")
compare(control.depth, 1)
compare(control.currentItem, item6)
// replace the topmost item
control.push(component)
compare(control.depth, 2)
var item7 = control.replace(control.get(1), component, StackView.Immediate)
compare(control.depth, 2)
compare(control.currentItem, item7)
// replace the item in the middle
control.push(component)
control.push(component)
control.push(component)
compare(control.depth, 5)
var item8 = control.replace(control.get(2), component, StackView.Immediate)
compare(control.depth, 3)
compare(control.currentItem, item8)
}
function test_clear() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
control.push(component, StackView.Immediate)
control.clear()
compare(control.depth, 0)
compare(control.busy, false)
control.push(component, StackView.Immediate)
control.clear(StackView.PopTransition)
compare(control.depth, 0)
compare(control.busy, true)
tryCompare(control, "busy", false)
}
function test_visibility_data() {
return [
{tag:"default transitions", properties: {}},
{tag:"null transitions", properties: {pushEnter: null, pushExit: null, popEnter: null, popExit: null}}
]
}
function test_visibility(data) {
var control = createTemporaryObject(stackView, testCase, data.properties)
verify(control)
var item1 = component.createObject(control)
control.push(item1, StackView.Immediate)
verify(item1.visible)
var item2 = component.createObject(control)
control.push(item2)
tryCompare(item1, "visible", false)
verify(item2.visible)
control.pop()
verify(item1.visible)
tryCompare(item2, "visible", false)
}
Component {
id: transitionView
StackView {
property int popEnterRuns
property int popExitRuns
property int pushEnterRuns
property int pushExitRuns
property int replaceEnterRuns
property int replaceExitRuns
popEnter: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++popEnterRuns
}
popExit: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++popExitRuns
}
pushEnter: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++pushEnterRuns
}
pushExit: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++pushExitRuns
}
replaceEnter: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++replaceEnterRuns
}
replaceExit: Transition {
PauseAnimation { duration: 1 }
onRunningChanged: if (!running) ++replaceExitRuns
}
}
}
function test_transitions_data() {
return [
{ tag: "undefined", operation: undefined,
pushEnterRuns: [0,1,1,1], pushExitRuns: [0,1,1,1], replaceEnterRuns: [0,0,1,1], replaceExitRuns: [0,0,1,1], popEnterRuns: [0,0,0,1], popExitRuns: [0,0,0,1] },
{ tag: "immediate", operation: StackView.Immediate,
pushEnterRuns: [0,0,0,0], pushExitRuns: [0,0,0,0], replaceEnterRuns: [0,0,0,0], replaceExitRuns: [0,0,0,0], popEnterRuns: [0,0,0,0], popExitRuns: [0,0,0,0] },
{ tag: "push", operation: StackView.PushTransition,
pushEnterRuns: [1,2,3,4], pushExitRuns: [0,1,2,3], replaceEnterRuns: [0,0,0,0], replaceExitRuns: [0,0,0,0], popEnterRuns: [0,0,0,0], popExitRuns: [0,0,0,0] },
{ tag: "pop", operation: StackView.PopTransition,
pushEnterRuns: [0,0,0,0], pushExitRuns: [0,0,0,0], replaceEnterRuns: [0,0,0,0], replaceExitRuns: [0,0,0,0], popEnterRuns: [1,2,3,4], popExitRuns: [0,1,2,3] },
{ tag: "replace", operation: StackView.ReplaceTransition,
pushEnterRuns: [0,0,0,0], pushExitRuns: [0,0,0,0], replaceEnterRuns: [1,2,3,4], replaceExitRuns: [0,1,2,3], popEnterRuns: [0,0,0,0], popExitRuns: [0,0,0,0] },
]
}
function test_transitions(data) {
var control = createTemporaryObject(transitionView, testCase)
verify(control)
control.push(component, data.operation)
tryCompare(control, "busy", false)
compare(control.pushEnterRuns, data.pushEnterRuns[0])
compare(control.pushExitRuns, data.pushExitRuns[0])
compare(control.replaceEnterRuns, data.replaceEnterRuns[0])
compare(control.replaceExitRuns, data.replaceExitRuns[0])
compare(control.popEnterRuns, data.popEnterRuns[0])
compare(control.popExitRuns, data.popExitRuns[0])
control.push(component, data.operation)
tryCompare(control, "busy", false)
compare(control.pushEnterRuns, data.pushEnterRuns[1])
compare(control.pushExitRuns, data.pushExitRuns[1])
compare(control.replaceEnterRuns, data.replaceEnterRuns[1])
compare(control.replaceExitRuns, data.replaceExitRuns[1])
compare(control.popEnterRuns, data.popEnterRuns[1])
compare(control.popExitRuns, data.popExitRuns[1])
control.replace(component, data.operation)
tryCompare(control, "busy", false)
compare(control.pushEnterRuns, data.pushEnterRuns[2])
compare(control.pushExitRuns, data.pushExitRuns[2])
compare(control.replaceEnterRuns, data.replaceEnterRuns[2])
compare(control.replaceExitRuns, data.replaceExitRuns[2])
compare(control.popEnterRuns, data.popEnterRuns[2])
compare(control.popExitRuns, data.popExitRuns[2])
control.pop(data.operation)
tryCompare(control, "busy", false)
compare(control.pushEnterRuns, data.pushEnterRuns[3])
compare(control.pushExitRuns, data.pushExitRuns[3])
compare(control.replaceEnterRuns, data.replaceEnterRuns[3])
compare(control.replaceExitRuns, data.replaceExitRuns[3])
compare(control.popEnterRuns, data.popEnterRuns[3])
compare(control.popExitRuns, data.popExitRuns[3])
}
TestItem {
id: indestructibleItem
}
Component {
id: destructibleComponent
TestItem { }
}
function test_ownership_data() {
return [
{tag:"item, transition", arg: indestructibleItem, operation: StackView.Transition, destroyed: false},
{tag:"item, immediate", arg: indestructibleItem, operation: StackView.Immediate, destroyed: false},
{tag:"component, transition", arg: destructibleComponent, operation: StackView.Transition, destroyed: true},
{tag:"component, immediate", arg: destructibleComponent, operation: StackView.Immediate, destroyed: true},
{tag:"url, transition", arg: Qt.resolvedUrl("TestItem.qml"), operation: StackView.Transition, destroyed: true},
{tag:"url, immediate", arg: Qt.resolvedUrl("TestItem.qml"), operation: StackView.Immediate, destroyed: true}
]
}
function test_ownership(data) {
var control = createTemporaryObject(transitionView, testCase, {initialItem: component})
verify(control)
// push-pop
control.push(data.arg, StackView.Immediate)
verify(control.currentItem)
verify(control.currentItem.hasOwnProperty("destroyedCallback"))
var destroyed = false
control.currentItem.destroyedCallback = function() { destroyed = true }
control.pop(data.operation)
tryCompare(control, "busy", false)
wait(0) // deferred delete
compare(destroyed, data.destroyed)
// push-replace
control.push(data.arg, StackView.Immediate)
verify(control.currentItem)
verify(control.currentItem.hasOwnProperty("destroyedCallback"))
destroyed = false
control.currentItem.destroyedCallback = function() { destroyed = true }
control.replace(component, data.operation)
tryCompare(control, "busy", false)
wait(0) // deferred delete
compare(destroyed, data.destroyed)
}
Component {
id: removeComponent
Item {
objectName: "removeItem"
StackView.onRemoved: destroy()
}
}
function test_destroyOnRemoved() {
var control = createTemporaryObject(stackView, testCase, { initialItem: component })
verify(control)
var item = removeComponent.createObject(control)
verify(item)
var removedSpy = signalSpy.createObject(control, { target: item.StackView, signalName: "removed" })
verify(removedSpy)
verify(removedSpy.valid)
var destructionSpy = signalSpy.createObject(control, { target: item.Component, signalName: "destruction" })
verify(destructionSpy)
verify(destructionSpy.valid)
// push-pop
control.push(item, StackView.Immediate)
compare(control.currentItem, item)
control.pop(StackView.Transition)
item = null
tryCompare(removedSpy, "count", 1)
tryCompare(destructionSpy, "count", 1)
compare(control.busy, false)
item = removeComponent.createObject(control)
verify(item)
removedSpy.target = item.StackView
verify(removedSpy.valid)
destructionSpy.target = item.Component
verify(destructionSpy.valid)
// push-replace
control.push(item, StackView.Immediate)
compare(control.currentItem, item)
control.replace(component, StackView.Transition)
item = null
tryCompare(removedSpy, "count", 2)
tryCompare(destructionSpy, "count", 2)
compare(control.busy, false)
}
function test_pushOnRemoved() {
var control = createTemporaryObject(stackView, testCase, { initialItem: component })
verify(control)
var item = control.push(component, StackView.Immediate)
verify(item)
item.StackView.onRemoved.connect(function() {
ignoreWarning(/.*QML StackView: cannot push while already in the process of completing a pop/)
control.push(component, StackView.Immediate)
})
// don't crash (QTBUG-62153)
control.pop(StackView.Immediate)
}
Component {
id: attachedItem
Item {
property int index: StackView.index
property StackView view: StackView.view
property int status: StackView.status
}
}
function test_attached() {
var control = createTemporaryObject(stackView, testCase, {initialItem: attachedItem})
compare(control.get(0).index, 0)
compare(control.get(0).view, control)
compare(control.get(0).status, StackView.Active)
control.push(attachedItem, StackView.Immediate)
compare(control.get(0).index, 0)
compare(control.get(0).view, control)
compare(control.get(0).status, StackView.Inactive)
compare(control.get(1).index, 1)
compare(control.get(1).view, control)
compare(control.get(1).status, StackView.Active)
control.pop(StackView.Immediate)
compare(control.get(0).index, 0)
compare(control.get(0).view, control)
compare(control.get(0).status, StackView.Active)
}
Component {
id: testButton
Button {
property int clicks: 0
onClicked: ++clicks
}
}
function test_interaction() {
var control = createTemporaryObject(stackView, testCase, {initialItem: testButton, width: testCase.width, height: testCase.height})
verify(control)
var firstButton = control.currentItem
verify(firstButton)
var firstClicks = 0
var secondClicks = 0
var thirdClicks = 0
// push - default transition
var secondButton = control.push(testButton)
compare(control.busy, true)
mouseClick(firstButton) // filtered while busy
mouseClick(secondButton) // filtered while busy
compare(firstButton.clicks, firstClicks)
compare(secondButton.clicks, secondClicks)
tryCompare(control, "busy", false)
mouseClick(secondButton)
compare(secondButton.clicks, ++secondClicks)
// replace - default transition
var thirdButton = control.replace(testButton)
compare(control.busy, true)
mouseClick(secondButton) // filtered while busy
mouseClick(thirdButton) // filtered while busy
compare(secondButton.clicks, secondClicks)
compare(thirdButton.clicks, thirdClicks)
tryCompare(control, "busy", false)
secondButton = null
secondClicks = 0
mouseClick(thirdButton)
compare(thirdButton.clicks, ++thirdClicks)
// pop - default transition
control.pop()
compare(control.busy, true)
mouseClick(firstButton) // filtered while busy
mouseClick(thirdButton) // filtered while busy
compare(firstButton.clicks, firstClicks)
compare(thirdButton.clicks, thirdClicks)
tryCompare(control, "busy", false)
thirdButton = null
thirdClicks = 0
mouseClick(firstButton)
compare(firstButton.clicks, ++firstClicks)
// push - immediate operation
secondButton = control.push(testButton, StackView.Immediate)
compare(control.busy, false)
mouseClick(secondButton)
compare(secondButton.clicks, ++secondClicks)
// replace - immediate operation
thirdButton = control.replace(testButton, StackView.Immediate)
compare(control.busy, false)
secondButton = null
secondClicks = 0
mouseClick(thirdButton)
compare(thirdButton.clicks, ++thirdClicks)
// pop - immediate operation
control.pop(StackView.Immediate)
compare(control.busy, false)
thirdButton = null
thirdClicks = 0
mouseClick(firstButton)
compare(firstButton.clicks, ++firstClicks)
// push - null transition
control.pushEnter = null
control.pushExit = null
secondButton = control.push(testButton)
compare(control.busy, false)
mouseClick(secondButton)
compare(secondButton.clicks, ++secondClicks)
// replace - null transition
control.replaceEnter = null
control.replaceExit = null
thirdButton = control.replace(testButton)
compare(control.busy, false)
secondButton = null
secondClicks = 0
mouseClick(thirdButton)
compare(thirdButton.clicks, ++thirdClicks)
// pop - null transition
control.popEnter = null
control.popExit = null
control.pop()
compare(control.busy, false)
thirdButton = null
thirdClicks = 0
mouseClick(firstButton)
compare(firstButton.clicks, ++firstClicks)
}
Component {
id: mouseArea
MouseArea {
property int presses: 0
property int releases: 0
property int clicks: 0
property int doubleClicks: 0
property int cancels: 0
onPressed: ++presses
onReleased: ++releases
onClicked: ++clicks
onDoubleClicked: ++doubleClicks
onCanceled: ++cancels
}
}
// QTBUG-50305
function test_events() {
var control = createTemporaryObject(stackView, testCase, {initialItem: mouseArea, width: testCase.width, height: testCase.height})
verify(control)
var testItem = control.currentItem
verify(testItem)
testItem.doubleClicked.connect(function() {
control.push(mouseArea) // ungrab -> cancel
})
mouseDoubleClickSequence(testItem)
compare(testItem.presses, 2)
compare(testItem.releases, 2)
compare(testItem.clicks, 1)
compare(testItem.doubleClicks, 1)
compare(testItem.pressed, false)
compare(testItem.cancels, 0)
}
function test_ungrab() {
var control = createTemporaryObject(stackView, testCase, {initialItem: mouseArea, width: testCase.width, height: testCase.height})
verify(control)
var testItem = control.currentItem
verify(testItem)
mousePress(testItem)
control.push(mouseArea)
tryCompare(control, "busy", false)
mouseRelease(testItem)
compare(testItem.presses, 1)
compare(testItem.releases, 0)
compare(testItem.clicks, 0)
compare(testItem.doubleClicks, 0)
compare(testItem.pressed, false)
compare(testItem.cancels, 1)
}
function test_failures() {
var control = createTemporaryObject(stackView, testCase, {initialItem: component})
verify(control)
var error = Qt.resolvedUrl("non-existent.qml") + ":-1 No such file or directory"
ignoreWarning("QQmlComponent: Component is not ready")
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: " + error)
control.push(Qt.resolvedUrl("non-existent.qml"))
ignoreWarning("QQmlComponent: Component is not ready")
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: replace: " + error)
control.replace(Qt.resolvedUrl("non-existent.qml"))
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: invalid url: x://[v]")
control.push("x://[v]")
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: replace: invalid url: x://[v]")
control.replace("x://[v]")
control.pop()
}
Component {
id: rectangle
Rectangle {
property color initialColor
Component.onCompleted: initialColor = color
}
}
function test_properties() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var rect = control.push(rectangle, {color: "#ff0000"})
compare(rect.color, "#ff0000")
compare(rect.initialColor, "#ff0000")
}
Component {
id: signalTest
Control {
id: ctrl
property SignalSpy activatedSpy: SignalSpy { target: ctrl.StackView; signalName: "activated" }
property SignalSpy activatingSpy: SignalSpy { target: ctrl.StackView; signalName: "activating" }
property SignalSpy deactivatedSpy: SignalSpy { target: ctrl.StackView; signalName: "deactivated" }
property SignalSpy deactivatingSpy: SignalSpy { target: ctrl.StackView; signalName: "deactivating" }
}
}
function test_signals() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = signalTest.createObject(control)
compare(item1.StackView.status, StackView.Inactive)
control.push(item1)
compare(item1.StackView.status, StackView.Active)
compare(item1.activatedSpy.count, 1)
compare(item1.activatingSpy.count, 1)
compare(item1.deactivatedSpy.count, 0)
compare(item1.deactivatingSpy.count, 0)
var item2 = signalTest.createObject(control)
compare(item2.StackView.status, StackView.Inactive)
control.push(item2)
compare(item2.StackView.status, StackView.Activating)
compare(item2.activatedSpy.count, 0)
compare(item2.activatingSpy.count, 1)
compare(item2.deactivatedSpy.count, 0)
compare(item2.deactivatingSpy.count, 0)
compare(item1.StackView.status, StackView.Deactivating)
compare(item1.activatedSpy.count, 1)
compare(item1.activatingSpy.count, 1)
compare(item1.deactivatedSpy.count, 0)
compare(item1.deactivatingSpy.count, 1)
tryCompare(item2.activatedSpy, "count", 1)
tryCompare(item1.deactivatedSpy, "count", 1)
control.pop()
compare(item2.StackView.status, StackView.Deactivating)
compare(item2.activatedSpy.count, 1)
compare(item2.activatingSpy.count, 1)
compare(item2.deactivatedSpy.count, 0)
compare(item2.deactivatingSpy.count, 1)
compare(item1.StackView.status, StackView.Activating)
compare(item1.activatedSpy.count, 1)
compare(item1.activatingSpy.count, 2)
compare(item1.deactivatedSpy.count, 1)
compare(item1.deactivatingSpy.count, 1)
tryCompare(item1.activatedSpy, "count", 2)
}
// QTBUG-56158
function test_repeatedPop() {
var control = createTemporaryObject(stackView, testCase, {initialItem: component, width: testCase.width, height: testCase.height})
verify(control)
for (var i = 0; i < 12; ++i)
control.push(component)
tryCompare(control, "busy", false)
while (control.depth > 1) {
control.pop()
wait(50)
}
tryCompare(control, "busy", false)
}
function test_pushSameItem() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
control.push(item, StackView.Immediate)
compare(control.currentItem, item)
compare(control.depth, 1)
// Pushing the same Item should do nothing.
ignoreWarning(Qt.resolvedUrl("tst_stackview.qml") + ":69:9: QML StackView: push: nothing to push")
control.push(item, StackView.Immediate)
compare(control.currentItem, item)
compare(control.depth, 1)
// Push a component so that it becomes current.
var current = control.push(component, StackView.Immediate)
compare(control.currentItem, current)
compare(control.depth, 2)
// Push a bunch of stuff. "item" is already in the stack, so it should be ignored.
current = control.push(component, item, StackView.Immediate)
verify(current !== item)
compare(control.currentItem, current)
compare(control.depth, 3)
}
function test_visible() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item1 = component.createObject(control)
control.push(item1, StackView.Immediate)
compare(item1.visible, true)
compare(item1.StackView.visible, item1.visible)
var item2 = component.createObject(control)
control.push(item2, StackView.Immediate)
compare(item1.visible, false)
compare(item2.visible, true)
compare(item1.StackView.visible, false)
compare(item2.StackView.visible, true)
// keep explicitly visible
item2.StackView.visible = true
control.push(component, StackView.Immediate)
compare(item2.visible, true)
compare(item2.StackView.visible, true)
// show underneath
item1.StackView.visible = true
compare(item1.visible, true)
compare(item1.StackView.visible, true)
control.pop(StackView.Immediate)
compare(item2.visible, true)
compare(item2.StackView.visible, true)
// hide the top-most
item2.StackView.visible = false
compare(item2.visible, false)
compare(item2.StackView.visible, false)
// reset the top-most
item2.StackView.visible = undefined
compare(item2.visible, true)
compare(item2.StackView.visible, true)
// reset underneath
item1.StackView.visible = undefined
compare(item1.visible, false)
compare(item1.StackView.visible, false)
control.pop(StackView.Immediate)
compare(item1.visible, true)
compare(item1.StackView.visible, true)
}
function test_resolveInitialItem() {
var control = createTemporaryObject(stackView, testCase, {initialItem: "TestItem.qml"})
verify(control)
verify(control.currentItem)
}
function test_resolve() {
var control = createTemporaryObject(stackView, testCase)
verify(control)
var item = control.push("TestItem.qml")
compare(control.depth, 1)
verify(item)
}
// QTBUG-65084
function test_mouseArea() {
var ma = createTemporaryObject(mouseArea, testCase, {width: testCase.width, height: testCase.height})
verify(ma)
var control = stackView.createObject(ma, {width: testCase.width, height: testCase.height})
verify(control)
mousePress(control)
verify(ma.pressed)
mouseRelease(control)
verify(!ma.pressed)
var touch = touchEvent(control)
touch.press(0, control).commit()
verify(ma.pressed)
touch.release(0, control).commit()
verify(!ma.pressed)
}
// Separate function to ensure that the temporary value created to hold the return value of the Qt.createComponent()
// call is out of scope when the caller calls gc().
function stackViewFactory()
{
return createTemporaryObject(stackView, testCase, {initialItem: Qt.createComponent("TestItem.qml")})
}
function test_initalItemOwnership()
{
var control = stackViewFactory()
verify(control)
gc()
verify(control.initialItem)
}
// Need to use this specific structure in order to reproduce the crash.
Component {
id: clearUponDestructionContainerComponent
Item {
id: container
objectName: "container"
property alias control: stackView
property var onDestructionCallback
property Component clearUponDestructionComponent: Component {
id: clearUponDestructionComponent
Item {
objectName: "clearUponDestructionItem"
Component.onDestruction: container.onDestructionCallback(stackView)
}
}
StackView {
id: stackView
initialItem: Item {
objectName: "initialItem"
}
}
}
}
// QTBUG-80353
// Tests that calling clear() in Component.onDestruction in response to that
// item being removed (e.g. via an earlier call to clear()) results in a warning and not a crash.
function test_recursiveClearClear() {
let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
{ onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
verify(container)
let control = container.control
control.push(container.clearUponDestructionComponent, StackView.Immediate)
// Shouldn't crash.
ignoreWarning(/.*cannot clear while already in the process of completing a clear/)
control.clear(StackView.Immediate)
}
function test_recursivePopClear() {
let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
{ onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
verify(container)
let control = container.control
control.push(container.clearUponDestructionComponent, StackView.Immediate)
// Pop all items except the first, removing the second item we pushed in the process.
// Shouldn't crash.
ignoreWarning(/.*cannot clear while already in the process of completing a pop/)
control.pop(null, StackView.Immediate)
}
function test_recursivePopPop() {
let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
{ onDestructionCallback: function(stackView) { stackView.pop(null, StackView.Immediate) }})
verify(container)
let control = container.control
// Push an extra item so that we can call pop(null) and reproduce the conditions for the crash.
control.push(component, StackView.Immediate)
control.push(container.clearUponDestructionComponent, StackView.Immediate)
// Pop the top item, then pop down to the first item in response.
ignoreWarning(/.*cannot pop while already in the process of completing a pop/)
control.pop(StackView.Immediate)
}
function test_recursiveReplaceClear() {
let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
{ onDestructionCallback: function(stackView) { stackView.clear(StackView.Immediate) }})
verify(container)
let control = container.control
control.push(container.clearUponDestructionComponent, StackView.Immediate)
// Replace the top item, then clear in response.
ignoreWarning(/.*cannot clear while already in the process of completing a replace/)
control.replace(component, StackView.Immediate)
}
function test_recursiveClearReplace() {
let container = createTemporaryObject(clearUponDestructionContainerComponent, testCase,
{ onDestructionCallback: function(stackView) { stackView.replace(component, StackView.Immediate) }})
verify(container)
let control = container.control
control.push(container.clearUponDestructionComponent, StackView.Immediate)
// Replace the top item, then clear in response.
ignoreWarning(/.*cannot replace while already in the process of completing a clear/)
control.clear(StackView.Immediate)
}
Component {
id: rectangleComponent
Rectangle {}
}
Component {
id: qtbug57267_StackViewComponent
StackView {
id: stackView
popEnter: Transition {
XAnimator { from: (stackView.mirrored ? -1 : 1) * -stackView.width; to: 0; duration: 400; easing.type: Easing.Linear }
}
popExit: Transition {
XAnimator { from: 0; to: (stackView.mirrored ? -1 : 1) * stackView.width; duration: 400; easing.type: Easing.Linear }
}
pushEnter: Transition {
XAnimator { from: (stackView.mirrored ? -1 : 1) * stackView.width; to: 0; duration: 400; easing.type: Easing.Linear }
}
pushExit: Transition {
XAnimator { from: 0; to: (stackView.mirrored ? -1 : 1) * -stackView.width; duration: 400; easing.type: Easing.Linear }
}
replaceEnter: Transition {
XAnimator { from: (stackView.mirrored ? -1 : 1) * stackView.width; to: 0; duration: 400; easing.type: Easing.Linear }
}
replaceExit: Transition {
XAnimator { from: 0; to: (stackView.mirrored ? -1 : 1) * -stackView.width; duration: 400; easing.type: Easing.Linear }
}
}
}
function test_qtbug57267() {
let redRect = createTemporaryObject(rectangleComponent, testCase, { color: "red" })
verify(redRect)
let blueRect = createTemporaryObject(rectangleComponent, testCase, { color: "blue" })
verify(blueRect)
let control = createTemporaryObject(qtbug57267_StackViewComponent, testCase,
{ "anchors.fill": testCase, initialItem: redRect })
verify(control)
control.replace(blueRect)
compare(control.currentItem, blueRect)
compare(control.depth, 1)
// Wait until the animation has started and then interrupt it by pushing the redRect.
tryCompare(control, "busy", true)
control.replace(redRect)
// The blue rect shouldn't be visible since we replaced it and therefore interrupted its animation.
tryCompare(blueRect, "visible", false)
// We did the replace very early on, so the transition for the redRect should still be happening.
compare(control.busy, true)
compare(redRect.visible, true)
// After finishing the transition, the red rect should still be visible.
tryCompare(control, "busy", false)
compare(redRect.visible, true)
}
// QTBUG-84381
function test_clearAndPushAfterDepthChange() {
var control = createTemporaryObject(stackView, testCase, {
popEnter: null, popExit: null, pushEnter: null,
pushExit: null, replaceEnter: null, replaceExit: null
})
verify(control)
control.depthChanged.connect(function() {
if (control.depth === 2) {
// Shouldn't assert.
ignoreWarning(/.*QML StackView: cannot clear while already in the process of completing a push/)
control.clear()
// Shouldn't crash.
ignoreWarning(/.*QML StackView: cannot push while already in the process of completing a push/)
control.push(component)
}
})
control.push(component)
control.push(component)
}
}
|