Results 1 to 2 of 2

Thread: complex search proxy for QTreeView

  1. #1
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default complex search proxy for QTreeView

    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 "[bp][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 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.

  2. #2
    Join Date
    Oct 2010
    Posts
    15
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: complex search proxy for QTreeView

    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.

Similar Threads

  1. QTreeView search
    By jpujolf in forum Qt Programming
    Replies: 6
    Last Post: 3rd March 2009, 06:43
  2. complex calculations with qt
    By gt.beta2 in forum Newbie
    Replies: 5
    Last Post: 7th February 2009, 23:55
  3. Replies: 4
    Last Post: 25th May 2008, 20:01
  4. Complex QCompleter
    By Amouse in forum Qt Programming
    Replies: 2
    Last Post: 12th May 2008, 22:39
  5. Complex Numbers
    By Max Yaffe in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2007, 17:40

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.