diff options
author | J-P Nurmi <jpnurmi@qt.io> | 2017-06-03 21:39:29 +0200 |
---|---|---|
committer | J-P Nurmi <jpnurmi@qt.io> | 2017-06-06 10:23:58 +0000 |
commit | 00594b6e0554950ba3f8683f452c1ca2574f80c5 (patch) | |
tree | b2e8d98badc2fc1fb41ca48873123695ed9c40d8 /tests | |
parent | 4339a686c190605121a327f703e96dae8b9451d5 (diff) |
QQuickContainer: removeItem(Item) and takeItem(int)
Deprecate removeItem(int) in favor of removeItem(Item) and
takeItem(int) with clearer semantics.
If one already has access to an item, one can pass it to removeItem()
to get rid of it for good, instead of having to call destroy() by hand.
If one knows the index instead, we provide a way to take the respective
item out of the container, and let the user decide what to do with it.
This way we provide convenient ways to remove & destroy items in one
go, and to take items out without destroying them.
This nice pattern was once upon time planned for the QQC1 containers
such as SplitView, and should have been used for the QQC2 containers,
but was simply forgotten during the development...
[ChangeLog][Controls][Container] Deprecated removeItem(int) in favor of
removeItem(Item) and takeItem(int) with clearer semantics. The former
destroys the item, whereas the latter transfers ownership to the
caller.
Change-Id: I4af51157b196c273f923d99b949a9660e6e8df64
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/auto/controls/data/tst_container.qml | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/tests/auto/controls/data/tst_container.qml b/tests/auto/controls/data/tst_container.qml index 049982fb..44d8e67a 100644 --- a/tests/auto/controls/data/tst_container.qml +++ b/tests/auto/controls/data/tst_container.qml @@ -126,4 +126,46 @@ TestCase { compare(control1.currentIndex, 1) compare(control2.currentIndex, 1) } + + function test_removeTakeItem() { + var control = createTemporaryObject(container, testCase) + verify(control) + + var item1 = rectangle.createObject(control) + var item2 = rectangle.createObject(control) + var item3 = rectangle.createObject(control) + + item1.Component.onDestruction.connect(function() { item1 = null }) + item2.Component.onDestruction.connect(function() { item2 = null }) + item3.Component.onDestruction.connect(function() { item3 = null }) + + control.addItem(item1) + control.addItem(item2) + control.addItem(item3) + compare(control.count, 3) + + // takeItem(int) does not destroy + compare(control.takeItem(1), item2) + compare(control.count, 2) + wait(1) + verify(item2) + + // removeItem(Item) destroys + control.removeItem(item1) + compare(control.count, 1) + wait(1) + verify(!item1) + + // removeItem(null) must not call removeItem(0) + control.removeItem(null) + compare(control.count, 1) + wait(1) + verify(item3) + + // deprecated removeItem(int) does not destroy + control.removeItem(0) + compare(control.count, 0) + wait(1) + verify(item3) + } } |