March 27, 2012

sajis997 sajis997
Lab Rat
18 posts

QAbstractProxyModel , mapToSource() and mapFromSource()

 

Hi forum,

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!!!!

Regards
Sajjad

4 replies

March 27, 2012

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi Sajjad,

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?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

March 27, 2012

hmuelner hmuelner
Lab Rat
29 posts

Like this [qt-project.org] ?

 Signature 

Helmut Mülner

March 27, 2012

sajis997 sajis997
Lab Rat
18 posts

Hi

Please Check the following link:

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.

Thanks
Sajjad

March 28, 2012

Gerolf Gerolf
Area 51 Engineer
3210 posts

Hi Sajjad,

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 —> 0×01FFFFFF (FF would mean not used!)
Tree Item: BooleanFilter —> 0×0103FFFF (FF would mean not used!)
Tree Item: PointNormalClipPane —> 0×010801FF (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.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

 
  ‹‹ [SOLVED] Can we set specific Network proxy for QWebView      Roadmap to support further features in XQuery ››

You must log in to post a reply. Not a member yet? Register here!