aspidites
23rd April 2009, 05:43
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:
if len(lineEdit.text()) > 0:
field = lineEdit.text().split("=")[0]
pattern = lineEdit.text().split("=")[1]
if field == name:
model.setNameFilter(pattern)
elif field == type:
model.setTypeFilter(pattern)
else:
model.invalidateFilter() # doesn't work
model.clear() # also doesn't work
model.invalidate() # again, doesn't work
model.setNameFilter("") # works
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.
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:
if len(lineEdit.text()) > 0:
field = lineEdit.text().split("=")[0]
pattern = lineEdit.text().split("=")[1]
if field == name:
model.setNameFilter(pattern)
elif field == type:
model.setTypeFilter(pattern)
else:
model.invalidateFilter() # doesn't work
model.clear() # also doesn't work
model.invalidate() # again, doesn't work
model.setNameFilter("") # works
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.