diff options
author | Christian Manning <cmanning999@gmail.com> | 2014-02-12 02:01:08 +0000 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-05-12 22:52:27 +0200 |
commit | 5988cfda014ffbe8ab8640f84c4fc704335b205d (patch) | |
tree | c40ab5b70dee1f2de8621aba4e2d87dab6c5c431 /src/controls/SplitView.qml | |
parent | 2b7e54ef5cf8e357493a54d977fcb2bf8288dc7a (diff) | |
download | qtquickcontrols-5988cfda014ffbe8ab8640f84c4fc704335b205d.tar.gz |
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 <jpnurmi@digia.com>
Diffstat (limited to 'src/controls/SplitView.qml')
-rw-r--r-- | src/controls/SplitView.qml | 48 |
1 files changed, 33 insertions, 15 deletions
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() |