Search code examples
objecttreecopy-pastegraphic

How to implement copy and paste tree of graphic items


I am working in graphical application that uses objects and groups. So, items can be grouped in a group. A group can contain other groups and items.

To copy the items and groups I produce an XML describing such items and groups and send the information to the clipboard, for example:

<!DOCTYPE tnkClpObjData>
<tnkItems>
    <tnkGroup id="003">
        <tnkItem>
            <PluginName>Ellipse</PluginName>
        </tnkItem>
        <tnkItem>
            <PluginName>Rectangle</PluginName>
        </tnkItem>
        <tnkGroup id="002">
            <tnkItem>
                    <PluginName>Rectangle</PluginName>
            </tnkItem>
            <tnkGroup id="001">
                    <tnkItem>
                        <PluginName>LineEdit</PluginName>
                    </tnkItem>
                    <tnkItem>
                        <PluginName>Label</PluginName>
                    </tnkItem>
            </tnkGroup>
        </tnkGroup>
    </tnkGroup>
</tnkItems>

For pasting the items I know I need to use the XML but what would be the best way to implement it? Do I first create the items and then the group? or do I need to navigate the tree from the deepest item up to the first?

Thanks, Carlos.


Solution

  • I used recursive functions for this.