diff options
author | Jüri Valdmann <juri.valdmann@qt.io> | 2019-05-06 14:09:11 +0200 |
---|---|---|
committer | Jüri Valdmann <juri.valdmann@qt.io> | 2019-05-07 11:17:58 +0000 |
commit | 9310d5fb5285ae5eb4b94c01606791319b775b85 (patch) | |
tree | 5f951759082b5eca0781c0cddef812271614da4a /src | |
parent | 7d001497ddcda501c55aac35b4c7a60980d9c6b5 (diff) |
Container: Keep currentIndex at 0 when removing item 0 if possible
Current behavior is to always decrement the currentIndex when the current item
is removed -- even when the current item is item 0. This means, for example,
that in a TabBar with three tabs and the first tab selected closing the first
tab will leave nothing at all selected.
Change behavior to keep currentIndex at 0 if there are still items left in the
container. Now closing the first tab will leave the next remaining tab selected.
Change-Id: If4e1903366e29fcee8226b776d5b2e03cec189df
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/quicktemplates2/qquickcontainer.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/quicktemplates2/qquickcontainer.cpp b/src/quicktemplates2/qquickcontainer.cpp index 2c357f82..8314230c 100644 --- a/src/quicktemplates2/qquickcontainer.cpp +++ b/src/quicktemplates2/qquickcontainer.cpp @@ -294,8 +294,9 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) updatingCurrent = true; + int count = contentModel->count(); bool currentChanged = false; - if (index == currentIndex) { + if (index == currentIndex && (index != 0 || count == 1)) { q->setCurrentIndex(currentIndex - 1); } else if (index < currentIndex) { --currentIndex; @@ -308,7 +309,6 @@ void QQuickContainerPrivate::removeItem(int index, QQuickItem *item) q->itemRemoved(index, item); - int count = contentModel->count(); for (int i = index; i < count; ++i) q->itemMoved(i, itemAt(i)); |