diff options
author | Mitch Curtis <mitch.curtis@qt.io> | 2018-12-04 15:44:00 +0100 |
---|---|---|
committer | Mitch Curtis <mitch.curtis@qt.io> | 2019-01-08 13:15:09 +0000 |
commit | 9c7429219d36e8eb40e1fe6e679715c89209fc40 (patch) | |
tree | d5a4999c774adf49f724886995ad05e3387caa7d /tests/auto | |
parent | ce9940ca550d70931248a98fc4d47f10959a9a9e (diff) |
SplitView: schedule another layout if requested sizes changed during layout
As mentioned in the review of ed87e837, there could be a scenario where the
user sets the preferred size of an item inside the onWidthChanged handler
of another item:
onWidthChanged: if (width < 10) secondItem.SplitView.preferredWidth = 100
Before this patch, this would result in the preferredWidth assignment being
ignored since it happened during a layout.
This patch adds some auto tests to ensure that this works, as the previous
patch (that converted layouts to be done in polish/updatePolish cycles)
already fixed the issue.
It also adds a check to avoid doing too many layouts in the case of
one of the split handles being dragged.
Change-Id: Ide519b33a2fa3bf746ae3793e0671fd1750c70d8
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/controls/data/tst_splitview.qml | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_splitview.qml b/tests/auto/controls/data/tst_splitview.qml index 40e7dda0..28c00179 100644 --- a/tests/auto/controls/data/tst_splitview.qml +++ b/tests/auto/controls/data/tst_splitview.qml @@ -1847,4 +1847,77 @@ TestCase { control.restoreState(settings.value("splitView")) compare(lastItem.SplitView.preferredWidth, 123) } + + function test_changePreferredSizeDuringLayout() { + var control = createTemporaryObject(threeSizedItemsComponent, testCase) + verify(control) + + var firstItem = control.itemAt(0) + var secondItem = control.itemAt(1) + secondItem.widthChanged.connect(function() { + if (secondItem.width < 10) + firstItem.SplitView.preferredWidth = 50 + }) + + // Change the size of the item so that a layout happens, but + // make the size small enough that the item's onWidthChanged handler gets triggered. + // The onWidthChanged handler will set the preferredWidth of another item during the + // layout, so we need to make sure the assignment isn't lost since we return early in that case. + secondItem.implicitWidth = 5 + verify(isPolishScheduled(control)) + verify(waitForItemPolished(control)) + compare(secondItem.width, 5) + compare(firstItem.width, 50) + + // Now do the same for height. + control.orientation = Qt.Vertical + secondItem.heightChanged.connect(function() { + if (secondItem.height < 10) + firstItem.SplitView.preferredHeight = 50 + }) + // Get the polishes for the orientation out of the way so that they + // don't intefere with our results. + verify(isPolishScheduled(control)) + verify(waitForItemPolished(control)) + + secondItem.implicitHeight = 5 + verify(isPolishScheduled(control)) + verify(waitForItemPolished(control)) + compare(secondItem.height, 5) + compare(firstItem.height, 50) + } + + // When the user drags a handle, we internally set preferredWidth/Height + // to reflect the new value. However, we also have to make sure that when + // we do so, it doesn't trigger a delayed layout. This is why we have + // m_ignoreNextDelayedLayoutRequest. This test checks that + // m_ignoreNextDelayedLayoutRequest doesn't interfere with any action from + // the user that results in a delayed layout. + function test_changePreferredSizeDuringLayoutWhileDraggingHandle() { + var control = createTemporaryObject(threeSizedItemsComponent, testCase) + verify(control) + + var firstItem = control.itemAt(0) + var secondItem = control.itemAt(1) + firstItem.widthChanged.connect(function() { + if (firstItem.width === 0) + secondItem.SplitView.preferredWidth = 50 + }) + + // Start dragging the handle. + var handles = findHandles(control) + var targetHandle = handles[0] + mousePress(targetHandle) + verify(control.resizing) + var localPos = testCase.mapToItem(targetHandle, 15, testCase.height / 2) + + // Move the handle to the very left, so that the item's width becomes zero. + mouseMove(targetHandle, -100, targetHandle.height / 2) + verify(control.resizing) + compare(firstItem.width, 0) + compare(secondItem.SplitView.preferredWidth, 50) + compare(secondItem.width, 50) + mouseRelease(targetHandle, -100, targetHandle.height / 2, Qt.LeftButton) + verify(!control.resizing) + } } |