PDA

View Full Version : "un-flattening" a data structure and when mapFromSource is called



BreakBad
19th June 2012, 19:47
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

ChrisW67
20th June 2012, 07:06
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.

BreakBad
20th June 2012, 15:40
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

ChrisW67
21st June 2012, 00:21
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.