PDA

View Full Version : MVC Example for SQL to GraphicsView ?



otternase
2nd June 2010, 23:12
Hi

I'm searching for examples or hints which could help me finding a way to do this task:

In a table (or view) of a database items are managed, which are to be displayed in a QGraphicsScene. Each line in the table is one item on the GraphicsScene, the position being determined by X,Y columns of the table.
Now I want the database automatically updated when the item is moved on the canvas by the user and vice versa the view automatically updated when the database table changes. I guess this calls for a MVC-pattern. But I couldn't find any examples of SQL-models connected to a GraphicsScene as the View and Controller? Is this possible?

Every help appreciated
Markus

tbscope
3rd June 2010, 05:43
This is certainly possible and a very nice thing to have. I already have a similar idea for a project I'm working on.
I guess, you basically need to have a combination of QGraphicsScene and QSqlQueryModel. Then you can use the combination for both the table and the graphics view. Moving an item in the scene for example is the same as editing an item in the model. Thus both views (and the database) are changed at once.

But it'll require some work to integrate both the scene and the model.

tbscope
3rd June 2010, 06:35
Thinking about it a little bit more:

I guess the easiest way is to crreate a graphics scene that can take an abstract item model.
The you can write something like:

ModelScene *myModelScene = new ModelScene;
myModelScene->setModel(mySqlQueryModel);

The graphics scene then becomes a "delegate" between the abstract item model and the graphics view.

aamer4yu
3rd June 2010, 06:44
I guess it will require implementation of QGraphicsModelView instead of scene and model. But no doubt even this will be complex since Graphics View framework is in itself a MVC design.
Here we want the user to have a graphical view of the model. Something like QLIstWidget class, which maintains a model of its own.

So something like -
class QGraphicsModelView : public QAbstractItemView
{
}

design will be better. It will also help in model / selectionModel choices.
Its just my thinking, though I can be wrong.

Still, a really good topic and feature to discuss.:cool: