From 5988cfda014ffbe8ab8640f84c4fc704335b205d Mon Sep 17 00:00:00 2001 From: Christian Manning Date: Wed, 12 Feb 2014 02:01:08 +0000 Subject: Add ability to dynamically add items to SplitView Factor out the loop body of init() into a pushItem() function to make the ability user-accessible. Can only append items due to the list property limitation. Takes account of item's fill property Task-number: QTBUG-35281 Change-Id: Ibb2a5e3cf945bede544cf6bf8eebe13ffd2f79e5 Reviewed-by: J-P Nurmi --- src/controls/SplitView.qml | 48 +++++++++++++++++++++++++++++++--------------- 1 file changed, 33 insertions(+), 15 deletions(-) (limited to 'src/controls/SplitView.qml') diff --git a/src/controls/SplitView.qml b/src/controls/SplitView.qml index dadff049..f5bb16d7 100644 --- a/src/controls/SplitView.qml +++ b/src/controls/SplitView.qml @@ -166,6 +166,17 @@ Item { onHeightChanged: d.updateLayout() onOrientationChanged: d.changeOrientation() + /*! Add an item to the end of the view. */ + function addItem(item) { + d.updateLayoutGuard = true + + d.addItem_impl(item) + + d.calculateImplicitSize() + d.updateLayoutGuard = false + d.updateFillIndex() + } + SystemPalette { id: pal } QtObject { @@ -185,28 +196,35 @@ Item { property int fillIndex: -1 property bool updateLayoutGuard: true + function addItem_impl(item) + { + // temporarily set fillIndex to new item + fillIndex = __items.length + if (splitterItems.children.length > 0) + handleLoader.createObject(splitterHandles, {"__handleIndex":splitterItems.children.length - 1}) + + item.parent = splitterItems + + // should match disconnections in Component.onDestruction + item.widthChanged.connect(d.updateLayout) + item.heightChanged.connect(d.updateLayout) + item.Layout.maximumWidthChanged.connect(d.updateLayout) + item.Layout.minimumWidthChanged.connect(d.updateLayout) + item.Layout.maximumHeightChanged.connect(d.updateLayout) + item.Layout.minimumHeightChanged.connect(d.updateLayout) + item.visibleChanged.connect(d.updateFillIndex) + item.Layout.fillWidthChanged.connect(d.updateFillIndex) + item.Layout.fillHeightChanged.connect(d.updateFillIndex) + } + function init() { for (var i=0; i<__contents.length; ++i) { var item = __contents[i]; if (!item.hasOwnProperty("x")) continue - - if (splitterItems.children.length > 0) - handleLoader.createObject(splitterHandles, {"__handleIndex":splitterItems.children.length - 1}) - item.parent = splitterItems + addItem_impl(item) i-- // item was removed from list - - // should match disconnections in Component.onDestruction - item.widthChanged.connect(d.updateLayout) - item.heightChanged.connect(d.updateLayout) - item.Layout.maximumWidthChanged.connect(d.updateLayout) - item.Layout.minimumWidthChanged.connect(d.updateLayout) - item.Layout.maximumHeightChanged.connect(d.updateLayout) - item.Layout.minimumHeightChanged.connect(d.updateLayout) - item.visibleChanged.connect(d.updateFillIndex) - item.Layout.fillWidthChanged.connect(d.updateFillIndex) - item.Layout.fillHeightChanged.connect(d.updateFillIndex) } d.calculateImplicitSize() -- cgit v1.2.1