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 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| class AssignmentDelegate(QtGui.QItemDelegate):
def __init__(self, owner):
QtGui.QItemDelegate.__init__(self, owner)
# #On charge TOUTES la table "Categories" dans le model
# self.modelAssignment = QSqlTableModel(self)
# self.modelAssignment.setTable("Assignments")
# self.modelAssignment.select()
def createEditor(self, parent, option, index):
text = index.data(QtCore.Qt.DisplayRole).toString()
editor = QtGui.QComboBox(parent)
#editor.setModel(self.modelAssignment)
editor.setModel(TVQCombo("Assignments"))
editor.setModelColumn(TVQCombo("Assignments").fieldIndex("name"))
indexCat = editor.findText(unicode(text))
editor.setCurrentIndex(indexCat)
editor.installEventFilter(self)
return editor
def setEditorData(self, editor, index):
value = index.data(QtCore.Qt.DisplayRole).toString()
indexAss = editor.findText(unicode(value))
editor.setCurrentIndex(indexAss)
def setModelData(self,editor,model,index):
value = editor.currentIndex()
myIndex = TVQCombo("Assignments").index(value, 0)
assignmentId = TVQCombo("Assignments").data(myIndex, 0).toInt()[0]
#Enregistrement
model.setData(index, QtCore.QVariant(assignmentId))
#En cas de virement, on doit mettre à jour les deux enregistrements.
row = index.row()
if model.index(row, 14).data().toInt()[1] == True:
idVirement = model.index(row, 14).data().toInt()[0]
query = QSqlQuery()
query.exec_('UPDATE Operations\
SET assignment_id = \"'+str(assignmentId)+'\"\
WHERE (virement_id = '+str(idVirement)+')')
#print query.lastError().text()
#################################################################### |
Partager