Results 1 to 4 of 4

Thread: MVC Example for SQL to GraphicsView ?

  1. #1
    Join Date
    Jun 2010
    Posts
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default MVC Example for SQL to GraphicsView ?

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: MVC Example for SQL to GraphicsView ?

    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.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: MVC Example for SQL to GraphicsView ?

    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:
    Qt Code:
    1. ModelScene *myModelScene = new ModelScene;
    2. myModelScene->setModel(mySqlQueryModel);
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: MVC Example for SQL to GraphicsView ?

    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.

Similar Threads

  1. Drawing in GraphicsView
    By er.soodneha in forum Newbie
    Replies: 1
    Last Post: 26th April 2010, 00:00
  2. Graphicsview??
    By Screeze in forum Newbie
    Replies: 2
    Last Post: 5th July 2009, 17:01
  3. graphicsview Problem
    By tampstaffs in forum Qt Programming
    Replies: 6
    Last Post: 8th February 2009, 19:59
  4. GraphicsView Framework
    By RY in forum Newbie
    Replies: 1
    Last Post: 10th September 2008, 08:03
  5. QT GraphicsView Help
    By mistertoony in forum Qt Programming
    Replies: 15
    Last Post: 15th February 2007, 04:17

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.