diff options
author | J-P Nurmi <jpnurmi@digia.com> | 2013-04-15 15:23:23 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-04-16 00:45:47 +0200 |
commit | 8272730f380ec9cf63db828e5726b933c52a98ef (patch) | |
tree | 619cd3d0df50bde2d68c7440003da48b93b829f1 /src/controls/TabView.qml | |
parent | a80b36edbe963495bca270a178237bc91772eed4 (diff) | |
download | qtquickcontrols-8272730f380ec9cf63db828e5726b933c52a98ef.tar.gz |
TabView: support dynamic tabs with createObject() and destroy()
Change-Id: I4c8e4219de6f510e4790343528fa7b6b502b7722
Reviewed-by: Thomas Hartmann <Thomas.Hartmann@digia.com>
Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/controls/TabView.qml')
-rw-r--r-- | src/controls/TabView.qml | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/controls/TabView.qml b/src/controls/TabView.qml index 1ff28392..82acef72 100644 --- a/src/controls/TabView.qml +++ b/src/controls/TabView.qml @@ -84,7 +84,7 @@ FocusScope { Returns the newly added tab. */ function addTab(title, component) { - var tab = tabcomp.createObject(this); + var tab = tabcomp.createObject(stack) tab.sourceComponent = component __tabs.push(tab) tab.parent = stack @@ -97,7 +97,7 @@ FocusScope { Returns the newly added tab. */ function insertTab(index, title, component) { - var tab = tabcomp.createObject(this); + var tab = tabcomp.createObject(stack) tab.sourceComponent = component tab.parent = stack tab.title = title @@ -193,10 +193,34 @@ FocusScope { } __setOpacities() } + + function onDynamicTabDestroyed() { + for (var i = 0; i < stack.children.length; ++i) { + if (this === stack.children[i]) { + root.removeTab(i) + break + } + } + } } onLoaded: { item.z = -1 } } + onChildrenChanged: { + var tabAdded = false + for (var i = 0; i < children.length; ++i) { + var child = children[i] + if (child.Accessible.role === Accessible.PageTab) { + __tabs.push(child) + child.parent = stack + child.Component.onDestruction.connect(stack.onDynamicTabDestroyed.bind(child)) + tabAdded = true + } + } + if (tabAdded) + __setOpacities() + } + states: [ State { name: "Bottom" |