Results 1 to 6 of 6

Thread: Proxy for TreeView

  1. #1
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Proxy for TreeView

    Hello,

    I'm trying to create a proxy for the simpletreemodel from the examples. But I have a problem translating the parent relation. The first level beneath the root works fine but my proxy doesn't get the right parents for the subitems.
    Qt Code:
    1. QModelIndex CUserProxyNoMeta::index(int r, int c, const QModelIndex& parent) const
    2. {
    3. if (!hasIndex(r, c))
    4. return QModelIndex();
    5. return createIndex(r, c);
    6. }
    7.  
    8. QModelIndex CUserProxyNoMeta::mapFromSource(const QModelIndex& sourceIndex) const
    9. {
    10. if (!sourceIndex.isValid()){
    11. return QModelIndex();
    12. }
    13.  
    14. return index(sourceIndex.row(), sourceIndex.column());
    15. }
    16.  
    17. QModelIndex CUserProxyNoMeta::mapToSource(const QModelIndex& proxyIndex) const
    18. {
    19. if (!proxyIndex.isValid()){
    20. return QModelIndex();
    21. }
    22. return sourceModel()->index(proxyIndex.row(), proxyIndex.column());
    23. }
    24.  
    25. QVariant CUserProxyNoMeta::data(const QModelIndex& ind, int role) const
    26. {
    27. return sourceModel()->data(mapToSource(ind), role);
    28. }
    29.  
    30. QModelIndex CUserProxyNoMeta::parent(const QModelIndex& index) const
    31. {
    32. if (!index.isValid()){
    33. return QModelIndex();
    34. }
    35. return mapFromSource(sourceModel()->parent(mapToSource(index)));
    36. }
    37.  
    38. int CUserProxyNoMeta::rowCount(const QModelIndex& ind) const{
    39. return sourceModel()->rowCount(mapToSource(ind));
    40. }
    41.  
    42. int CUserProxyNoMeta::columnCount(const QModelIndex& ind) const
    43. {
    44. return sourceModel()->columnCount(mapToSource(ind));
    45. }
    To copy to clipboard, switch view to plain text mode 

    How can I get the right parent relations for the proxy?

    Thanks,
    Patrik

  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: Proxy for TreeView

    You are not taking the "parent" index into consideration when mapping indexes. I don't know what your proxy is supposed to do, so I can't suggest a solution.

  3. #3
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Proxy for TreeView

    Hi wysota,

    in the first step I just wanna get my model into the proxy. Later I want to use the proxy to adapt the model. I tried to get the parent in the transformation but didn't succeeded. In the model the Item is used to get the parent, but as far as I understand the proxy concept it is not the right way to work over the items and I don't know how to get the parent over the index in this approach.

    thanks,
    Patrik

  4. #4
    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: Proxy for TreeView

    Maybe you should start with QSortFilterProxyModel instead of the abstract one?

  5. #5
    Join Date
    Feb 2008
    Posts
    10
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Proxy for TreeView

    Hi wysota,

    I made some tests with the QSortFilterProxy but that doesn't fit for the things I want to make

    Cheers

  6. #6
    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: Proxy for TreeView

    And what do you want to make? Looking at your code I see you are trying to do 1-1 mapping and that's exactly what the sort filter proxy does out of the box.

Similar Threads

  1. Custom proxy model issue
    By Khal Drogo in forum Qt Programming
    Replies: 13
    Last Post: 30th November 2007, 12:41
  2. QT Network Proxy Configuration
    By suresh in forum Qt Programming
    Replies: 7
    Last Post: 28th September 2007, 01:16
  3. QTcpSocket - Proxy problem
    By vishesh in forum Qt Programming
    Replies: 1
    Last Post: 26th September 2007, 23:48
  4. Model and Proxy
    By larry104 in forum Qt Programming
    Replies: 1
    Last Post: 4th August 2006, 21:05
  5. 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.