aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/controls/data/tst_swipedelegate.qml
diff options
context:
space:
mode:
Diffstat (limited to 'tests/auto/controls/data/tst_swipedelegate.qml')
-rw-r--r--tests/auto/controls/data/tst_swipedelegate.qml265
1 files changed, 237 insertions, 28 deletions
diff --git a/tests/auto/controls/data/tst_swipedelegate.qml b/tests/auto/controls/data/tst_swipedelegate.qml
index 21bb1a37..bcf25f28 100644
--- a/tests/auto/controls/data/tst_swipedelegate.qml
+++ b/tests/auto/controls/data/tst_swipedelegate.qml
@@ -40,7 +40,8 @@
import QtQuick 2.6
import QtTest 1.0
-import QtQuick.Controls 2.0
+import QtQuick.Layouts 1.1
+import QtQuick.Controls 2.1
TestCase {
id: testCase
@@ -110,14 +111,14 @@ TestCase {
function test_horizontalAnchors_data() {
return [
- { tag: "background, fill", component: backgroundFillComponent, itemName: "background", warningLocation: ":58:25" },
- { tag: "background, centerIn", component: backgroundCenterInComponent, itemName: "background", warningLocation: ":65:25" },
- { tag: "background, left", component: backgroundLeftComponent, itemName: "background", warningLocation: ":72:25" },
- { tag: "background, right", component: backgroundRightComponent, itemName: "background", warningLocation: ":79:25" },
- { tag: "contentItem, fill", component: contentItemFillComponent, itemName: "contentItem", warningLocation: ":86:26" },
- { tag: "contentItem, centerIn", component: contentItemCenterInComponent, itemName: "contentItem", warningLocation: ":93:26" },
- { tag: "contentItem, left", component: contentItemLeftComponent, itemName: "contentItem", warningLocation: ":100:26" },
- { tag: "contentItem, right", component: contentItemRightComponent, itemName: "contentItem", warningLocation: ":107:26" }
+ { tag: "background, fill", component: backgroundFillComponent, itemName: "background", warningLocation: ":59:25" },
+ { tag: "background, centerIn", component: backgroundCenterInComponent, itemName: "background", warningLocation: ":66:25" },
+ { tag: "background, left", component: backgroundLeftComponent, itemName: "background", warningLocation: ":73:25" },
+ { tag: "background, right", component: backgroundRightComponent, itemName: "background", warningLocation: ":80:25" },
+ { tag: "contentItem, fill", component: contentItemFillComponent, itemName: "contentItem", warningLocation: ":87:26" },
+ { tag: "contentItem, centerIn", component: contentItemCenterInComponent, itemName: "contentItem", warningLocation: ":94:26" },
+ { tag: "contentItem, left", component: contentItemLeftComponent, itemName: "contentItem", warningLocation: ":101:26" },
+ { tag: "contentItem, right", component: contentItemRightComponent, itemName: "contentItem", warningLocation: ":108:26" }
];
}
@@ -166,6 +167,12 @@ TestCase {
}
Component {
+ id: signalSpyComponent
+
+ SignalSpy {}
+ }
+
+ Component {
id: itemComponent
Item {}
@@ -201,7 +208,7 @@ TestCase {
verify(control);
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: cannot set both behind and left/right properties")
+ ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties")
control.swipe.behind = itemComponent;
// Shouldn't be any warnings when unsetting delegates.
@@ -210,7 +217,7 @@ TestCase {
// right is still set.
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: cannot set both behind and left/right properties")
+ ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties")
control.swipe.behind = itemComponent;
control.swipe.right = null;
@@ -219,11 +226,11 @@ TestCase {
control.swipe.behind = itemComponent;
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: cannot set both behind and left/right properties")
+ ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties")
control.swipe.left = itemComponent;
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: cannot set both behind and left/right properties")
+ ":160:9: QML SwipeDelegate: cannot set both behind and left/right properties")
control.swipe.right = itemComponent;
control.swipe.behind = null;
@@ -238,7 +245,7 @@ TestCase {
var oldLeft = control.swipe.left;
var oldLeftItem = control.swipe.leftItem;
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
+ ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
control.swipe.left = null;
compare(control.swipe.left, oldLeft);
compare(control.swipe.leftItem, oldLeftItem);
@@ -249,7 +256,7 @@ TestCase {
var oldRight = control.swipe.right;
var oldRightItem = control.swipe.rightItem;
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
+ ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
control.swipe.right = null;
compare(control.swipe.right, oldRight);
compare(control.swipe.rightItem, oldRightItem);
@@ -275,7 +282,7 @@ TestCase {
var oldBehind = control.swipe.behind;
var oldBehindItem = control.swipe.behindItem;
ignoreWarning(Qt.resolvedUrl("tst_swipedelegate.qml") +
- ":159:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
+ ":160:9: QML SwipeDelegate: left/right/behind properties may only be set when swipe.position is 0")
control.swipe.behind = null;
compare(control.swipe.behind, oldBehind);
compare(control.swipe.behindItem, oldBehindItem);
@@ -297,7 +304,7 @@ TestCase {
SignalSequenceSpy {
id: mouseSignalSequenceSpy
- signals: ["pressed", "released", "canceled", "clicked", "doubleClicked", "pressedChanged"]
+ signals: ["pressed", "released", "canceled", "clicked", "doubleClicked", "pressedChanged", "pressAndHold"]
}
function test_swipe() {
@@ -306,12 +313,17 @@ TestCase {
var overDragDistance = Math.round(dragDistance * 1.1);
+ var completedSpy = signalSpyComponent.createObject(control, { target: control.swipe, signalName: "completed" });
+ verify(completedSpy);
+ verify(completedSpy.valid);
+
mouseSignalSequenceSpy.target = control;
mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": true }], "pressed"];
mousePress(control, control.width / 2, control.height / 2);
verify(control.pressed);
compare(control.swipe.position, 0.0);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 0);
verify(mouseSignalSequenceSpy.success);
verify(!control.swipe.leftItem);
verify(!control.swipe.rightItem);
@@ -321,6 +333,7 @@ TestCase {
verify(control.pressed);
compare(control.swipe.position, overDragDistance / control.width);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 0);
verify(control.swipe.leftItem);
verify(control.swipe.leftItem.visible);
compare(control.swipe.leftItem.parent, control);
@@ -332,6 +345,7 @@ TestCase {
verify(control.pressed);
compare(control.swipe.position, 0.0);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 0);
verify(control.swipe.leftItem);
verify(control.swipe.leftItem.visible);
compare(control.swipe.leftItem.parent, control);
@@ -344,6 +358,7 @@ TestCase {
verify(control.pressed);
compare(control.swipe.position, -overDragDistance / control.width);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 0);
verify(control.swipe.leftItem);
verify(!control.swipe.leftItem.visible);
verify(control.swipe.rightItem);
@@ -356,6 +371,7 @@ TestCase {
verify(control.pressed);
compare(control.swipe.position, 0.6);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 0);
verify(control.swipe.leftItem);
verify(control.swipe.leftItem.visible);
verify(control.swipe.rightItem);
@@ -366,6 +382,7 @@ TestCase {
verify(!control.pressed);
compare(control.swipe.position, 1.0);
verify(control.swipe.complete);
+ compare(completedSpy.count, 1);
verify(mouseSignalSequenceSpy.success);
verify(control.swipe.leftItem);
verify(control.swipe.leftItem.visible);
@@ -381,11 +398,13 @@ TestCase {
// complete should still be true, because we haven't moved yet, and hence
// haven't started grabbing behind's mouse events.
verify(control.swipe.complete);
+ compare(completedSpy.count, 1);
verify(mouseSignalSequenceSpy.success);
mouseMove(control, control.width / 2 - overDragDistance, control.height / 2);
verify(control.pressed);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 1);
compare(control.swipe.position, 1.0 - overDragDistance / control.width);
mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "released", "clicked"];
@@ -393,6 +412,7 @@ TestCase {
verify(!control.pressed);
compare(control.swipe.position, 1.0);
verify(control.swipe.complete);
+ compare(completedSpy.count, 2);
verify(mouseSignalSequenceSpy.success);
tryCompare(control.contentItem, "x", control.width + control.leftPadding);
@@ -402,11 +422,13 @@ TestCase {
verify(control.pressed);
compare(control.swipe.position, 1.0);
verify(control.swipe.complete);
+ compare(completedSpy.count, 2);
verify(mouseSignalSequenceSpy.success);
mouseMove(control, control.width * -0.1, control.height / 2);
verify(control.pressed);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 2);
compare(control.swipe.position, 0.4);
mouseSignalSequenceSpy.expectedSequence = [["pressedChanged", { "pressed": false }], "released", "clicked"];
@@ -414,6 +436,7 @@ TestCase {
verify(!control.pressed);
compare(control.swipe.position, 0.0);
verify(!control.swipe.complete);
+ compare(completedSpy.count, 2);
verify(mouseSignalSequenceSpy.success);
tryCompare(control.contentItem, "x", control.leftPadding);
@@ -507,12 +530,6 @@ TestCase {
}
}
- Component {
- id: signalSpyComponent
-
- SignalSpy {}
- }
-
function test_eventsToLeftAndRight() {
var control = swipeDelegateWithButtonComponent.createObject(testCase);
verify(control);
@@ -607,6 +624,26 @@ TestCase {
mouseDoubleClickSequence(control, control.width / 2, control.height / 2, Qt.LeftButton);
verify(mouseSignalSequenceSpy.success);
+ // press and hold
+ var pressAndHoldSpy = signalSpyComponent.createObject(control, { target: control, signalName: "pressAndHold" });
+ verify(pressAndHoldSpy);
+ verify(pressAndHoldSpy.valid);
+
+ mouseSignalSequenceSpy.expectedSequence = [
+ ["pressedChanged", { "pressed": true }],
+ "pressed",
+ "pressAndHold",
+ ["pressedChanged", { "pressed": false }],
+ "released"
+ ];
+ mousePress(control);
+ compare(control.pressed, true);
+ tryCompare(pressAndHoldSpy, "count", 1);
+
+ mouseRelease(control);
+ compare(control.pressed, false);
+ verify(mouseSignalSequenceSpy.success);
+
control.destroy();
}
@@ -629,8 +666,6 @@ TestCase {
text: modelData
width: listView.width
- onClicked: if (swipe.complete) ListView.view.model.remove(index)
-
property alias removeAnimation: onRemoveAnimation
ListView.onRemove: SequentialAnimation {
@@ -655,9 +690,12 @@ TestCase {
}
swipe.left: Rectangle {
- color: rootDelegate.swipe.complete && rootDelegate.pressed ? "#333" : "#444"
+ objectName: "rectangle"
+ color: SwipeDelegate.pressed ? "#333" : "#444"
anchors.fill: parent
+ SwipeDelegate.onClicked: listView.model.remove(index)
+
Label {
objectName: "label"
text: "Remove"
@@ -680,11 +718,14 @@ TestCase {
verify(firstItem.pressed);
compare(firstItem.swipe.position, 0.0);
verify(!firstItem.swipe.complete);
+ verify(!firstItem.swipe.leftItem);
mouseMove(listView, firstItem.width * 1.1, firstItem.height / 2);
verify(firstItem.pressed);
compare(firstItem.swipe.position, 0.6);
verify(!firstItem.swipe.complete);
+ verify(firstItem.swipe.leftItem);
+ verify(!firstItem.swipe.leftItem.SwipeDelegate.pressed);
mouseRelease(listView, firstItem.width / 2, firstItem.height / 2);
verify(!firstItem.pressed);
@@ -695,9 +736,23 @@ TestCase {
// Wait for it to settle down.
tryCompare(firstItem.contentItem, "x", firstItem.leftPadding + firstItem.width);
- // Click the button to remove the item.
+ var leftClickedSpy = signalSpyComponent.createObject(firstItem.swipe.leftItem,
+ { target: firstItem.swipe.leftItem.SwipeDelegate, signalName: "clicked" });
+ verify(leftClickedSpy);
+ verify(leftClickedSpy.valid);
+
+ // Click the left item to remove the delegate from the list.
var contentItemX = firstItem.contentItem.x;
- mouseClick(listView, firstItem.width / 2, firstItem.height / 2);
+ mousePress(listView, firstItem.width / 2, firstItem.height / 2);
+ verify(firstItem.swipe.leftItem.SwipeDelegate.pressed);
+ compare(leftClickedSpy.count, 0);
+ verify(!firstItem.pressed);
+
+ mouseRelease(listView, firstItem.width / 2, firstItem.height / 2);
+ verify(!firstItem.swipe.leftItem.SwipeDelegate.pressed);
+ compare(leftClickedSpy.count, 1);
+ verify(!firstItem.pressed);
+ leftClickedSpy = null;
tryCompare(firstItem.removeAnimation, "running", true);
// There was a bug where the resizeContent() would be called because the height
// of the control was changing due to the animation. contentItem would then
@@ -992,6 +1047,160 @@ TestCase {
control.destroy();
}
+ Component {
+ id: closeSwipeDelegateComponent
+
+ SwipeDelegate {
+ text: "SwipeDelegate"
+ width: 150
+
+ onClicked: close()
+
+ swipe.right: Item {
+ width: parent.width
+ height: parent.height
+ }
+ }
+ }
+
+ function test_close() {
+ var control = swipeDelegateComponent.createObject(testCase);
+ verify(control);
+
+ swipe(control, 0.0, -1.0);
+ compare(control.swipe.rightItem.visible, true);
+ // Should animate, so it shouldn't change right away.
+ compare(control.swipe.rightItem.x, 0);
+ tryCompare(control.swipe.rightItem, "x", control.background.x + control.background.width);
+
+ control.destroy();
+ }
+
+ Component {
+ id: multiActionSwipeDelegateComponent
+
+ SwipeDelegate {
+ text: "SwipeDelegate"
+ width: 150
+
+ swipe.right: Item {
+ objectName: "rightItemRoot"
+ width: parent.width
+ height: parent.height
+
+ property alias firstAction: firstAction
+ property alias secondAction: secondAction
+
+ property int firstClickCount: 0
+ property int secondClickCount: 0
+
+ RowLayout {
+ anchors.fill: parent
+ anchors.margins: 5
+
+ Rectangle {
+ id: firstAction
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ color: "tomato"
+
+ SwipeDelegate.onClicked: ++firstClickCount
+ }
+ Rectangle {
+ id: secondAction
+ Layout.fillWidth: true
+ Layout.fillHeight: true
+ color: "navajowhite"
+
+ SwipeDelegate.onClicked: ++secondClickCount
+ }
+ }
+ }
+ }
+ }
+
+ // Tests that it's possible to have multiple non-interactive items in one delegate
+ // (e.g. left/right/behind) that can each receive clicks.
+ function test_multipleClickableActions() {
+ var control = multiActionSwipeDelegateComponent.createObject(testCase);
+ verify(control);
+
+ swipe(control, 0.0, -1.0);
+ verify(control.swipe.rightItem);
+ tryCompare(control.swipe, "complete", true);
+
+ var firstClickedSpy = signalSpyComponent.createObject(control,
+ { target: control.swipe.rightItem.firstAction.SwipeDelegate, signalName: "clicked" });
+ verify(firstClickedSpy);
+ verify(firstClickedSpy.valid);
+
+ // Clicked within rightItem, but not within an item using the attached properties.
+ mousePress(control, 2, 2);
+ compare(control.swipe.rightItem.firstAction.SwipeDelegate.pressed, false);
+ compare(firstClickedSpy.count, 0);
+
+ mouseRelease(control, 2, 2);
+ compare(control.swipe.rightItem.firstAction.SwipeDelegate.pressed, false);
+ compare(firstClickedSpy.count, 0);
+
+ // Click within the first item.
+ mousePress(control.swipe.rightItem.firstAction, 0, 0);
+ compare(control.swipe.rightItem.firstAction.SwipeDelegate.pressed, true);
+ compare(firstClickedSpy.count, 0);
+
+ mouseRelease(control.swipe.rightItem.firstAction, 0, 0);
+ compare(control.swipe.rightItem.firstAction.SwipeDelegate.pressed, false);
+ compare(firstClickedSpy.count, 1);
+ compare(control.swipe.rightItem.firstClickCount, 1);
+
+ var secondClickedSpy = signalSpyComponent.createObject(control,
+ { target: control.swipe.rightItem.secondAction.SwipeDelegate, signalName: "clicked" });
+ verify(secondClickedSpy);
+ verify(secondClickedSpy.valid);
+
+ // Click within the second item.
+ mousePress(control.swipe.rightItem.secondAction, 0, 0);
+ compare(control.swipe.rightItem.secondAction.SwipeDelegate.pressed, true);
+ compare(secondClickedSpy.count, 0);
+
+ mouseRelease(control.swipe.rightItem.secondAction, 0, 0);
+ compare(control.swipe.rightItem.secondAction.SwipeDelegate.pressed, false);
+ compare(secondClickedSpy.count, 1);
+ compare(control.swipe.rightItem.secondClickCount, 1);
+
+ control.destroy();
+ }
+
+ // Pressing on a "side action" and then dragging should eventually
+ // cause the ListView to grab the mouse and start changing its contentY.
+ // When this happens, it will grab the mouse and hence we must clear
+ // that action's pressed state so that it doesn't stay pressed after releasing.
+ function test_dragSideAction() {
+ var listView = removableDelegatesComponent.createObject(testCase);
+ verify(listView);
+
+ var control = listView.itemAt(0, 0);
+ verify(control);
+
+ // Expose the side action.
+ swipe(control, 0.0, 1.0);
+ verify(control.swipe.leftItem);
+ tryCompare(control.swipe, "complete", true);
+
+ var pressedSpy = signalSpyComponent.createObject(control,
+ { target: control.swipe.leftItem.SwipeDelegate, signalName: "pressedChanged" });
+ verify(pressedSpy);
+ verify(pressedSpy.valid);
+
+ mouseDrag(listView, 20, 20, 0, listView.height);
+ compare(pressedSpy.count, 2);
+ verify(listView.contentY !== 0);
+
+ compare(control.swipe.leftItem.SwipeDelegate.pressed, false);
+
+ listView.destroy();
+ }
+
// When the width of a SwipeDelegate changes (as it does upon portrait => landscape
// rotation, for example), the positions of the contentItem and background items
// should be updated accordingly.