Results 1 to 3 of 3

Thread: Model, View and Proxy

  1. #1
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Model, View and Proxy

    I am fairly new to Qt. I have read through the Qt 4.2.1 documentation, but some questions remain:

    I have some data inside a tree like this:
    A
    - 1
    - x y z
    - 2
    - x y z
    - a b c
    - d e f
    B
    - 1
    -x y z
    C
    - 1
    -x y z

    I want to use the MVC concept to display and edit this data in two views: one tree view and one table view:

    table view:
    A
    - 1
    - 2
    B
    - 1
    C
    - 1

    list view (depending on tree view selection; here A 2 was selected by the user):
    x y z
    a b c
    d e f

    Further the tree view can be hidden and the table view should show all data in a flat view:
    A 1 x y z
    A 2 x y z
    A 2 a b c
    A 2 d e f
    B 1 x y z
    C 1 x y z

    How would I implement this correctly?

    - Do I implement two models, one for the tree view and one for the table view or do I implement one model to access all data and two proxies filtering the data needed for each view?

    - Would I add another filtering proxy to the table view that filters the rows based on if the tree view is shown and subclass the view to hide the first two colums if needed? Or would the proxy filter the colums also?

    - How do I notify the model about changes inside the data that occured outside the MVC?

    - Where would I add the editing delegates? To the model or the proxy? I only want editing to be done inside the table view. Changes to the tree view data is done internally (some buttons).

    Thanks in advance, sorry for my bad english, greetings from Germany,
    -Jens
    Last edited by No-Nonsense; 20th November 2006 at 17:33. Reason: updated contents

  2. #2
    Join Date
    Jan 2006
    Location
    Alingsås, Sweden
    Posts
    437
    Thanks
    3
    Thanked 39 Times in 39 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model, View and Proxy

    - You will need proxies to achieve all your views. Look at the proxy classes in the Qt docs and the FlaxProxy class here http://www.thorsen-consulting.dk/software.html .

    - Delegates can be added to the view - so you do not have to worry about adding it to the proxy or the model.

    - Changes from outside can be made by calling setData which takes care of notifying the views.

  3. The following user says thank you to e8johan for this useful post:

    No-Nonsense (21st November 2006)

  4. #3
    Join Date
    Nov 2006
    Posts
    35
    Thanks
    25
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model, View and Proxy

    So I would implement one model and one proxy for each view and maybe a third proxy on top of the table view proxy to filter the rows (& colums)?

    Regarding the filtering of columns: is this better done as proxy (I think I will need to remap the indices then?) or to subclass the view and hide (as explained in the book Practical Qt) the unneeded columns?
    I imagine hiding is easyer (but not good practice) as I would not have to change which column wich delegate is used?

    I do not want to to use the model when changing data from the outside of the MVC using setData. I expect there is a slot to notify the model of changes (e.g. rows, colums or whole data)?
    This is because the datastructure might be used in another non Qt project and mainly because the operations on it might change the whole tree. When calling the operations from button's slots, I know if this changes one row/column, cell or if this can change the whole tree. So I could notify the model myself.

    Thanks in advance,
    -Jens

Similar Threads

  1. Sharing Selections between Model and ProxyModel
    By mentat in forum Qt Programming
    Replies: 14
    Last Post: 27th January 2010, 17:31
  2. data, model and tree view
    By larry104 in forum Qt Programming
    Replies: 17
    Last Post: 3rd July 2006, 14:43
  3. Filter Proxy Model to Autoupdate View
    By Big Duck in forum Qt Programming
    Replies: 1
    Last Post: 1st June 2006, 20:32
  4. setIndexWidget and proxy interaction
    By Derf in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2006, 18:15

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.