zosodk69
28th August 2009, 18:13
Sorry to drudge this up as it seems to get asked every couple months around here. I've wasted a bit of time on this so before I lay down any more code I'd like to air out my ideas in this forum.
I'm working on an editor for a game I'm creating. The game is tile based so the editor consists of a grid with various QGraphicsItems representing floors, doors, walls, etc. At first glance it seems I could greatly benefit from applying the model/view paradigm to QGraphicsScene but this has been a rather frustrating endeavor akin to jamming a square peg into a round hole. There doesn't seem to be any published best-practice for combining these frameworks (let alone example code).
I'm leaning towards having both QGraphicsScene and QGraphicsView owned by a subclass of QAbstractItemView. I'd subclass QAbstractItemModel and tailor the data method to return QGraphicsItems.
The advantage I can see of using this method is that I won't have to sync my underlying data with the graphical representation (a general argument for using Interview). I wouldn't be able to have multiple QGraphicsViews pointing to the same scene with this methodology though.
Is this the right way to go about this?
Should I even be using Interview to solve this problem? In earlier iterations of this project my code would change the back-end data structure when creating or deleting graphics items (synchronizing the two). While this works OK I've found it very difficult to separate logic from gui code.
I'm working on an editor for a game I'm creating. The game is tile based so the editor consists of a grid with various QGraphicsItems representing floors, doors, walls, etc. At first glance it seems I could greatly benefit from applying the model/view paradigm to QGraphicsScene but this has been a rather frustrating endeavor akin to jamming a square peg into a round hole. There doesn't seem to be any published best-practice for combining these frameworks (let alone example code).
I'm leaning towards having both QGraphicsScene and QGraphicsView owned by a subclass of QAbstractItemView. I'd subclass QAbstractItemModel and tailor the data method to return QGraphicsItems.
The advantage I can see of using this method is that I won't have to sync my underlying data with the graphical representation (a general argument for using Interview). I wouldn't be able to have multiple QGraphicsViews pointing to the same scene with this methodology though.
Is this the right way to go about this?
Should I even be using Interview to solve this problem? In earlier iterations of this project my code would change the back-end data structure when creating or deleting graphics items (synchronizing the two). While this works OK I've found it very difficult to separate logic from gui code.