diff options
author | Jocelyn Turcotte <jocelyn.turcotte@digia.com> | 2014-05-06 13:45:59 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-07 14:02:20 +0200 |
commit | 7c7e510b6b4fb84d248059b9c55f58490fccc339 (patch) | |
tree | 7e5b0b78880c82eb42bfd6354eaafda1d12f0d8b /tests/auto/controls/data/tst_tabview.qml | |
parent | a84bb8aa5c24083c7ef54951a98bc62e7526da20 (diff) | |
download | qtquickcontrols-7c7e510b6b4fb84d248059b9c55f58490fccc339.tar.gz |
Fix the update of TabView.currentIndex when inserting/removing tabs
- Update currentIndex when adding or inserting tabs.
- Make sure that we update the current index before updating the array
to avoid a state of currentIndex > count -1 when removing the
last tab, where a property binding on TabView.count could try
fetching a tab past the array limit through TabView.getTab.
- Only decrease currentIndex when removedIndex <= currentIndex to
keep the current tab active when possible. Activate the next tab
instead of the previous one when the current tab is removed to make
it more instinctive to remove multiple tabs successively.
- Keep the current behavior of leaving currentIndex to 0 when
removing the last tab.
Change-Id: I030b86a03ce73f1177b1f04857abbdc2f7ec5835
Reviewed-by: J-P Nurmi <jpnurmi@digia.com>
Diffstat (limited to 'tests/auto/controls/data/tst_tabview.qml')
-rw-r--r-- | tests/auto/controls/data/tst_tabview.qml | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_tabview.qml b/tests/auto/controls/data/tst_tabview.qml index b7de67ba..9e556dd1 100644 --- a/tests/auto/controls/data/tst_tabview.qml +++ b/tests/auto/controls/data/tst_tabview.qml @@ -84,22 +84,53 @@ TestCase { function test_addRemoveTab() { var tabView = Qt.createQmlObject('import QtQuick 2.2; import QtQuick.Controls 1.2; TabView { }', testCase, ''); + + function verifyCurrentIndexCountDiff() { + verify(!tabView.currentIndex || tabView.count > tabView.currentIndex) + } + tabView.currentIndexChanged.connect(verifyCurrentIndexCountDiff) + tabView.countChanged.connect(verifyCurrentIndexCountDiff) + compare(tabView.count, 0) + compare(tabView.currentIndex, 0) tabView.addTab("title 1", newTab) compare(tabView.count, 1) + compare(tabView.currentIndex, 0) tabView.addTab("title 2", newTab) compare(tabView.count, 2) + compare(tabView.currentIndex, 0) compare(tabView.getTab(0).title, "title 1") compare(tabView.getTab(1).title, "title 2") + tabView.currentIndex = 1 + tabView.insertTab(1, "title 3") compare(tabView.count, 3) + compare(tabView.currentIndex, 2) compare(tabView.getTab(0).title, "title 1") compare(tabView.getTab(1).title, "title 3") compare(tabView.getTab(2).title, "title 2") tabView.insertTab(0, "title 4") compare(tabView.count, 4) + compare(tabView.currentIndex, 3) + compare(tabView.getTab(0).title, "title 4") + compare(tabView.getTab(1).title, "title 1") + compare(tabView.getTab(2).title, "title 3") + compare(tabView.getTab(3).title, "title 2") + + tabView.insertTab(tabView.count, "title 5") + compare(tabView.count, 5) + compare(tabView.currentIndex, 3) + compare(tabView.getTab(0).title, "title 4") + compare(tabView.getTab(1).title, "title 1") + compare(tabView.getTab(2).title, "title 3") + compare(tabView.getTab(3).title, "title 2") + compare(tabView.getTab(4).title, "title 5") + + tabView.removeTab(tabView.count - 1) + compare(tabView.count, 4) + compare(tabView.currentIndex, 3) compare(tabView.getTab(0).title, "title 4") compare(tabView.getTab(1).title, "title 1") compare(tabView.getTab(2).title, "title 3") @@ -107,21 +138,25 @@ TestCase { tabView.removeTab(0) compare(tabView.count, 3) + compare(tabView.currentIndex, 2) compare(tabView.getTab(0).title, "title 1") compare(tabView.getTab(1).title, "title 3") compare(tabView.getTab(2).title, "title 2") tabView.removeTab(1) compare(tabView.count, 2) + compare(tabView.currentIndex, 1) compare(tabView.getTab(0).title, "title 1") compare(tabView.getTab(1).title, "title 2") tabView.removeTab(1) compare(tabView.count, 1) + compare(tabView.currentIndex, 0) compare(tabView.getTab(0).title, "title 1") tabView.removeTab(0) compare(tabView.count, 0) + compare(tabView.currentIndex, 0) tabView.destroy() } |