Results 1 to 6 of 6

Thread: Searching a hierarchical QStandardItemModel

  1. #1
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Searching a hierarchical QStandardItemModel

    I've been struggling for about an hour trying to figure out how to correctly use findItem to find an item in a heirarchical QStandardItemModel. The item is in column 2, so I set the column and I told it to search recursively (also tried MatchWrap too), and yet it returns nothing. I'm thinking this has something to do with the fact that only the first column in my table knows about the hierarchy, as you append rows to an item to create a hierarchical pattern, not the entire row. I told it also to search collumn 0 since that is the collumn that the hierarchy is built up in, but that failed, as expected, because I'm sure it did a search down just all the items in column 0.

    So now I don't know what to try. How am I ever supposed to search for an item that isn't in the first collumn or at the top level of the hierarchy? Is there a better way I can build my QStandardItemModel such that it supports what I want to do? It currently is being displayed in a QTreeView, and looks great, but behind the scenes I need to be able to search the model.

    Suggestions?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Searching a hierarchical QStandardItemModel

    Unfortunately squidge has broken his crystal ball again so you'll have to provide some code for us to look at.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Searching a hierarchical QStandardItemModel

    I got a successful bug in and confirmed by the Qt development team with the exact same description I gave before, but if you guys can think of another work around other than the one suggested let me know:

    Bug Report
    Last edited by Zoober7; 15th March 2011 at 17:20.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Searching a hierarchical QStandardItemModel

    Why do you think this is a bug? The docs clearly state only the data in a particular column is searched. If the parent doesn't satisfy the column condition, its children will not be searched. You can of course implement it by subclassing match but for a big model with lots of children this function will be terribly slow as it will have to traverse each index in the tree because it might happen that deep deep inside the tree there is a child that satisfies this condition. If you had 1000 rows with 1000 columns having 1000 rows with 1000 columns as children you would have to search through 10^12 items which would probably last a couple of years or at least a couple of days. With the current implementation you only have to check 10^6 items. If you have a particular model that has some special features that simplifiy the search you can reimplement match() and use this additional knowledge to perform a full scan of the tree.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Mar 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Searching a hierarchical QStandardItemModel

    Well here's a couple reasons:
    1) Because when you search a model "recursively" you expect it to find ANY item or sub item in the model that matches your search. I'm sorry you don't agree, but the expected behavior is that if anything in the column your searching for matches it, it should be returned.
    2) A person should realize that you're going to get a slow operation if you're just willy-nilly searching a huge model like that recrusively, the performance gain granted from only doing a crummy job of searching the list does not merit the said crummy searching.
    3) This type of iteration over every item in the list only needs to occur if you are searching recursively, and could be remidied by constructing different mechanisms for tracking children.
    4) The data shouldn't just reside in that column once its been appended to a certain item, unless there is the option to append a row to another, because there could be MANY items in other columns that have now just been completely hidden from a search.
    5) If you use this model, which the documentation recommends you do, for hierarchical data models that may or may not have multiple collumns, you probably want to be able to search for things besides things just the first column. (if the first column is where your hierarchy is built up)
    6) A Qt Support representitive also thinks its a bug?

    I already wrote my own version of the QStandardItemModel::findItems function that remedies the problem and only acts if it is called recursively. I'm not trying to cause any problems, but it is broken in the way it works right now.

  6. #6
    Join Date
    Mar 2012
    Posts
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Searching a hierarchical QStandardItemModel

    Hi Zoober7,

    Could you please explain a bit more on how you wrote your version of the QStandardItemModel::findItems ? I even tried 'match' function, which works same as findItems .

    Any further pointers would really be appreciated.

    Regards,
    Vrushali

Similar Threads

  1. Replies: 1
    Last Post: 20th March 2014, 10:36
  2. Hierarchical QTableView
    By lotek in forum Newbie
    Replies: 0
    Last Post: 12th January 2011, 19:24
  3. Hierarchical Table/Listview
    By cia.michele in forum Qt Programming
    Replies: 8
    Last Post: 7th December 2009, 08:50
  4. hierarchical model in a flat view
    By gniking in forum Qt Programming
    Replies: 4
    Last Post: 10th November 2009, 20:17
  5. Saving hierarchical structures of data.
    By psih128 in forum Qt Programming
    Replies: 1
    Last Post: 30th July 2009, 08:33

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.