From 2fffdc7724f6b641275b3d601bf50de3f451ece1 Mon Sep 17 00:00:00 2001 From: Jonathan Neuhauser Date: Thu, 10 Feb 2022 14:22:04 +0100 Subject: [PATCH] duplicate() sets IDs of descendants --- inkex/elements/_base.py | 5 +- ...nd__Snake__--id__g3427__--id__path2551.out | 4 +- ...d__Ribbon__--id__g4054__--id__path4056.out | 22 ++++----- ...al__True__--id__g3961__--id__path10007.out | 14 +++--- ...ace__5__--id__path2408__--id__path2405.out | 2 +- ...nd__Snake__--id__g5848__--id__path3336.out | 30 ++++++------ ...th4608__--id__path4610__--id__path4612.out | 2 +- ..._Snake__--id__text4418__--id__path4412.out | 46 +++++++++---------- tests/test_inkex_elements_base.py | 14 +++++- 9 files changed, 76 insertions(+), 63 deletions(-) diff --git a/inkex/elements/_base.py b/inkex/elements/_base.py index 422363f4..3c8e22de 100644 --- a/inkex/elements/_base.py +++ b/inkex/elements/_base.py @@ -366,10 +366,11 @@ class BaseElement(IBaseElement): return elem def duplicate(self): - """Like copy(), but the copy stays in the tree and sets a random id""" + """Like copy(), but the copy stays in the tree and sets a random id on the + duplicate and all its descendants""" elem = self.copy() self.addnext(elem) - elem.set_random_id() + elem.set_random_ids() return elem def __str__(self): diff --git a/tests/data/refs/pathalongpath__--copymode__Repeated__--kind__Snake__--id__g3427__--id__path2551.out b/tests/data/refs/pathalongpath__--copymode__Repeated__--kind__Snake__--id__g3427__--id__path2551.out index 7b9bdd4b..483726dc 100644 --- a/tests/data/refs/pathalongpath__--copymode__Repeated__--kind__Snake__--id__g3427__--id__path2551.out +++ b/tests/data/refs/pathalongpath__--copymode__Repeated__--kind__Snake__--id__g3427__--id__path2551.out @@ -44,8 +44,8 @@ - - + + diff --git a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--id__g4054__--id__path4056.out b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--id__g4054__--id__path4056.out index d0a4a15a..6622d5e8 100644 --- a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--id__g4054__--id__path4056.out +++ b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--id__g4054__--id__path4056.out @@ -55,21 +55,21 @@ - - - - - - + + + + + + - + - - - + + + - + diff --git a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--vertical__True__--id__g3961__--id__path10007.out b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--vertical__True__--id__g3961__--id__path10007.out index 104e3800..d6a315f5 100644 --- a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--vertical__True__--id__g3961__--id__path10007.out +++ b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Ribbon__--vertical__True__--id__g3961__--id__path10007.out @@ -38,14 +38,14 @@ - - - - - + + + + + - - + + diff --git a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Snake__--noffset__5__--space__5__--id__path2408__--id__path2405.out b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Snake__--noffset__5__--space__5__--id__path2408__--id__path2405.out index 3e504f3d..62e5ba93 100644 --- a/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Snake__--noffset__5__--space__5__--id__path2408__--id__path2405.out +++ b/tests/data/refs/pathalongpath__--copymode__Repeated____stretched__--kind__Snake__--noffset__5__--space__5__--id__path2408__--id__path2405.out @@ -90,7 +90,7 @@ Settings: Repeated, Stretched, Ribbon, Vertical. Tests a group pattern with multiple nested transforms Settings: Repeated, Stretched, Ribbon. Tests a group pattern with multiple nested clones Settings: Single, Stretched, Snake. Tests putting a text (converted to a path) on a path and stretching it to fit its length - + Settings: Repeated, Stretched, Snake, Space between copies=5, Normal offset=5. Tests putting a path with multiple subpaths with a gradient on a closed path Settings: Single, Stretched, Snake. Tests selecting multiple sceleton paths, one consisting of multiple subpaths diff --git a/tests/data/refs/pathalongpath__--copymode__Single__--duplicate__True__--kind__Snake__--id__g5848__--id__path3336.out b/tests/data/refs/pathalongpath__--copymode__Single__--duplicate__True__--kind__Snake__--id__g5848__--id__path3336.out index ee214ea2..ea164222 100644 --- a/tests/data/refs/pathalongpath__--copymode__Single__--duplicate__True__--kind__Snake__--id__g5848__--id__path3336.out +++ b/tests/data/refs/pathalongpath__--copymode__Single__--duplicate__True__--kind__Snake__--id__g5848__--id__path3336.out @@ -23,28 +23,28 @@ - - - - - - - - - + + + - - - + + + - - - + + + + + + + + + diff --git a/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__path4585__--id__path4608__--id__path4610__--id__path4612.out b/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__path4585__--id__path4608__--id__path4610__--id__path4612.out index 7e49beed..10129620 100644 --- a/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__path4585__--id__path4608__--id__path4610__--id__path4612.out +++ b/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__path4585__--id__path4608__--id__path4610__--id__path4612.out @@ -81,7 +81,7 @@ - + diff --git a/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__text4418__--id__path4412.out b/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__text4418__--id__path4412.out index 35556827..c151f769 100644 --- a/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__text4418__--id__path4412.out +++ b/tests/data/refs/pathalongpath__--copymode__Single____stretched__--kind__Snake__--id__text4418__--id__path4412.out @@ -80,29 +80,29 @@ - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/test_inkex_elements_base.py b/tests/test_inkex_elements_base.py index 49010ee7..13b8b402 100644 --- a/tests/test_inkex_elements_base.py +++ b/tests/test_inkex_elements_base.py @@ -14,7 +14,7 @@ from inkex.elements import ( TextElement, Line, ) -from inkex.elements._base import NodeBasedLookup +from inkex.elements._base import NodeBasedLookup, BaseElement from inkex.transforms import Transform from inkex.styles import Style from inkex.utils import FragmentError @@ -336,6 +336,18 @@ class RelationshipTestCase(SvgTestCase): self.assertNotEqual(elem.get("id"), dup.get("id")) self.assertEqual(elem.getparent(), dup.getparent()) + def test_duplicate_group(self): + """Check that when duplicating a group, all ids are replaced + (Issue https://gitlab.com/inkscape/extensions/-/issues/379)""" + elem: BaseElement = self.svg.getElementById("A") + dup = elem.duplicate() + elem_ids = [i.get_id() for i in elem.iter() if hasattr(i, "get_id")] + dup_ids = [i.get_id() for i in dup.iter() if hasattr(i, "get_id")] + + in_both = [i for i in elem_ids if i in dup_ids] + + self.assertListEqual(in_both, []) + def test_replace_with(self): """Replacing nodes in a tree""" rect = self.svg.getElementById("E") -- GitLab