void CUndoRedoStack::push(QUndoCommand* cmd) { if(!cmd) return; // First register the undo command into the undo stack. QUndoCommand* topCmd = d->undoStack.count() ? d->undoStack.top() : 0; if(!topCmd) { d->undoStack.push(cmd); CUndoRedoCmdBase* cmd2 = dynamic_cast<CUndoRedoCmdBase*>(cmd); if(cmd2) addCommand(cmd2); } else { if(topCmd->id() == cmd->id()) { bool success = topCmd->mergeWith(cmd); if(!success) { d->undoStack.push(cmd); CUndoRedoCmdBase* cmd2 = dynamic_cast<CUndoRedoCmdBase*>(cmd); if(cmd2) addCommand(cmd2); } else delete cmd; } } // Now clear the redo stack. for(int i=0; i<d->redoStack.count(); i++) { QUndoCommand* cmd = d->redoStack.pop(); CUndoRedoCmdBase* cmd2 = dynamic_cast<CUndoRedoCmdBase*>(cmd); if(cmd2) removeCommand(cmd2); delete cmd; } // emit change notifications. emit canUndoChanged(d->undoStack.count()); emit canRedoChanged(d->redoStack.count()); emit countChanged(count()); }
void QUndoStack::push(QUndoCommand *cmd) { Q_D(QUndoStack); cmd->redo(); bool macro = !d->macro_stack.isEmpty(); QUndoCommand *cur = 0; if (macro) { QUndoCommand *macro_cmd = d->macro_stack.last(); if (!macro_cmd->d->child_list.isEmpty()) cur = macro_cmd->d->child_list.last(); } else { if (d->index > 0) cur = d->command_list.at(d->index - 1); while (d->index < d->command_list.size()) delete d->command_list.takeLast(); if (d->clean_index > d->index) d->clean_index = -1; // we've deleted the clean state } bool try_merge = cur != 0 && cur->id() != -1 && cur->id() == cmd->id() && (macro || d->index != d->clean_index); if (try_merge && cur->mergeWith(cmd)) { delete cmd; if (!macro) { emit indexChanged(d->index); emit canUndoChanged(canUndo()); emit undoTextChanged(undoText()); emit canRedoChanged(canRedo()); emit redoTextChanged(redoText()); } } else { if (macro) { d->macro_stack.last()->d->child_list.append(cmd); } else { d->command_list.append(cmd); d->checkUndoLimit(); d->setIndex(d->index + 1, false); } } }
static PyObject *meth_QUndoCommand_mergeWith(PyObject *sipSelf, PyObject *sipArgs) { PyObject *sipParseErr = NULL; bool sipSelfWasArg = (!sipSelf || sipIsDerived((sipSimpleWrapper *)sipSelf)); { const QUndoCommand* a0; QUndoCommand *sipCpp; if (sipParseArgs(&sipParseErr, sipArgs, "BJ8", &sipSelf, sipType_QUndoCommand, &sipCpp, sipType_QUndoCommand, &a0)) { bool sipRes; sipRes = (sipSelfWasArg ? sipCpp->QUndoCommand::mergeWith(a0) : sipCpp->mergeWith(a0)); return PyBool_FromLong(sipRes); } } /* Raise an exception if the arguments couldn't be parsed. */ sipNoMethod(sipParseErr, sipName_QUndoCommand, sipName_mergeWith, doc_QUndoCommand_mergeWith); return NULL; }