def cut(self): self.copy() index = self.view.tableView.selectionModel().selectedIndexes()[0] command = EditCommand(self.model, index) command.newValue("") self.undoStack.beginMacro("Cut") self.undoStack.push(command) self.undoStack.endMacro() self.view.tableView.reset()
def paste(self): if len(self.view.tableView.selectionModel().selectedIndexes()) != 0: clipboard = QApplication.clipboard() index = self.view.tableView.selectionModel().selectedIndexes()[0] command = EditCommand(self.model, index) command.newValue(str(clipboard.text())) self.undoStack.beginMacro("Paste") self.undoStack.push(command) self.undoStack.endMacro() self.view.tableView.reset()
def action_cut_cell(self): if self.action_copy_cell(): # no else case since it was handled in the copy callback index = self.first_selected_index() command = EditCommand(self.table_model, index) command.newValue("0") self.model.undo_stack.beginMacro("Cut Cell") self.model.undo_stack.push(command) self.model.undo_stack.endMacro() self.update_undo_actions() self.view.tableView.reset()
def action_paste_cell(self): if self.cell_selected(): clipboard = QApplication.clipboard() index = self.view.tableView.selectionModel().selectedIndexes()[0] command = EditCommand(self.table_model, index) command.newValue(clipboard.text()) self.model.undo_stack.beginMacro("Paste Cell") self.model.undo_stack.push(command) self.model.undo_stack.endMacro() self.update_undo_actions() self.view.tableView.reset() return True else: # TODO return False
def editorEvent(self, event, model, option, index): self.edit = EditCommand(model, index)