From: Drew Fisher Date: Sun, 5 Jul 2009 18:57:49 +0000 (-0500) Subject: Filtered, incremental search works in EditPerson. X-Git-Url: http://git.zarvox.org/shortlog/static/widgets.js?a=commitdiff_plain;h=60ec258178746a7115a74045a212163e47bc22af;p=wp3.git Filtered, incremental search works in EditPerson. The edit menu allows you to search for a particular record now. Many thanks to Matthew Mullins, who wrote the safe filtering logic used in WP2 and adapted for use here. --- diff --git a/editperson.py b/editperson.py index 7cf924d..81fc8bd 100644 --- a/editperson.py +++ b/editperson.py @@ -170,9 +170,25 @@ class EditPerson(QDialog): self.pb_reset.setEnabled(True) self.pb_save.setEnabled(True) self.pb_saveclose.setEnabled(True) - def updateTable(self): + def updateTable(self, text): + if text.isEmpty(): + self.model.setFilter("") + self.model.select() + return + t = str(text) + strs = t.split() + patterns = [] # can't use list comprehensions for this one because setValue returns void + for i in strs: + f = QSqlField("input",QVariant.String) + f.setValue(QVariant(QString("%" + i + "%"))) + patterns.append(f) + escapedpatterns = [ self.model.database().driver().formatValue(wc, False) for wc in patterns] + filters = [ str(QString("(surname LIKE %1 OR forename LIKE %2)").arg(wc).arg(wc)) for wc in escapedpatterns] + filterString = " AND ".join(filters) + self.model.setFilter(QString(filterString)) self.model.select() - print "Text changed" + if self.model.rowCount() == 1: + self.tableview.selectRow(0) def resetPressed(self): self.fillForm([]) self.pb_reset.setEnabled(False)