diff options
| author | Filippo Cucchetto <filippocucchetto@gmail.com> | 2015-01-18 17:35:09 +0100 |
|---|---|---|
| committer | Filippo Cucchetto <filippocucchetto@gmail.com> | 2015-02-16 07:21:57 +0000 |
| commit | 4d40351035d744a6021a7930cd46fe021474ba1d (patch) | |
| tree | 77d8de3c323345ca92907aecb216b07d38f1ca92 /src/controls/SplitView.qml | |
| parent | f442e9569fe4baf92ecc71d701484d32153c7d80 (diff) | |
Added remove function to the SplitView
Change-Id: Ie30e76356716a546f7eaa3e4c2eccbc15ebf9a5c
Task-number: QTBUG-42509
Reviewed-by: J-P Nurmi <jpnurmi@theqtcompany.com>
Diffstat (limited to 'src/controls/SplitView.qml')
| -rw-r--r-- | src/controls/SplitView.qml | 95 |
1 files changed, 81 insertions, 14 deletions
diff --git a/src/controls/SplitView.qml b/src/controls/SplitView.qml index 38b7f8391..be1a9e923 100644 --- a/src/controls/SplitView.qml +++ b/src/controls/SplitView.qml @@ -181,14 +181,27 @@ Item { \since QtQuick.Controls 1.3 */ function addItem(item) { d.updateLayoutGuard = true - d.addItem_impl(item) - d.calculateImplicitSize() d.updateLayoutGuard = false d.updateFillIndex() } + /*! Remove \a item from the view. + \since QtQuick.Controls 1.4 */ + function removeItem(item) { + d.updateLayoutGuard = true + var result = d.removeItem_impl(item) + if (result !== null) { + d.calculateImplicitSize() + d.updateLayoutGuard = false + d.updateFillIndex() + } + else { + d.updateLayoutGuard = false + } + } + SystemPalette { id: pal } QtObject { @@ -230,8 +243,12 @@ Item { handleLoader.createObject(splitterHandles, {"__handleIndex":splitterItems.children.length - 1}) item.parent = splitterItems + d.initItemConnections(item) + } - // should match disconnections in Component.onDestruction + function initItemConnections(item) + { + // should match disconnections in terminateItemConnections item.widthChanged.connect(d.updateLayout) item.heightChanged.connect(d.updateLayout) item.Layout.maximumWidthChanged.connect(d.updateLayout) @@ -247,6 +264,66 @@ Item { item.Layout.fillHeightChanged.connect(d.updateFillIndex) } + function terminateItemConnections(item) + { + // should match connections in initItemConnections + item.widthChanged.disconnect(d.updateLayout) + item.heightChanged.disconnect(d.updateLayout) + item.Layout.maximumWidthChanged.disconnect(d.updateLayout) + item.Layout.minimumWidthChanged.disconnect(d.updateLayout) + item.Layout.maximumHeightChanged.disconnect(d.updateLayout) + item.Layout.minimumHeightChanged.disconnect(d.updateLayout) + item.visibleChanged.disconnect(d.updateFillIndex) + item.Layout.fillWidthChanged.disconnect(d.updateFillIndex) + item.Layout.fillHeightChanged.disconnect(d.updateFillIndex) + } + + function removeItem_impl(item) + { + var pos = itemPos(item) + + // Check pos range + if (pos < 0 || pos >= __items.length) + return null + + // Temporary unset the fillIndex + fillIndex = __items.length - 1 + + // Remove the handle at the left/right of the item that + // is going to be removed + var handlePos = -1 + var hasPrevious = pos > 0 + var hasNext = (pos + 1) < __items.length + + if (hasPrevious) + handlePos = pos-1 + else if (hasNext) + handlePos = pos + if (handlePos >= 0) { + var handle = __handles[handlePos] + handle.visible = false + handle.parent = null + handle.destroy() + for (var i = handlePos; i < __handles.length; ++i) + __handles[i].__handleIndex = i + } + + // Remove the item. + // Disconnect the item to be removed + terminateItemConnections(item) + item.parent = null + + return item + } + + function itemPos(item) + { + for (var i = 0; i < __items.length; ++i) + if (item === __items[i]) + return i + return -1 + } + function init() { for (var i=0; i<__contents.length; ++i) { @@ -540,17 +617,7 @@ Item { Component.onDestruction: { for (var i=0; i<splitterItems.children.length; ++i) { var item = splitterItems.children[i]; - - // should match connections in init() - item.widthChanged.disconnect(d.updateLayout) - item.heightChanged.disconnect(d.updateLayout) - item.Layout.maximumWidthChanged.disconnect(d.updateLayout) - item.Layout.minimumWidthChanged.disconnect(d.updateLayout) - item.Layout.maximumHeightChanged.disconnect(d.updateLayout) - item.Layout.minimumHeightChanged.disconnect(d.updateLayout) - item.visibleChanged.disconnect(d.updateFillIndex) - item.Layout.fillWidthChanged.disconnect(d.updateFillIndex) - item.Layout.fillHeightChanged.disconnect(d.updateFillIndex) + d.terminateItemConnections(item) } } } |
