Results 1 to 8 of 8

Thread: Synchronizing behaviour between QListView and QGraphicsScene

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    May 2009
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Synchronizing behaviour between QListView and QGraphicsScene

    But if you think about the idea of using a 2-way map between QStandardItem and QGraphicsItem, the synchronization problem is resolved pretty easily. When the user selects items from the tree, you retrieve the list of selected QStandardItems, look them up in the map, and set the matching QGraphicsItem to selected. Likewise, when the user selects items in the graphics view, you do the reverse lookup and set the QStandardItem as selected.
    Exactly. The solution I came up with is a templated bi-directional hash map:
    Qt Code:
    1. template <class U, class V>
    2. class BidirectionalHashMap
    3. {
    4. public:
    5. U find(V v) { return mapVU.find(v).value(); }
    6. V find(U u) { return mapUV.find(u).value(); }
    7. void insert(U u, V v) { mapUV.insert(u,v); mapVU.insert(v,u); }
    8.  
    9. private:
    10. QHash<U, V> mapUV;
    11. QHash<V, U> mapVU;
    12. };
    To copy to clipboard, switch view to plain text mode 

    It works great for what I needed to accomplish.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,319
    Thanks
    316
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Synchronizing behaviour between QListView and QGraphicsScene

    It works great for what I needed to accomplish.
    At least as long as either of the QHash::find() calls in your two find() methods doesn't return QHash::end(). Then the following call to QHash::iterator::value() will assert. If your code guarantees that you will never try to find() a key that isn't in the map, this won't be a problem.

  3. #3
    Join Date
    May 2009
    Posts
    16
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Synchronizing behaviour between QListView and QGraphicsScene

    Ah, good point. Yes, I don't see any case where I would be trying to find a key that isn't in the bi-map.

Similar Threads

  1. Strange behaviour in QGraphicsScene
    By yagabey in forum Qt Programming
    Replies: 1
    Last Post: 20th July 2011, 02:01
  2. synchronizing events
    By zaphod.b in forum Qt Programming
    Replies: 0
    Last Post: 14th July 2009, 16:29
  3. Synchronizing QFtp
    By arun_vj in forum Qt Programming
    Replies: 0
    Last Post: 5th November 2008, 12:31
  4. Synchronizing two GraphicsScenes
    By manojmka in forum Qt Programming
    Replies: 13
    Last Post: 3rd December 2007, 09:59

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
  •  
Qt is a trademark of The Qt Company.