There is a mechanism in UBCoreGraphicsScene which manages a set of items which are currently not on the scene, but should remain alive for some reason. In order to delete these items when the scene is deleted, they are managed in a set mItemsToDelete. However I think there should always be some object responsible for them.
When are items added
Items are added to this set here:
- When an item is converted to a tool widget, then the item is added to this set in order to allow later restoration when it is again converted back to an item.
- If an item is removed from a group. This happens in an undo command, in
scene::clearContent() and in scene::shapeToStrokesGroup().
- And interestingly in
UBCoreGraphicsScene::addItem(). Here I don't know what this means, because the item is definitely also owned by the scene after this function call.
When are items removed
Items are removed from this set here:
- When an item is added to a group.
- As part of the Item Undo Command.
- For some temporary items in graphics scene.
- For child items, if a group is added to the scene.
- When a tool widget is created, but still not activated.
Item ownership
I think all of this is related to poor management of item ownership. Without further analysis I think:
- An item is owned by the scene as long as it is added to the scene.
- An item might be owned by an item undo command. Depending on the undo/redo state, these are either the added or removed items.
- A child item is owned by its parent.
- The item related to a tool widget should be owned by the tool widget.
Using these rules, it should not be necessary to keep such a list of items to be deleted. Instead the owning object should delete these items when it is deleted.
There is a mechanism in
UBCoreGraphicsScenewhich manages a set of items which are currently not on the scene, but should remain alive for some reason. In order to delete these items when the scene is deleted, they are managed in a setmItemsToDelete. However I think there should always be some object responsible for them.When are items added
Items are added to this set here:
scene::clearContent()and inscene::shapeToStrokesGroup().UBCoreGraphicsScene::addItem(). Here I don't know what this means, because the item is definitely also owned by the scene after this function call.When are items removed
Items are removed from this set here:
Item ownership
I think all of this is related to poor management of item ownership. Without further analysis I think:
Using these rules, it should not be necessary to keep such a list of items to be deleted. Instead the owning object should delete these items when it is deleted.