Results 1 to 2 of 2

Thread: How do i duplicate a QGraphicsScene and make a deep copy of it ?

  1. #1
    Join Date
    Jan 2018
    Location
    India, Delhi
    Posts
    10
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Windows

    Question How do i duplicate a QGraphicsScene and make a deep copy of it ?

    Okay, i've a class that goes by the name "Frame" (represents a single animation frame) , now this frame for sure contains objects of type AnimatedSpriteItem (this class inherits QGraphicsItem).

    I want to have the functionality so whenever user create a new Frame (scene), it should not be blank but rather clone of another existing frame.
    However, after searching on web for some time, i was unable to find any concrete solution, as im afraid chances of making shallow copies are quite high and so i want to know if there is any concrete way to solve this issue ? do i need to make a private data member say, frameItems like this
    QMap<QString, AnimatedSpriteItem *> frameItems; that maps item names to their references and then traverse this container in order to have much more control over process of cloning or there is a better way ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,229
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do i duplicate a QGraphicsScene and make a deep copy of it ?

    Like all classes in Qt that have parent-child ownership relationships (QObject, QGraphicsItem, etc.), QGraphicsScene and QGraphicsItem have no copy constructors. In order to clone a scene, you will have to write the code to make a deep copy yourself, starting at the top level with QGraphicsScene::items(), and then for each QGraphicsItem in that list, cloning it and all of its child items.

    If everything in the scene is a QGraphicsItem of your own derived class(es), then you could add a clone() method to these that would make the process somewhat simpler. For out-of-the-box QGraphicsItem-bsed classes, you can creat and copy them based on their QGraphicsItem::type() values.

    You don't really need to keep any separate data structures. The whole hierarchy of object instances in the scene is there in the QGraphicsScene::items() method.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. The following user says thank you to d_stranz for this useful post:

    keshav2010 (24th May 2018)

Similar Threads

  1. Replies: 6
    Last Post: 14th May 2014, 13:14
  2. Replies: 2
    Last Post: 3rd March 2012, 07:34
  3. Deep copy of widget hierarchy
    By ajoffe in forum Qt Programming
    Replies: 2
    Last Post: 14th December 2009, 07:36
  4. QVector, containers, deep copy
    By TheKedge in forum Qt Programming
    Replies: 2
    Last Post: 23rd January 2007, 06:45
  5. Do assignment operators in Qt4 return deep or shallow copy?
    By high_flyer in forum Qt Programming
    Replies: 5
    Last Post: 25th September 2006, 10:01

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.