QAbstractProxyModel , mapToSource() and mapFromSource()
I would like to browse through an example where QAbstractProxyModel is sub-classed and the above mentioned functions are over-ridden. I have checked the examples that come along with the qt installation, but did not find any. Let me know if i miss.
If any one aware of any open source examples , please refer them to me.
I really like to have some idea of this concept. I already have tree model shown in the tree view. i would like to create a proxy model that flatten down the source tree model and user the proxy model in the completer to provide user hint.
Again , it has been quite a while i am stuck with this issue. So please let me know anyone knows anything about this issue!!!!
what exactly is your problem, I did not get it. I already iomplemented proxy models and have overwritten mapToSource/mapFromSource. It works.
So can you please give us moire details about your problem?
Like "this":http://qt-project.org/wiki/Proxy_model_example_code ?
Please Check the following link:
!http://www.student.itn.liu.se/~sajis997/nodetree.png(Node Hierarchy tree)!
As you an see the tree view is loaded. I have another line edit widget which helps the users to find the node using the QCompleter. QCompleter works level by level in the tree view and i want to provide the user with the hint for all levels and i thought about flattening the tree down in the proxy model.
The manual also sys the if i sub-class the proxy model i must over-ride the following two functions :
mapToSource() and mapFromSource()
I am not sure how to over-ride these two functions and specifically, once i say about flattening down i mean that all the tree item will be under QModelIndex(). For the time being, i can browse through my customized tree recursively and print the tree item. I want to re-assign all the tree item under the QModelIndex() - which is the invisible root item. I believe all my requirements will have to be implemented to the above mentioned functions.
Am i addressing the issue properly ?
Will be looking forward to more on this issue.
I think I got it. The problem you have is, you need a mapping of the flat proxy items to the hierarchical tree items. This is what must be done in mapToSource/mapFromSource.
If you know, you tree will not be deeper than 4 levels and no level will contain more then 255 elements, you could go something like:
Each QModelIndex has a custom data (I think an int?)
This could contain in each byte the index of the corresponding tree item in the level, like:
Tree item: X3DNode --> 0x01FFFFFF (FF would mean not used!)
Tree Item: BooleanFilter --> 0x0103FFFF (FF would mean not used!)
Tree Item: PointNormalClipPane --> 0x010801FF (FF would mean not used!)
If these restrictions do not work for you, you must find some other mapping that fits.
mapToSouce is called with a QModelIndex of the proxy and must return a QModelIndex of the source model. You additionaly MUST handle the correct QModelIndex creation.