From: Drew Fisher Date: Tue, 7 Jul 2009 05:18:00 +0000 (-0700) Subject: Complete EditPerson functionality. X-Git-Url: http://git.zarvox.org/shortlog/%7B%7B%20url_for%28%27main.logout_page%27%29%20%7D%7D?a=commitdiff_plain;h=76eca15290b5f7c0f7c21b453131f61af75a4020;p=wp3.git Complete EditPerson functionality. With this commit, the program now has 2 of the 4 main screen pushbuttons fully implemented - New Person Wizard and Edit Person. Plans for photo merging - order photo files by creation timestamp and database entries without photos by creation timestamp. Plans for exporting to document - QTextDocumentWriter is sweet. http://doc.trolltech.com/qq/qq27-odfwriter.html --- diff --git a/editperson.py b/editperson.py index 81fc8bd..a54fd2c 100644 --- a/editperson.py +++ b/editperson.py @@ -57,6 +57,8 @@ class EditPerson(QDialog): def setupForm(self): + self.current_record = QSqlRecord() + self.current_row = -1 # Text labels self.netid_lab = QLabel("NetID:") self.year_lab = QLabel("Year:") @@ -78,7 +80,7 @@ class EditPerson(QDialog): self.displaypixmap = QPixmap() self.photo.setAlignment(Qt.AlignCenter) self.pb_changephoto = QPushButton("Select &photo") - self.pb_changephoto.setEnabled(True) + self.pb_changephoto.setEnabled(False) # Personal info self.surname = QLineEdit() self.firstname = QLineEdit() @@ -94,7 +96,7 @@ class EditPerson(QDialog): self.dorm = QComboBox() self.room = QLineEdit() # Fill the comboboxes with values, set valid field types - years = QStringList(["1987","1988","1989","1990","1991","1992","1993","1994"]) + years = QStringList(["1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994"]) months = QStringList(["January","February","March","April","May","June","July","August","September","October","November","December"]) days = QStringList(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]) dorms = QStringList(["Clements","Lechner","McFadden"]) @@ -146,6 +148,8 @@ class EditPerson(QDialog): def setupActions(self): # Update filtered table QObject.connect(self.search_bar, SIGNAL("textChanged(QString)"), self.updateTable ) + # Selecting a record loads it for editing + QObject.connect(self.tableview.selectionModel(), SIGNAL("selectionChanged(QItemSelection, QItemSelection)"), self.selectionChanged ) # Map buttons to actions QObject.connect(self.pb_reset, SIGNAL("clicked()"), self.resetPressed ) QObject.connect(self.pb_cancel, SIGNAL("clicked()"), self.closePressed ) @@ -153,13 +157,13 @@ class EditPerson(QDialog): QObject.connect(self.pb_save, SIGNAL("clicked()"), self.savePressed ) QObject.connect(self.pb_changephoto, SIGNAL("clicked()"), self.changePhoto ) # Changes to the record enable buttons - QObject.connect(self.netid, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.firstname, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.surname, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.email, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.phone, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.major, SIGNAL("textChanged(QString)"), self.formChanged ) - QObject.connect(self.room, SIGNAL("textChanged(QString)"), self.formChanged ) + QObject.connect(self.netid, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.firstname, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.surname, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.email, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.phone, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.major, SIGNAL("textEdited(QString)"), self.formChanged ) + QObject.connect(self.room, SIGNAL("textEdited(QString)"), self.formChanged ) QObject.connect(self.year, SIGNAL("currentIndexChanged(int)"), self.formChanged ) QObject.connect(self.month, SIGNAL("currentIndexChanged(int)"), self.formChanged ) QObject.connect(self.day, SIGNAL("currentIndexChanged(int)"), self.formChanged ) @@ -167,9 +171,44 @@ class EditPerson(QDialog): def formChanged(self): # Do this only if a record has been selected - self.pb_reset.setEnabled(True) - self.pb_save.setEnabled(True) - self.pb_saveclose.setEnabled(True) + if not self.current_record.isEmpty(): + self.pb_reset.setEnabled(True) + self.pb_save.setEnabled(True) + self.pb_saveclose.setEnabled(True) + def selectionChanged(self, selected, deselected): + items = selected.indexes() + if len(items) > 0: + self.current_row = items[0].row() # this is the row of the current selected item + self.current_record = self.model.record(items[0].row()) + self.fillForm() + def fillForm(self): + # Fill fields with data from selected record + self.netid.setText(self.current_record.field("netid").value().toString()) + self.firstname.setText(self.current_record.field("forename").value().toString()) + self.surname.setText(self.current_record.field("surname").value().toString()) + self.email.setText(self.current_record.field("email").value().toString()) + self.phone.setText(self.current_record.field("phone").value().toString()) + self.major.setText(self.current_record.field("major").value().toString()) + self.room.setText(self.current_record.field("room").value().toString()) + bday = str(self.current_record.field("birthday").value().toString()).split("-") + self.year.setCurrentIndex(self.year.findText(bday[0])) + self.month.setCurrentIndex(int(bday[1]) - 1) + self.day.setCurrentIndex(int(bday[2]) - 1) + self.dorm.setCurrentIndex(self.dorm.findText(self.current_record.field("dorm").value().toString())) + self.pb_reset.setEnabled(False) + self.pb_save.setEnabled(False) + self.pb_saveclose.setEnabled(False) + ba = self.current_record.field("photo").value().toByteArray() + if ba.size() > 0: + self.currentimage = QImage() + self.currentimage.loadFromData(ba) + self.displayimage = self.currentimage.scaled(self.photo.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) + self.displaypixmap = QPixmap.fromImage(self.displayimage) + self.photo.setPixmap(self.displaypixmap) + else: + self.photo.setText("No photo available") + self.pb_changephoto.setEnabled(True) + def updateTable(self, text): if text.isEmpty(): self.model.setFilter("") @@ -190,16 +229,36 @@ class EditPerson(QDialog): if self.model.rowCount() == 1: self.tableview.selectRow(0) def resetPressed(self): - self.fillForm([]) + self.current_record = self.model.record(self.current_row) + self.fillForm() self.pb_reset.setEnabled(False) self.pb_save.setEnabled(False) self.pb_saveclose.setEnabled(False) print "Resetting form" def closePressed(self): print "Closing" + self.model.revertAll() self.reject() def savePressed(self): print "Saving" + self.current_record.setValue("netid",QVariant(self.netid.text())) + self.current_record.setValue("forename",QVariant(self.firstname.text())) + self.current_record.setValue("surname",QVariant(self.surname.text())) + self.current_record.setValue("email",QVariant(self.email.text())) + self.current_record.setValue("phone",QVariant(self.phone.text())) + self.current_record.setValue("major",QVariant(self.major.text())) + self.current_record.setValue("room",QVariant(self.room.text())) + self.current_record.setValue("dorm",QVariant(self.dorm.currentText())) + y = self.year.currentText().toInt()[0] + m = self.month.currentIndex() + 1 + d = self.day.currentText().toInt()[0] + 1 + bday = QDate(y,m,d) + self.current_record.setValue("birthday", QVariant(bday.toString(Qt.ISODate)) ) + self.current_record.setValue("mtime", QVariant(QDateTime.currentDateTime().toString(Qt.ISODate)) ) # update modification time + + self.model.setRecord(self.current_row, self.current_record) + self.model.submitAll() + self.updateTable(self.search_bar.text()) # Reselect from the DB self.pb_reset.setEnabled(False) self.pb_save.setEnabled(False) self.pb_saveclose.setEnabled(False) @@ -215,14 +274,15 @@ class EditPerson(QDialog): self.displayimage = self.currentimage.scaled(self.photo.size(), Qt.KeepAspectRatio, Qt.SmoothTransformation) self.displaypixmap = QPixmap.fromImage(self.displayimage) self.photo.setPixmap(self.displaypixmap) - - def fillForm(self, args): - print "Filling form" - - def recordSelected(self): - print "New record selected" - self.fillForm([]) - self.pb_changephoto.setEnabled(True) + ba = QByteArray() + buffer = QBuffer(ba) + buffer.open(QIODevice.WriteOnly) + self.currentimage.save(buffer, "JPG") + buffer.close() + self.current_record.setValue("photo",QVariant(ba)) + self.pb_reset.setEnabled(True) + self.pb_save.setEnabled(True) + self.pb_saveclose.setEnabled(True) if __name__ == "__main__": diff --git a/pagecommit.py b/pagecommit.py index 31a6f33..0da3d59 100644 --- a/pagecommit.py +++ b/pagecommit.py @@ -22,14 +22,14 @@ class PageCommit(QWizardPage): q.bindValue(":forename", self.field("forename") ) q.bindValue(":surname", self.field("surname") ) q.bindValue(":email", self.field("email") ) - y = self.field("year").toInt()[0] + 1987 + y = self.field("year").toInt()[0] + 1983 m = self.field("month").toInt()[0] + 1 d = self.field("day").toInt()[0] + 1 bday = QDate(y,m,d) q.bindValue(":birthday", QVariant(bday.toString(Qt.ISODate)) ) q.bindValue(":phone", self.field("phone") ) q.bindValue(":major", self.field("major") ) - q.bindValue(":dorm", self.field("dorm") ) + q.bindValue(":dorm", QVariant(QString(["Clements","Lechner","McFadden"][self.field("dorm").toInt()[0]])) ) q.bindValue(":room", self.field("room") ) q.bindValue(":createtime", QVariant(QDateTime.currentDateTime().toString(Qt.ISODate)) ) q.bindValue(":mtime", QVariant(QDateTime.currentDateTime().toString(Qt.ISODate)) ) diff --git a/pagenewuserdata.py b/pagenewuserdata.py index 37ad4c9..30e2463 100644 --- a/pagenewuserdata.py +++ b/pagenewuserdata.py @@ -34,13 +34,14 @@ class PageNewUserData(QWizardPage): self.dorm = QComboBox() self.room = QLineEdit() # Fill the comboboxes with values, set valid field types - years = QStringList(["1987","1988","1989","1990","1991","1992","1993","1994"]) + years = QStringList(["1983","1984","1985","1986","1987","1988","1989","1990","1991","1992","1993","1994"]) months = QStringList(["January","February","March","April","May","June","July","August","September","October","November","December"]) days = QStringList(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"]) dorms = QStringList(["Clements","Lechner","McFadden"]) self.year.addItems(years) self.month.addItems(months) self.day.addItems(days) + self.year.setCurrentIndex(6) # Start in 1988 or so self.dorm.addItems(dorms) self.phone.setInputMask("(999)-999-9999") self.major.setMaxLength(4)