diff --git a/inkex/elements/_base.py b/inkex/elements/_base.py index 422363f47b22f746a6a45e557db55cd5b69019cd..3c8e22dec1fa221d2133ba8e3e4e2e446083040b 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 7b9bdd4b4f0ae9b907b9b035e38e5ffdaccb355d..483726dcd4a433ab7c0ae7cddd9a3a7cb0f1eca0 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 d0a4a15ad257c8535a386bc2c12527b0506ac3a4..6622d5e8f9a579e7c8022e279372e41a3449bf77 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 104e38000d8630bf83c618dd6ab5134e050f052e..d6a315f5a2df6a249f162c8491efcf7febff0369 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 3e504f3db4ba649b05d618670fcb8621f7c99369..62e5ba93ceddff32af89def39dd9ae3b1b27b929 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 ee214ea209ebe4115beb1937b50501424f40a764..ea164222e5e869cb3e0a2c0da46fb300e6dc7e69 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 7e49beed2126061f92f1955ad9db954869aedbb2..101296202610f229b1d1dad32bb88e0eecfbf96d 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 35556827f6e5632f23fbd8ed1538d2547a23f9fd..c151f7693f1499121a7ed3c761408a29c08ae4b8 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 49010ee73784d683c34be4028d89f288f6d9be6b..13b8b4020dc5fcdcf7b97ae255488c438b1fcbb8 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")