Results 1 to 4 of 4

Thread: "un-flattening" a data structure and when mapFromSource is called

  1. #1
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default "un-flattening" a data structure and when mapFromSource is called

    After reimplementing mapFromSource and mapToSource in my abstractProxy, I noticed mapFromSource is never called implicitly (even in the transpose example). What is the purpose of this method(mapFromSource) if it is never implicitly called by the views/models? I was thinking this was the method I needed to implement in order to accomplish a different view of the data.

    Here's my problem, my data is virtually flat with metadata describing a hierarchy:

    item1
    item2
    item3
    item4 [parent: item3]
    item5 [parent: item4]


    In my treeview I'd like it displayed:
    item1
    item2
    item3
    ----item4
    ---------item5

    Would mapTo handle this alteration? If so what is mapFrom for? Or do I have to permanently alter the actual data structure to show the hierarchy?

    TYVM,

    BB
    Last edited by BreakBad; 19th June 2012 at 18:55.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: "un-flattening" a data structure and when mapFromSource is called

    mapFromSource() is used extensively in both the QIdentityProxyModel and QSortFilterProxyModel so perhaps you should look into the source for those classes to see what you are missing. Also check that your declaration of mapFromSource() correctly matches the virtual you are trying to re-implement.

    Do you also need to display the model in its flat form, say in a table view? If not you could just wrap the flat data structure with a QAbstractItemModel that presents a tree view and dispense with the layered proxy model.

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

    BreakBad (20th June 2012)

  4. #3
    Join Date
    Jun 2012
    Posts
    25
    Thanks
    7
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: "un-flattening" a data structure and when mapFromSource is called

    Quote Originally Posted by ChrisW67 View Post
    mapFromSource() is used extensively in both the QIdentityProxyModel and QSortFilterProxyModel so perhaps you should look into the source for those classes to see what you are missing. Also check that your declaration of mapFromSource() correctly matches the virtual you are trying to re-implement.

    Do you also need to display the model in its flat form, say in a table view? If not you could just wrap the flat data structure with a QAbstractItemModel that presents a tree view and dispense with the layered proxy model.
    Thank you for the response,

    I was reimplementing QAbstractProxyModel, maybe that is why I didn't see mapFromSource being utilized?

    And you are correct, I do NOT need to render the flat form of the data. Therefore in the root AbstractItemModel I could modify parent() and child() methods to simulate the hierarchy, if that is what you meant?

    Thank you very much,

    BB

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: "un-flattening" a data structure and when mapFromSource is called

    QAbstractProxyModel has no functionality of its own, you need to implement it. I pointed out other implementations so you could see how the mapping functions were being used internally and the sort of things they did.

    And you are correct, I do NOT need to render the flat form of the data. Therefore in the root AbstractItemModel I could modify parent() and child() methods to simulate the hierarchy, if that is what you meant?
    Yes, that's the sort of thing I meant. There is still some work to do to get the model indexes right but I think it will be less confusing.

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

    BreakBad (21st June 2012)

Similar Threads

  1. Replies: 3
    Last Post: 26th August 2011, 13:44
  2. Replies: 1
    Last Post: 7th April 2010, 21:46
  3. Replies: 3
    Last Post: 25th August 2009, 13:03
  4. Replies: 3
    Last Post: 8th July 2008, 19:37
  5. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19: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.