Use Presentation.parent instead of Diagram.get_parent()

This commit is contained in:
Arjan Molenaar 2020-12-24 17:41:43 +01:00
parent 8ebee980f7
commit 268d0563f0
No known key found for this signature in database
GPG Key ID: BF977B918996CB13
11 changed files with 22 additions and 25 deletions

View File

@ -56,7 +56,7 @@ def order_lifeline_covered_by(lifeline):
def owner_for_message(line, lifeline):
maybe_interaction = lifeline.diagram.get_parent(lifeline)
maybe_interaction = lifeline.parent
if line.subject.interaction:
return
elif isinstance(maybe_interaction, InteractionItem):
@ -248,7 +248,7 @@ class LifelineExecutionSpecificationConnect(BaseConnector):
exec_spec.enclosingInteraction = lifeline.interaction
diagram = self.diagram
if diagram.get_parent(self.line) is not self.element:
if self.line.parent is not self.element:
self.line.parent = self.element
for cinfo in diagram.connections.get_connections(connected=self.line):
@ -263,8 +263,8 @@ class LifelineExecutionSpecificationConnect(BaseConnector):
diagram = self.diagram
if diagram.get_parent(self.line) is self.element:
new_parent = diagram.get_parent(self.element)
if self.line.parent is self.element:
new_parent = self.element.parent
self.line.parent = new_parent # type: ignore[assignment]
for cinfo in diagram.connections.get_connections(connected=self.line):

View File

@ -146,7 +146,7 @@ def test_message_is_owned_by_implicit_interaction_connecting_to_head(
assert msg.subject is not None
assert msg.subject.interaction is interaction
assert diagram.get_parent(msg) is None
assert msg.parent is None
@pytest.mark.parametrize("end_name", ["head", "tail"])
@ -165,7 +165,7 @@ def test_message_is_owned_by_interaction_item_connecting_to_one_end(
assert msg.subject is not None
assert msg.subject.interaction is interaction.subject
assert diagram.get_parent(msg) is interaction
assert msg.parent is interaction
def test_disconnection(diagram):

View File

@ -157,7 +157,7 @@ class StyledDiagram:
return (
StyledItem(item, self.selection)
for item in self.diagram.get_all_items()
if not self.diagram.get_parent(item)
if not item.parent
)
def attribute(self, name: str) -> str:
@ -187,7 +187,7 @@ class StyledItem:
return removesuffix(type(self.item).__name__, "Item").lower()
def parent(self) -> Union[StyledItem, StyledDiagram]:
parent = self.diagram.get_parent(self.item)
parent = self.item.parent
return (
StyledItem(parent, self.selection)
if parent

View File

@ -153,7 +153,7 @@ def copy_presentation(item: Presentation) -> PresentationCopy:
buffer[name] = serialize(value)
item.save(save_func)
parent = item.diagram.get_parent(item)
parent = item.parent
return PresentationCopy(
cls=item.__class__,
data=buffer,

View File

@ -57,7 +57,7 @@ class DropZoneMove(GuidedItemMove):
view = self.view
x, y = pos
current_parent = view.model.get_parent(item)
current_parent = item.parent
over_item = item_at_point(view, (x, y), selected=False)
if not over_item:
@ -83,8 +83,7 @@ class DropZoneMove(GuidedItemMove):
super().stop_move(pos)
item = self.item
view = self.view
model = view.model
old_parent = model.get_parent(item)
old_parent = item.parent
new_parent = view.selection.dropzone_item
try:

View File

@ -34,7 +34,7 @@ def from_package_str(item):
return False
namespace = subject.namespace
parent = diagram.get_parent(item)
parent = item.parent
# if there is a parent (i.e. interaction)
if parent and parent.subject and parent.subject.namespace is not namespace:

View File

@ -17,7 +17,7 @@ def node_with_component(diagram, element_factory):
Group(node_item, comp_item).group()
comp_item.parent = node_item
assert diagram.get_parent(comp_item) is node_item
assert comp_item.parent is node_item
return node_item, comp_item
@ -29,7 +29,7 @@ def test_copy_paste_of_nested_item(diagram, element_factory, node_with_component
(new_comp_item,) = paste(buffer, diagram, element_factory.lookup)
assert diagram.get_parent(new_comp_item) is node_item
assert new_comp_item.parent is node_item
def test_copy_paste_of_item_with_nested_item(
@ -44,7 +44,7 @@ def test_copy_paste_of_item_with_nested_item(
new_node_item = next(i for i in new_items if isinstance(i, NodeItem))
new_comp_item = next(i for i in new_items if isinstance(i, ComponentItem))
assert diagram.get_parent(new_comp_item) is new_node_item
assert new_comp_item.parent is new_node_item
def test_copy_remove_paste_of_item_with_nested_item(
@ -56,4 +56,4 @@ def test_copy_remove_paste_of_item_with_nested_item(
new_node_item = next(i for i in new_items if isinstance(i, NodeItem))
new_comp_item = next(i for i in new_items if isinstance(i, ComponentItem))
assert diagram.get_parent(new_comp_item) is new_node_item
assert new_comp_item.parent is new_node_item

View File

@ -60,7 +60,7 @@ class CopyService(Service, ActionProvider):
# move pasted items a bit, so user can see result of his action :)
for item in new_items:
if diagram.get_parent(item) not in new_items:
if item.parent not in new_items:
item.matrix.translate(10, 10)
return new_items

View File

@ -17,9 +17,7 @@ def test_load_grouped_connected_items(element_factory, loader):
loader(NODE_EXAMPLE_XML)
diagram = element_factory.lselect()[0]
node_item, dep_item = [
e for e in diagram.get_all_items() if not diagram.get_parent(e)
]
node_item, dep_item = [e for e in diagram.get_all_items() if not e.parent]
child_one, child_two = node_item.children
@ -28,7 +26,7 @@ def test_load_grouped_connected_items(element_factory, loader):
assert isinstance(child_one, NodeItem)
assert isinstance(child_two, NodeItem)
assert diagram.get_parent(child_one) is node_item
assert child_one.parent is node_item
assert tuple(diagram.get_matrix_i2c(child_one)) == (
1.0,

View File

@ -13,7 +13,7 @@ def test_message_item_upgrade(element_factory, modeling_language):
load_elements(elements, element_factory, modeling_language)
diagram = element_factory.lselect(UML.Diagram)[0]
items = [e for e in diagram.get_all_items() if not diagram.get_parent(e)]
items = [e for e in diagram.get_all_items() if not e.parent]
message_items = [i for i in items if isinstance(i, diagramitems.MessageItem)]
subjects = [m.subject for m in message_items]
messages = element_factory.lselect(UML.Message)

View File

@ -87,5 +87,5 @@ class ActionIssueTestCase(TestCase):
for a in actions:
(p,) = a.inPartition
assert p
assert diagram.get_parent(a.presentation[0])
assert diagram.get_parent(a.presentation[0]) is p.presentation[0]
assert a.presentation[0].parent
assert a.presentation[0].parent is p.presentation[0]