From da7f7af244e5f1f61ef7060b62b2e5c8d240701f Mon Sep 17 00:00:00 2001 From: Mitch Curtis Date: Wed, 16 Oct 2019 15:18:36 +0200 Subject: Fix assertion failure when hiding a SplitView with only one item Check for -1 when calling handleIndexForSplitIndex(). Change-Id: I81021b64265ace0c47269ea54e538a2725c84b79 Fixes: QTBUG-79270 Reviewed-by: Richard Moe Gustavsen --- src/quicktemplates2/qquicksplitview.cpp | 12 ++++++++---- tests/auto/controls/data/tst_splitview.qml | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp index 75cd9674..108dbe07 100644 --- a/src/quicktemplates2/qquicksplitview.cpp +++ b/src/quicktemplates2/qquicksplitview.cpp @@ -849,6 +849,8 @@ QQuickSplitViewPrivate::EffectiveSizeData QQuickSplitViewPrivate::effectiveSizeD int QQuickSplitViewPrivate::handleIndexForSplitIndex(int splitIndex) const { + // If it's the first and only item in the view, it doesn't have a handle, + // so return -1: splitIndex (0) - 1. // If it's the last item in the view, it doesn't have a handle, so use // the handle for the previous item. return splitIndex == contentModel->count() - 1 ? splitIndex - 1 : splitIndex; @@ -1016,11 +1018,13 @@ void QQuickSplitViewPrivate::itemVisibilityChanged(QQuickItem *item) // of the corresponding handle (if one exists). const int handleIndex = handleIndexForSplitIndex(itemIndex); - QQuickItem *handleItem = m_handleItems.at(handleIndex); - handleItem->setVisible(item->isVisible()); + if (handleIndex != -1) { + QQuickItem *handleItem = m_handleItems.at(handleIndex); + handleItem->setVisible(item->isVisible()); - qCDebug(qlcQQuickSplitView) << "set visible property of handle item" - << handleItem << "at index" << handleIndex << "to" << item->isVisible(); + qCDebug(qlcQQuickSplitView) << "set visible property of handle item" + << handleItem << "at index" << handleIndex << "to" << item->isVisible(); + } updateHandleVisibilities(); updateFillIndex(); diff --git a/tests/auto/controls/data/tst_splitview.qml b/tests/auto/controls/data/tst_splitview.qml index a03c09a0..bd36e898 100644 --- a/tests/auto/controls/data/tst_splitview.qml +++ b/tests/auto/controls/data/tst_splitview.qml @@ -1958,4 +1958,20 @@ TestCase { mouseRelease(targetHandle, -100, targetHandle.height / 2, Qt.LeftButton) verify(!control.resizing) } + + Component { + id: oneItemComponent + + SplitView { + Item {} + } + } + + // QTBUG-79270 + function test_hideSplitViewWithOneItem() { + var control = createTemporaryObject(oneItemComponent, testCase) + verify(control) + // Shouldn't be an assertion failure. + control.visible = false + } } -- cgit v1.2.3