Results 1 to 5 of 5

Thread: How do I design this code?

  1. #1
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How do I design this code?

    I have been using MVC approach for many years, and now users have a new request that I have to provide.

    Let's say the users want to visualize a house that has a kitchen, several bed rooms, a guest room, and a garage. users want to create several views that can look at different parts of the house (see attachment draft). Each view is an MDI subwindow, which can be activated one at a time. The left panel is a tree widget that lists the house and its components.

    When View 2 is activated, the items selected or unselected in the left panel will apply only to view 2. When view 1 is activated (by clicking on the view 1's title bar), the left panel will immediately show the selection state of the view 1, and then the items selected or unselected in the left panel will apply only to view 1, etc.

    What is the best approach to design this project? Obviously, it has a Data Model, several View Models, and several Views. But how about the controller? Or should I use other design pattern?

    Model-view-viewModel (MVVM) doesn't seem to work either...

    Any suggestion is very welcome!

    house.png

  2. #2
    Join Date
    Mar 2010
    Location
    Heredia, Costa Rica
    Posts
    257
    Thanks
    24
    Thanked 17 Times in 14 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: How do I design this code?

    Hi,

    More information is needed, however I put some ideas in your image. Hope it helps.

    Carlos.

    house2.jpg

  3. #3
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I design this code?

    When View 2 is activated, the items selected or unselected in the left panel will apply only to view 2. When view 1 is activated (by clicking on the view 1's title bar), the left panel will immediately show the selection state of the view 1, and then the items selected or unselected in the left panel will apply only to view 1, etc.
    It isn't clear from your description what the "views" contain. Does each "view" correspond to a single room of the house, or does each "view" show the entire house, but with only the selections that are active for that view? Do these views need to be interactive? (That is, can the user click on things in the view and move them or see details about them?)

    Contrary to the other reply, I would implement the views as QGraphicsView, and map between your data model and QGraphicsScene instances. Selections from the tree would control the visibility status of the graphics items in a particular view.

  4. #4
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How do I design this code?

    Thank you all for suggestions.

    Let me describe it in more detail. Let's say "View 2" is currently the active view, and looking at Bed Room 1 and Bed Room 2. Now click on "View 1" to make View 1 active (at the same time, View 2 is deactivated), and now select "Kitchen" and keep all others unselected. View 1 should now show only "Kitchen".

    When user click on "View 2" again, the selection state should change to what View 2 is showing: that is, Bed Room 1 and Bed Room 2 is selected, while all other items are unselected, etc...

    For simplicity, let's not do any interactions at this stage...

    At the end, user should be able to save the Data Model, and the View Models, then restore them at later time...

    Implementation is not an issue. The problem is what design pattern should be used? I am looking at this article: http://www.codeproject.com/Articles/...MVVM-Explained. But this article is not enough....

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: How do I design this code?

    In the Qt world, I don't think there is anything equivalent to a "ViewModel". The ViewModel implementation is spread over a whole collection of classes:

    The QAbstractItemModel takes on some of the duties of the ViewModel, by determining the presentation of items through the various Qt:ItemRole types. QAbstractProxyModel and its derivatives also have some aspects of the ViewModel, by enabling items to be filtered or rearranged in between the model and the view. QItemDelegate performs some editing functions in conjunction with the view, and QItemSelectionModel handles selection.

    So, even though I know you don't want to hear about "implementation":

    For your purposes (as long as you don't need interaction in the "view"), a QItemSelectionModel instance for each of your "views" can serve as the glue between that view and the tree. When each view is activated (see QMdiSubWindow::windowStateChanged()), it should emit a signal (like "selectionModelChanged( QItemSelectionModel * )"). These signals are all connected to a corresponding slot in the tree view ("onSelectionModelChanged( QItemSelectionModel * )") which changes the current selection model and updates the selections to match.

    Sharing a selection model between multiple views based on the same underlying model is a standard way to synchronize selections between them.

Similar Threads

  1. Replies: 4
    Last Post: 20th August 2010, 13:07
  2. Replies: 0
    Last Post: 1st August 2009, 08:05
  3. Replies: 1
    Last Post: 15th April 2008, 23:15
  4. qt design and adding other code
    By cxl2253 in forum Qt Tools
    Replies: 2
    Last Post: 1st February 2007, 17:12
  5. Dialog and code design issue
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 24th September 2006, 17:54

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.