示例#1
0
void CUndoRedoStack::redo()
{
    QUndoCommand* topCmd = d->redoStack.count() ? d->redoStack.pop() : 0;
    if(!topCmd)
        return;

    QString cmdText = topCmd->text();
    topCmd->redo();
    d->undoStack.push(topCmd);
    qWarning("Redo: %s", qPrintable(cmdText));

    // emit change notifications.
    emit redone(cmdText);
    emit canUndoChanged(d->undoStack.count());
    emit canRedoChanged(d->redoStack.count());
}
示例#2
0
bool UndoCommand::internalRedo(const vector<UndoCommand*>& childCommands, bool executeThis, bool isAborting)
{
    m_bAborted = false;
    vector<UndoCommand*> executed;
    switch(m_eRedoChildExecutionPolicy)
    {
    case e_ChildExecutionPolicy_BackwardAfterParent:
        {
            if(executeThis) redo();
            if(m_bAborted) 
            {
                o_error(!isAborting, "Failed on aborting");
                return false;
            }
            size_t i = childCommands.size(); 
            while(i--)
            {
                if(!childCommands[i]->internalRedo(isAborting))
                {
                    o_error(!isAborting, "Failed on aborting");
                    std::reverse(executed.begin(), executed.end());
                    internalUndo(executed, true, true);
                    return false;
                }
                executed.push_back(childCommands[i]);
            }
        }
        break;
    case e_ChildExecutionPolicy_BackwardBeforeParent:
        {
            size_t i = childCommands.size();
            while(i--)
            {
                if(!childCommands[i]->internalRedo(isAborting))
                {
                    o_error(!isAborting, "Failed on aborting");
                    std::reverse(executed.begin(), executed.end());
                    internalUndo(executed, false, true);
                    return false;
                }
                executed.push_back(childCommands[i]);
            }
            if(executeThis) redo();
            if(m_bAborted) 
            {
                o_error(!isAborting, "Failed on aborting");
                std::reverse(executed.begin(), executed.end());
                internalUndo(executed, false, true);
                return false;
            }
        }
        break;
    case e_ChildExecutionPolicy_ForwardAfterParent:
        {
            if(executeThis) redo();
            if(m_bAborted) 
            {
                o_error(!isAborting, "Failed on aborting");
                return false;
            }
            for(size_t i = 0; i<childCommands.size(); ++i)
            {
                if(!childCommands[i]->internalRedo(isAborting))
                {
                    o_error(!isAborting, "Failed on aborting");
                    internalUndo(executed, true, true);
                    return false;
                }
                executed.push_back(childCommands[i]);
            }
        }
        break;
    case e_ChildExecutionPolicy_ForwardBeforeParent:
        {
            for(size_t i = 0; i<childCommands.size(); ++i)
            {
                if(!childCommands[i]->internalRedo(isAborting))
                {
                    o_error(!isAborting, "Failed on aborting");
                    internalUndo(executed, false, true);
                    return false;
                }
                executed.push_back(childCommands[i]);
            }
            if(executeThis) redo();
            if(m_bAborted) 
            {
                o_error(!isAborting, "Failed on aborting");
                internalUndo(executed, false, true);
                return false;
            }
        }
        break;
    }
    o_emit redone();
    return true;
}