]> git.zarvox.org Git - wp3.git/commitdiff
Filtered, incremental search works in EditPerson.
authorDrew Fisher <drew.m.fisher@gmail.com>
Sun, 5 Jul 2009 18:57:49 +0000 (13:57 -0500)
committerDrew Fisher <drew.m.fisher@gmail.com>
Sun, 5 Jul 2009 18:57:49 +0000 (13:57 -0500)
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.

editperson.py

index 7cf924dc2f67f82dddeec980c30cb0d02402ae71..81fc8bd84f18855f91304f6e834590d7bdaca8ab 100644 (file)
@@ -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)