Connect Graphics Scene to SQL relational Model
There is an example distributed with Qt called "diagramscene". In the application, the user creates a variety of graphics objects in the Graphics Scene. I am interested in saving this data in a relational database. One table with the list of objects and the second table with the connections between the objects. What would it take to connect the objects to a QSQLRelationalTableModel"? What classes do I need to allow retrieving the data, edit, and saving the data?
Re: Connect Graphics Scene to SQL relational Model
I would approach this from the opposite direction. Instead of having a graphics scene update a database, have the database update the graphics scene. The user interactions add entries to the database model, which then issues signals to cause updates to the scene as displayed on screen.
I've done something similar in my current application - everything that is displayed onscreen is implemented as a class derived from QAbstractItemModel, and there are "glue" classes that listen for model signals and invoke updates to the graphics.
If you derive a class from QGraphicsScene and add slots to connect it to the SQL model's signals (modelReset(), dataChanged(), etc.) as well as storing a pointer to the model, then you can use the model's signals to update the scene. The QGraphicsView instances attached to the scene will automatically update with changes to the scene.
Your database will also have to keep track of the parent-child relationships between graphics items, unless your design has all objects as top level members of a scene.