Results 1 to 2 of 2

Thread: QAbstractProxyModel MapToSource Problem

  1. #1
    Join Date
    Feb 2010
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QAbstractProxyModel MapToSource Problem

    Hi,

    I'm trying to develope a complex Model with different Proxymodels. The Main-Model is a Tree with different Items based on a ItemBaseClass.
    The first Proxymodel is a QSortFilterProxyModel for the tree-Navigation-Widget. This works.

    Qt Code:
    1. Tree:
    2. -Item1
    3. ---sub1
    4. ---subsub1
    5. ---subsub2
    6. ---sub2
    7. -Item2
    8. ---sub3
    9.  
    10. Table of sub1:
    11. subsub1-name | subsub1-property
    12. subsub2-name | subsub2-property
    To copy to clipboard, switch view to plain text mode 

    The second Proxymodel is to show and edit a TreeItem with subElements in a table.
    This works a bit. The Elements are shown in the table, but I cannot insert or delete rows.
    My problem is that I do not know how to implement the MapToSource/MapFromSource methods..
    So here are my simple implementations:
    Qt Code:
    1. QModelIndex TFSEditorItemModel::mapFromSource(const QModelIndex &source) const{
    2. return index(source.row(), source.column(), source.parent());
    3. }
    4.  
    5. QModelIndex TFSEditorItemModel::mapToSource(const QModelIndex &proxy) const {
    6. if(!proxy.isValid())
    7. {
    8. return QModelIndex();
    9. }
    10. return sourceModel()->index(proxy.row(), proxy.column(), proxy.parent() ) ;
    11. }
    To copy to clipboard, switch view to plain text mode 

    If I try to use mapToSource e.g. to insert a row through the sourceModel, I never get a correct sourceIndex. Especally the proxy.parent-Index is not valid, so the sourceModel cannot create a valid Index in the sourcetree.
    How can I get an index of the table-root-item from the sourceModel? I have a Pointer to the Item (the tables root-item) but no Index. I think I cannot remember this Index because it can change..?

    I hiope you can help me or give a reference to a good example. I tried to find something, but the results did not help me.

    greets
    david

  2. #2
    Join Date
    Dec 2011
    Posts
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QAbstractProxyModel MapToSource Problem

    return sourceModel()->index(proxy.row(), proxy.column(), proxy.parent() ) ;

    proxy.parent is an index of proxy model, you must pass an index of source model in this case

Similar Threads

  1. How to subclass QAbstractProxyModel
    By skycrestway in forum Qt Programming
    Replies: 2
    Last Post: 22nd October 2010, 23:35
  2. Replies: 3
    Last Post: 6th February 2010, 20:07
  3. QAbstractProxyModel to do a Tree
    By xgoan in forum Qt Programming
    Replies: 3
    Last Post: 18th November 2008, 17:31
  4. Help with QAbstractProxyModel
    By killerwookie99 in forum Qt Programming
    Replies: 9
    Last Post: 12th September 2008, 22:13
  5. QAbstractProxyModel::mapToSource performance issues
    By maximAL in forum Qt Programming
    Replies: 2
    Last Post: 14th January 2008, 22:48

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.