Results 1 to 2 of 2

Thread: Model/View Confusion in QTreeView - number of rows

  1. #1
    Join Date
    Jul 2007
    Location
    New York
    Posts
    45
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Model/View Confusion in QTreeView - number of rows

    I am trying to create a model/view system for plugins. Each plugin has different attributes, which should be displayed in a QTreeView.

    I am confused, however, if the view's number of rows does not match the number of items in the model.

    For instance, I want to display the plugins like this:
    Qt Code:
    1. (root)
    2. +-Transform Nodes 2 nodes
    3. | +-Move
    4. | | +-Inputs
    5. | | | input1 image
    6. | | +-Attributes 2 attributes
    7. | | Xpos float
    8. | | Ypos float
    9. | +-Rotate
    10. | +-Inputs
    11. | | input1 image
    12. | +-Attributes 1 attribute
    13. | angle float
    14. +-Color Nodes 2 nodes
    15. +-Brightness
    16. | +-Inputs
    17. | | input1 image
    18. | +-Attributes 1 attribute
    19. | amount float
    20. +-etc... etc...
    To copy to clipboard, switch view to plain text mode 

    which leads me to believe that I have 2 groups, and 2 children in each group (potentially many of each, but for this example...), and certain rows have two columns, but others only have one. The inputs and attributes are not child items, they only exist in the view and are really members of pluginItem.

    The problem is, while the model has 2 groups of 2 items, the view has 19 (and more) rows. Also, another problem is that the row number of a particular item is determined by which parents are expanded/collapsed (but this may already be contained in the QTreeView code).

    Does it make more sense to:

    1) create a pluginGroup class which contains pluginItem children that reports many rows when displayed, or
    2) create a pluginGroup class which contains pluginItem children that contains pluginDisplayGroup children that contains pluginDisplayAttribute children, or
    3) create a generic pluginRow item which may be either a child or parent and has a flag in it to determine usage, or
    4) create a pluginItem array in the model, which stores the group name, where the view somehow splits the rows based on unique group names, or
    5) some other framework that I'm not thinking of.

    Another, more minor thing, is that if I want the view to expand/collapse based on a single click... where do I insert this trigger? Do I need a delegate?

    I would like to use 4 or 1 above, but I am confused about where the additonal rows are generated... 4 makes the most sense, because that's what the model really should be.
    Last edited by themolecule; 6th August 2007 at 01:10.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Model/View Confusion in QTreeView - number of rows

    Quote Originally Posted by themolecule View Post
    I am confused, however, if the view's number of rows does not match the number of items in the model.
    According to what you describe - it does.

    which leads me to believe that I have 2 groups, and 2 children in each group (potentially many of each, but for this example...), and certain rows have two columns, but others only have one. The inputs and attributes are not child items, they only exist in the view and are really members of pluginItem.
    What is "pluginItem"? What does it inherit?

    The problem is, while the model has 2 groups of 2 items, the view has 19 (and more) rows.
    Each of the "items" has children of its own which increases the total number of items in the view.

    Also, another problem is that the row number of a particular item is determined by which parents are expanded/collapsed (but this may already be contained in the QTreeView code).
    What do you need the view row number for?

    5) some other framework that I'm not thinking of.
    Depends what you want the model to do in the first place... The model is just a data container and the view is a mean to represent some data visually, so first you should decide what you want to visualize and what do you want to store in the model.

    Another, more minor thing, is that if I want the view to expand/collapse based on a single click... where do I insert this trigger? Do I need a delegate?
    The delegate (at least Qt item-view delegate) doesn't handle that. Connect to the collapsed() or expanded() signals in QTreeView using a custom slot and collapse/expand all children accordingly. Just make sure not to fall into an endless loop (for example by checking if the parent is already collapsed/expanded).

Similar Threads

  1. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  2. Replies: 6
    Last Post: 5th March 2006, 21:05

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.