From 53fa52bb604ab28ee37aba26e155486e94c66dec Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Tue, 27 Aug 2013 14:50:59 +0200 Subject: TabView: fix dynamic tab handling Task-number: QTBUG-33162 Change-Id: I873b37bd157230f80237fd40f3e5149fbd0207ca Reviewed-by: Volker Krause Reviewed-by: Jens Bache-Wiig --- src/controls/TabView.qml | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) (limited to 'src/controls/TabView.qml') diff --git a/src/controls/TabView.qml b/src/controls/TabView.qml index 6319d72cd..cd8a023aa 100644 --- a/src/controls/TabView.qml +++ b/src/controls/TabView.qml @@ -95,12 +95,14 @@ FocusScope { Returns the newly added tab. */ function insertTab(index, title, component) { - var tab = tabcomp.createObject(stack) + var tab = tabcomp.createObject() 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 +205,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 +223,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 +237,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 } } -- cgit v1.2.3 From 04e000d2b1719696581bb4ae6ec21e39236ef38c Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Wed, 18 Sep 2013 13:43:59 +0200 Subject: Fix Tab ownership issue that has been blocking stable->dev merge Change-Id: Ifcae96687bcc54486d7f16b1e1002e54394b914d Reviewed-by: Gabriel de Dietrich --- src/controls/TabView.qml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/controls/TabView.qml') diff --git a/src/controls/TabView.qml b/src/controls/TabView.qml index cd8a023aa..bee7b3eb9 100644 --- a/src/controls/TabView.qml +++ b/src/controls/TabView.qml @@ -95,7 +95,9 @@ FocusScope { Returns the newly added tab. */ function insertTab(index, title, component) { - var tab = tabcomp.createObject() + // '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.title = title // insert at appropriate index first, then set the parent to -- cgit v1.2.3