diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-04-30 14:18:03 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-05-07 14:32:46 +0200 |
commit | a6deb27ba0252bc06fd6f28fb76b552e6320853f (patch) | |
tree | 1eaadd966e87d195c7113d4332c21443cd9e7cdc /tests/auto/controls/data/tst_tabview.qml | |
parent | bb7e55b798a3e75d4ccb2d1e4c9c9705bcb1c4d8 (diff) | |
download | qtquickcontrols-a6deb27ba0252bc06fd6f28fb76b552e6320853f.tar.gz |
Fix TabView not to insert duplicate tabs
There are three ways to add tabs:
- declare 'static' Tab { } child elements
- call addTab() / insertTab()
- Component::createObject(tabView)
=> Do not rely on the calling order of Component.onCompleted()
and make sure that the same tabs are not accidentally re-inserted.
Task-number: QTBUG-30873
Change-Id: Ib30cfb676debbb302c5e9f7d757f66aab6fcc684
Reviewed-by: Caroline Chao <caroline.chao@digia.com>
Diffstat (limited to 'tests/auto/controls/data/tst_tabview.qml')
-rw-r--r-- | tests/auto/controls/data/tst_tabview.qml | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/tests/auto/controls/data/tst_tabview.qml b/tests/auto/controls/data/tst_tabview.qml index 973b6fde..ad132265 100644 --- a/tests/auto/controls/data/tst_tabview.qml +++ b/tests/auto/controls/data/tst_tabview.qml @@ -192,18 +192,35 @@ TestCase { } function test_dynamicTabs() { - var tabView = Qt.createQmlObject('import QtQuick 2.1; import QtQuick.Controls 1.0; TabView { property Component tabComponent: Component { Tab { } } }', testCase, ''); - compare(tabView.count, 0) - var tab1 = tabView.tabComponent.createObject(tabView) - compare(tabView.count, 1) - var tab2 = tabView.tabComponent.createObject(tabView) - compare(tabView.count, 2) - tab1.destroy() - wait(0) - compare(tabView.count, 1) - tab2.destroy() + var test_tabView = ' \ + import QtQuick 2.1; \ + import QtQuick.Controls 1.0; \ + TabView { \ + id: tabView; \ + Tab { title: "static" } \ + property Component tabComponent: Component { \ + id: tabComponent; \ + Tab { title: "dynamic" } \ + } \ + Component.onCompleted: { \ + addTab("added", tabComponent); \ + insertTab(0, "inserted", tabComponent); \ + tabComponent.createObject(tabView); \ + } \ + } ' + + var tabView = Qt.createQmlObject(test_tabView, testCase, '') + // insertTab(), addTab(), createObject() and static Tab {} + compare(tabView.count, 4) + compare(tabView.tabAt(0).title, "inserted") + + var tab = tabView.tabComponent.createObject(tabView) + compare(tabView.count, 5) + compare(tabView.tabAt(4).title, "dynamic") + tab.destroy() wait(0) - compare(tabView.count, 0) + compare(tabView.count, 4) + tabView.destroy() } function test_mousePressOnTabBar() { |