Results 1 to 3 of 3

Thread: QSortFilterProxyModel.invalidateFilter() misunderstanding

  1. #1
    Join Date
    Apr 2009
    Posts
    5
    Qt products
    Platforms
    Unix/X11

    Default QSortFilterProxyModel.invalidateFilter() misunderstanding

    The Long Version
    I have a QSortFilterProxyModel subclass that reimplements filterAcceptsRow(). In filterAcceptsRow, I check the result of various regexp's (one for each column of a tableview). Additionally, I have numerous set methods that change the value of the regexp patterns used in filterAcceptsRow() and call invalidateFilter().

    In my main window, I have a QLineEdit that, upon emitting its textChanged signal sets the forementioned filters according to a specific syntax. If, for example, I have:

    name=beagle; type=dog

    the result set would consist of rows who's name column contains beagle and type column contains dog.

    What I can't figure out, is how to remove all filters if the line edit is empty. Well, I can, but I can't help but think there must be a more correct way to do it. Here is some pseudo-code (python) that demonstrates what I've tried, and what I've ended up doing until I find a more permanent solution:

    Qt Code:
    1. if len(lineEdit.text()) > 0:
    2. field = lineEdit.text().split("=")[0]
    3. pattern = lineEdit.text().split("=")[1]
    4. if field == name:
    5. model.setNameFilter(pattern)
    6. elif field == type:
    7. model.setTypeFilter(pattern)
    8. else:
    9. model.invalidateFilter() # doesn't work
    10. model.clear() # also doesn't work
    11. model.invalidate() # again, doesn't work
    12. model.setNameFilter("") # works
    To copy to clipboard, switch view to plain text mode 

    The Short Version
    In short, what method should I be calling to get the model back to it's original state? Have I misunderstood the use of invalidateFilter? Should I be reimplementing it?

    Thanks in advance for any help. I've been teaching myself python and Qt for the last month or so, and things have been fairly smooth up until now.

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: QSortFilterProxyModel.invalidateFilter() misunderstanding

    Hi,

    I am not sure if I fully understand the problem but maybe you could call the base class if the filters are empty e.g:

    Qt Code:
    1. if (nameFilter.isEmpty() && typeFilter.isEmpty())
    2. QSortFilterProxyModel::filterAcceptsRow(source_row, source_parent )
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Apr 2009
    Posts
    5
    Qt products
    Platforms
    Unix/X11

    Default Re: QSortFilterProxyModel.invalidateFilter() misunderstanding

    That's not quite what I'm trying to check for. Instead of checking for emtpy filters, I'm trying to check for an empty widget (line edit).

    What I'd lik to do is remove all filters from the model if the line edit is empty. In other words, if it is empty, all filters should be cleared. I'd like to clear all the filters without having to set them to "" like this:

    Qt Code:
    1. self.setNameFilter("")
    2. self.setTypeFilter("")
    To copy to clipboard, switch view to plain text mode 

    Failing that, I'd like to at least find a way to ignore their values and return the model to its original state.

    I'm going to have another look at the base class's implementation of reset and invalidate(). Thanks again.

Similar Threads

  1. parent() heirarchy misunderstanding?
    By KShots in forum Qt Programming
    Replies: 2
    Last Post: 16th October 2007, 18:18

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.