PDA

View Full Version : QCompleter - isslplpue



sajis997
13th March 2012, 23:01
Hello forum,

I am sure that some one over here have used QCompleter somewhere in their project and i need you help. The manual says something related to file system.

How to customize it if it a customized item model derived from QAbstractItemModel ?

I have a tree model preety much same as the simple tree model example. A snapshot might help:

7497


I want the completer to provide the user the look-up hint in such a manner that if the user type X3D, then all the names that starts with "X3D...." pop up in the lookup completion hint.

I think in that we have to lookup all the levels at a time. What do you think? I already did the following changes, but i am not getting what i need and i believe i am far away from what i want to get.



QCompleter *completer = new QCompleter(this);
completer->setModel(m_h3dTreeModel);
m_nodeHighlightingEditor->setCompleter(completer);




I need more hints to achieve this behavior.

Let me know if i am clear enough with my requirement explanation.


Regards
Sajjad

ChrisW67
14th March 2012, 01:23
Have you read: Handling Tree Models?

wysota
14th March 2012, 01:57
Create a proxy model that will "flatten" your tree model. Then assign that proxy model to your completer.

sajis997
15th March 2012, 17:41
Hi

I did not actually get what do you mean by flattening the model. Does it happen by itself once i assign the source model to the proxy model or i have re-program it and break the hierarchy while building the proxy model.


Looking forward to more on this !!


Regards
Sajjad

wysota
15th March 2012, 20:49
No, nothing happens by itself. By flattening I mean that the proxy model needs to transform the original model in such a way that all children of each item become siblings of that item so that you don't have children anymore and all elements are directly under the root of the model.

sajis997
16th March 2012, 07:15
Hi

I think that in this case i have subclass the QProxyModel and over-ride the following functions as follows:



class FlatTreeModel : public QAbstractProxyModel
{
public:
QModelIndex mapFromSource(...);
QModelIndex mapToSource(....);

};



I am not sure what would be inside the definition of those above functions . As per suggestion i need to flatten down the existing tree hierarchy model and send it to the QCompleter.


Some more hint or example is appreciated.


Regards
Sajjad

wysota
16th March 2012, 09:49
Take a piece of paper, draw a schema of your tree model (including branches and children) and think what needs to be done step by step to obtain a situation where the model is flat. When you find the algorithm of recalculating model indexes, implement it in mapFromSource() and mapToSource().

sajis997
31st March 2012, 14:44
Hi

If i flatten down the tree hierarchy , it will eventually look like a list model, right?


Regards
Sajjad

wysota
31st March 2012, 17:35
A list or a table model, depending on the number of columns your original model has.