PDA

View Full Version : complex search proxy for QTreeView



brixton
30th October 2010, 21:11
Hi, I don't know if this is a simple question or whether I should be in the QtProgramming forum ... but I'm a Qt newbie so I'm asking here.

As a learning project, I have implemented a simple program which reads data from an Xml file and displays it in a QTreeView with four columns. I put in a little search box which lets me apply a QRegExp to the first column. So far, so good.

What I want to do, however, is to do much more complex searching on the data. The idea is to have a rule like "match any vowel". So if I search for "bad", it will match "bad", "bed", "bid", "bod" and "bud". This is easy to implement with a regexp ("b[aeiou]d"). But what I want is to have several of these rules -- so maybe "[aeiou]d" -- AND to rank the closest match highest in the list of results.

So in the above example, the results would be something like:
bad (exact match)
pad (one letter change)
bed
bid
bod
bud
ped (two letter changes)
pid
pod
pud

So I'm curious if anyone has some insight about the best implementation. Speed will be important if there are thousands of words and complex rules. I think I could keep track of things in a custom [b]QSortFilterProxyModel::acceptsRow -- but I'm not sure the best way of passing the query to that function (as a customised QString through setFilterWildcard?). Or maybe I'm looking at it in completely the wrong way?

Does anyone have any suggestions as to how I should approach this problem?

Cheers, B.

brixton
19th November 2010, 22:10
To reply to my own thread (it can be lonely here), what I did was reimplement QStandardItemModel and the QSortFilterProxyModel as normal. But I implemented my search function (as described above) inside the subclassed Model. The search function performs the search and gives each word that matches a value >0 in the model (high number means closer match). The Proxy just checks the Model for >0 values to display and sorts on the correct column.

My only question is if this is the most efficient way of doing things in Qt. It's pretty fast but once the number of words to search gets big there is a bit of a delay.