def setModelData(self, editor: QtGui.QWidget, model: QtCore.QAbstractItemModel, index: QtCore.QModelIndex) -> None: assert isinstance(editor, QtGui.QLineEdit) text = editor.text() model.setData(index, text.title() if editor.hasAcceptableInput() else text, QtCore.Qt.EditRole)
def setModelData(self, editor: QtGui.QWidget, model: QtCore.QAbstractItemModel, index: QtCore.QModelIndex) -> None: assert isinstance(editor, QtGui.QLineEdit) text = editor.text() if editor.hasAcceptableInput() and not text.startswith("+2"): text = "+2" + text model.setData(index, text, QtCore.Qt.EditRole)
def setData(self, index, value, role): if not index.isValid(): return False item = index.internalPointer().node() if role == Qt.CheckStateRole: # a checkbox was modified progress, success = value.toInt() item.toElement().setAttribute("percentageComplete",str(progress*50)) # check children numChildren = item.childNodes().count() if numChildren > 0 and progress == Qt.Checked: for i in xrange(0,numChildren): self.setData(index.child(i,0),value,role) self.dataChanged.emit(index,index.child(numChildren-1,0)) if progress == Qt.Unchecked: self.setData(index.parent(),value,role) self.dataChanged.emit(index.parent(),index) return True elif role == Qt.EditRole: if index.column() == 0: # task desc item.toElement().setAttribute("subject", unicode(value.toString())) self.dataChanged.emit(index,index) return True elif index.column() == 1: # task progress item.toElement().setAttribute("percentageComplete", str(value.toString())) self.dataChanged.emit(index,index) progress, success = value.toInt() if progress == 100: # if task is now completed, update children # FIXME: this doesn't work and I don't understand why :( numChildren = item.childNodes().count() if numChildren > 0: for i in xrange(0,numChildren): self.setData(index.child(i,1),value,role) self.dataChanged.emit(index,index.child(numChildren-1,1)) return True elif progress < 100: # if task is now NOT complete and parent is, update parent. # this works if self.data(index.parent(),Qt.CheckStateRole) == Qt.Checked: parentIndex = self.index(index.parent().row(),index.column(),index.parent().parent()) self.setData(parentIndex,value,role) self.dataChanged.emit(index.parent(),index) return True return True # for everything else, do the generic thing return QAbstractItemModel.setData(self,index,value,role)
def setData(self, index, value, role): """ \reimp Set the data which value is `value` at index `index` with role `role`. \return `True` if no error occured, `False` otherwise. """ if not index.isValid(): return QVariant() column = index.column() if role == Qt.CheckStateRole: if column == HNAME: node = self.VFS.getNodeFromPointer(index.internalId()) if value == Qt.Unchecked: if (long(node.this), 1) in self.checkedNodes: self.checkedNodes.remove((long(node.this), 1)) else: self.checkedNodes.add((long(node.this), 1)) QAbstractItemModel.setData(self, index, value, role) return True
def setData(self, index, value, role): """ \reimp Set the data which value is `value` at index `index` with role `role`. \return `True` if no error occured, `False` otherwise. """ if not index.isValid(): return QVariant() column = index.column() if role == Qt.CheckStateRole: if column == HNAME: node = self.VFS.getNodeFromPointer(index.internalId()) if value == Qt.Unchecked: if (long(node.this), 1) in self.checkedNodes: self.checkedNodes.remove((long(node.this), 1)) else: self.checkedNodes.add((long(node.this) , 1)) QAbstractItemModel.setData(self, index, value, role) return True
def setModelData(self, editor: QtGui.QWidget, model: QtCore.QAbstractItemModel, index: QtCore.QModelIndex) -> None: assert isinstance(editor, QtGui.QComboBox) model.setData(index, editor.currentText(), QtCore.Qt.EditRole)