diff options
author | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-09-18 15:19:06 +0200 |
---|---|---|
committer | Gabriel de Dietrich <gabriel.dedietrich@digia.com> | 2013-09-18 15:19:06 +0200 |
commit | 46f3cc477fc00aae887f085e063d6cb10bfdcd4c (patch) | |
tree | 0585601759ccbae2ed2abecedaf16e06b80676d0 /src/controls/TabView.qml | |
parent | 4c184095d378622fb0c3bb1692b331b3cc04e010 (diff) | |
parent | 04e000d2b1719696581bb4ae6ec21e39236ef38c (diff) | |
download | qtquickcontrols-46f3cc477fc00aae887f085e063d6cb10bfdcd4c.tar.gz |
Merge branch 'stable' into dev
Conflicts:
src/controls/qquickaction.cpp
Change-Id: I85255ba5c27c0d8ea023d0867e5963d43f8f1ddb
Diffstat (limited to 'src/controls/TabView.qml')
-rw-r--r-- | src/controls/TabView.qml | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/src/controls/TabView.qml b/src/controls/TabView.qml index e8dd9be8..696c6b3f 100644 --- a/src/controls/TabView.qml +++ b/src/controls/TabView.qml @@ -95,12 +95,16 @@ FocusScope { Returns the newly added tab. */ function insertTab(index, title, component) { - var tab = tabcomp.createObject(stack) + // 'loader' parent is a pending workaround while waiting for: + // https://codereview.qt-project.org/#change,65788 + var tab = tabcomp.createObject(loader) tab.sourceComponent = component - tab.parent = stack tab.title = title - tab.__inserted = true + // insert at appropriate index first, then set the parent to + // avoid onChildrenChanged appending it to the end of the list __tabs.insert(index, {tab: tab}) + tab.__inserted = true + tab.parent = stack __setOpacities() return tab } @@ -203,8 +207,17 @@ FocusScope { property int frameWidth property string style + property bool completed: false - Component.onCompleted: addTabs(stack.children) + Component.onCompleted: { + addTabs(stack.children) + completed = true + } + + onChildrenChanged: { + if (completed) + stack.addTabs(stack.children) + } function addTabs(tabs) { var tabAdded = false @@ -212,12 +225,11 @@ FocusScope { var tab = tabs[i] if (!tab.__inserted && tab.Accessible.role === Accessible.LayeredPane) { tab.__inserted = true - if (tab.parent === root) { - tab.parent = stack - // a tab added dynamically by Component::createObject() and passing the - // tab view as a parent should also get automatically removed when destructed + // reparent tabs created dynamically by createObject(tabView) + tab.parent = stack + // a dynamically added tab should also get automatically removed when destructed + if (completed) tab.Component.onDestruction.connect(stack.onDynamicTabDestroyed.bind(tab)) - } __tabs.append({tab: tab}) tabAdded = true } @@ -227,9 +239,10 @@ FocusScope { } function onDynamicTabDestroyed() { - for (var i = 0; i < stack.children.length; ++i) { - if (this === stack.children[i]) { - root.removeTab(i) + for (var i = 0; i < __tabs.count; ++i) { + if (__tabs.get(i).tab === this) { + __tabs.remove(i, 1) + __setOpacities() break } } |