diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2016-11-10 13:03:28 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2016-11-10 12:53:51 +0000 |
commit | 48731e5c2eee6d6f6e8029f82195e3209e01d066 (patch) | |
tree | a9c43fd46b3358665c7c96a877d65fc920f693d1 /tests | |
parent | 80ef46b3b2c234832be4280ea7025083fd4f632a (diff) |
Dialog: emit rejected() when closed interactively
This is what QDialog does, for example.
This allows applications to perform some actions
that must be done when the dialog is closed. For example,
clearing any unsaved changes in a shortcut editor dialog.
[ChangeLog][Controls][Dialog] Dialog now emits rejected()
when closed interactively.
Task-number: QTBUG-56928
Change-Id: Iad4e2fe984323d0b9fdfd17ee3746043b5eaf849
Reviewed-by: J-P Nurmi <jpnurmi@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_dialog.qml | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_dialog.qml b/tests/auto/controls/data/tst_dialog.qml index 69c47fed..4cfda8ee 100644 --- a/tests/auto/controls/data/tst_dialog.qml +++ b/tests/auto/controls/data/tst_dialog.qml @@ -106,6 +106,50 @@ TestCase { tryCompare(control, "visible", false) + // Check that rejected() is emitted when CloseOnEscape is triggered. + control.x = 10 + control.y = 10 + control.width = 100 + control.height = 100 + control.closePolicy = Popup.CloseOnEscape + control.open() + verify(control.visible) + + keyPress(Qt.Key_Escape) + compare(rejectedSpy.count, 2) + tryCompare(control, "visible", false) + + keyRelease(Qt.Key_Escape) + compare(rejectedSpy.count, 2) + + // Check that rejected() is emitted when CloseOnPressOutside is triggered. + control.closePolicy = Popup.CloseOnPressOutside + control.open() + verify(control.visible) + + mousePress(testCase, 1, 1) + compare(rejectedSpy.count, 3) + tryCompare(control, "visible", false) + + mouseRelease(testCase, 1, 1) + compare(rejectedSpy.count, 3) + + // Check that rejected() is emitted when CloseOnReleaseOutside is triggered. + // For this, we need to make the dialog modal, because the overlay won't accept + // the press event because it doesn't want to block the press. + control.modal = true + control.closePolicy = Popup.CloseOnReleaseOutside + control.open() + verify(control.visible) + + mousePress(testCase, 1, 1) + compare(rejectedSpy.count, 3) + verify(control.visible) + + mouseRelease(testCase, 1, 1) + compare(rejectedSpy.count, 4) + tryCompare(control, "visible", false) + control.destroy() } |