Results 1 to 9 of 9

Thread: Model / View - Design Question

  1. #1
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Model / View - Design Question

    Hi !

    I have a tree "domain model" with a lot of different nodes.
    Access to the domain model is done through QAbstractItemModel which acts more like an adapter to the domain model.
    The views (tree view and table view - like an explorer) are attached through two proxy models to the adapter.
    The problem is that the table view shows a lot of different data (but partially the same as the tree view) and this depends on the selected node. Unfortunately setRootIndex() which is used to select what has to be shown in the table view doesn't provide something to adjust the header of the table view (the header/data should come from the item set by setRootIndex() and not the model itself).
    Providing all possible headers and filtering through a proxy (depending on the node type) is complicated for such a lot of different data/headers.
    Using different Q...Models (one always attached for the tree and one dynamically attached to the selected node) attached to the domain model would imply that I have to do the synchronisation by my self (That's not what I want, when Qt provides this already)

    It looks like a sub-model (table) within the model (tree).
    So what's the best solution for that problem ?

    Example:

    tree view
    ----------
    node1
    ...+--- node11
    ...+--- node12
    .............+--- node 121
    ....

    table view node1 selected:
    =================
    name | h1 | h2 | h3 | h4
    -------------------------------
    node11 | x1 | x2 | x3 | x4
    node12 | y1 | y2 | y3 | y4

    table view node 121 selected:
    ==================
    name | h1 | h7
    --------------------------------
    node121 | a1 | a7

    .... (lets assume 30 different nodes types, and a lot of different columns)

    many thanks for your help,
    bernd

    Note: mixing up the tree content with the table content looks like a little bit of violation of "separation of concernce" to me. nevertheless - it's legacy code and can't be changed.
    Last edited by antarctic; 4th June 2009 at 23:48. Reason: updated contents

  2. #2
    Join Date
    Apr 2007
    Location
    Sunny Darwin, NT Australia
    Posts
    186
    Thanks
    29
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Model / View - Design Question

    So you want to have different nodes with different number of columns and headings ?

  3. #3
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model / View - Design Question

    That's exactly what I want.
    Selecting a node in the (left) tree shows the content (right) in the table. And there are a lot of different nodes. Each node type has different header and data.

  4. #4
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model / View - Design Question

    Solved with two different Q...Models.
    click on the item in the tree view prepares a model and view in the table view,
    depending on the node type.
    synchronisation must be implemented separate.

    best regards,
    bernd

  5. #5
    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 - Design Question

    To me it seems a simple proxy and manipulation with QAbstractItemView::rootIndex() would be sufficient...
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    antarctic (8th June 2009)

  7. #6
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model / View - Design Question

    I did an implementation with two proxies, but it was really ugly.
    - I had to analyse the content of the nodes for the differnt views (specially requirement).
    - You can't create an index for the source model (you must store it, which results in a lot of duplicated QModelIndexes, or you have to implement a workaround, to be able to set the model pointer correct in the index). for a huge amout of data not really nice.
    - The nodes knows the header and with proxies you have to set the headers far away from the nodes.

    Returning a lot of different columns in one model (all available columns for all nodes) and then filtering out what's necessary is painful.

    suppose (a concrete example - the real application is much more painful):

    room
    ..+device
    ....+-chip
    ......+-pin

    where the headers are
    room: floor, size, costs, ............
    device: supplier, pin-count, supply-voltage, .......
    pin: mode, trigger-voltage, period, ...........
    ...
    ...
    ...

    it's different from file browser or something else, where you show more or less the
    same data for each node. one model with one header.

    best regards,
    bernd

  8. #7
    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 - Design Question

    Aren't you overcomplicating things? Try to break your functionality into fundamental properties and then start thinking about the architecture of the model. If you have to store indexes instead of calculating them then it means your design is wrong.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #8
    Join Date
    Jun 2009
    Posts
    11
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Model / View - Design Question

    How to calulate the source model index from the proxy model index (the other direction is no problem). Especially for a tree model ? Seems this problem have other people too :

    http://api.kde.org/4.2-api/kdepim-ap...pp-source.html

    00055 namespace {
    00056 // Think this is ugly? Well, it's not from me, it comes from QProxyModel
    00057 struct KDPrivateModelIndex {
    00058 int r, c;
    00059 void *p;
    00060 const QAbstractItemModel *m;
    00061 };
    00062 }

    And make a static_cast :-(
    (There is another link, where it's better documented).

    I can't think about restructuring the domain model. This is legacy code and it must not be changed (software requirement). (by the way, I think it isn't changeable anyway. 15 years growing code - with a really huge database behind. And no one has money today. It's a shame :-)

    I would appreciate to know a good source about proxies using Q...Model, or when you can post something.

    best regards,
    Bernd

    Nevertheless: QT is the best GUI framework I've ever seen.

  10. #9
    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 - Design Question

    If someone bases his code on deprecated QProxyModel then I have no comments on that

    As for your situation - I mean the design of the internals of the model, not what it represents.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    antarctic (8th June 2009)

Similar Threads

  1. Replies: 1
    Last Post: 18th November 2009, 23:21
  2. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  3. Model, View and Proxy
    By No-Nonsense in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2006, 08:50
  4. Model - View Programming doubt.
    By munna in forum Qt Programming
    Replies: 4
    Last Post: 28th April 2006, 13:01
  5. Replies: 6
    Last Post: 20th April 2006, 10:23

Tags for this Thread

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.