Update educational qualifications completed
[biacv.git] / biacv_mainwindow.py
index 3133477..18dc486 100644 (file)
@@ -7,11 +7,55 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
        def __init__ (self):
                PyQt4.QtGui.QMainWindow.__init__ (self)
                self.setupUi (self)
+               self.currentfile = None
 
+       # delete educational qualification
+       def on_delete_education (self):
+               # get the selected items in the education list
+               selitems = self.educationlist.selectedItems ()
+               # if no items are selected
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot delete", "No items selected.")
+               # delete the items after confirmation
+               else:
+                       ans = PyQt4.QtGui.QMessageBox.question (self, "Confirm",
+                               "Are you sure you wish to delete selected item?",
+                               PyQt4.QtGui.QMessageBox.Yes, PyQt4.QtGui.QMessageBox.No)
+                       if ans == PyQt4.QtGui.QMessageBox.Yes:
+                               # remove the item selected
+                               for item in selitems:
+                                       self.educationlist.takeTopLevelItem (self.educationlist.indexOfTopLevelItem (item))
+                               self.reset_education_fields ()
+
+       # selection is changed
+       def on_select_education (self):
+               self.set_education_fields ()
+
+       # update educational qualification button
+       def on_update_education (self):
+               selitems = self.educationlist.selectedItems ()
+               # if no item is selected
+               if selitems == []:
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "No item selected")
+                       return
+               # if the qualification title is not set
+               if self.degree_name.text () == "":
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot update", "A required field is missing.")
+                       return
+               selitem = selitems[0]
+
+               selitem.setText (0, self.degree_name.text ())
+               selitem.setText (1, self.yearofpassing.date ().toString ("MMM, yyyy"))
+               selitem.setText (2, self.institution.text ())
+               selitem.setText (3, self.university.text ())
+               selitem.setText (4, self.grade.text ())
+               selitem.setText (5, str (self.percentage.value ()))
+
+       # add educational qualification button
        def on_add_education (self):
                # check if the qualification title is set
                if self.degree_name.text () == "":
-                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "Some required fields are missing.")
+                       PyQt4.QtGui.QMessageBox.critical (self, "Cannot add", "A required fields is missing.")
                else:
                        educationitem = PyQt4.QtGui.QTreeWidgetItem ([
                                        self.degree_name.text (),
@@ -21,4 +65,30 @@ class Biacv_mainwindow (PyQt4.QtGui.QMainWindow, bui.Ui_biacv_mainwindow):
                                        self.grade.text (),
                                        str (self.percentage.value ())
                        ])
-                       self.educationlist.addTopLevelItem (educationitem)
\ No newline at end of file
+                       self.educationlist.addTopLevelItem (educationitem)
+                       # clear the fields
+                       self.reset_education_fields ()
+
+       # set fields in the education tab from current selected item
+       def set_education_fields (self):
+               selitems = self.educationlist.selectedItems ()
+               if selitems == []:
+                       return
+               selitem = selitems[0]
+               # set the fields to the data in the selected item in the list
+               self.degree_name.setText (selitem.text (0))
+               self.yearofpassing.setDate (PyQt4.QtCore.QDate.fromString (selitem.text(1), "MMM, yyyy"))
+               self.institution.setText (selitem.text (2))
+               self.university.setText (selitem.text (3))
+               self.grade.setText (selitem.text(4))
+               self.percentage.setValue (self.percentage.valueFromText (selitem.text(5)))
+
+       # reset fields in the education tab
+       def reset_education_fields (self):
+               self.degree_name.setText ("")
+               self.yearofpassing.setDate (PyQt4.QtCore.QDate (1988, 1, 1))
+               self.institution.setText ("")
+               self.university.setText ("")
+               self.grade.setText ("")
+               self.percentage.setValue (50.0)
+