Skip to content

[Refactor] Ownership of graphic items #248

Description

@letsfindaway

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions