Example #1
0
void KUndo2QStack::purgeRedoState()
{
    bool macro = !m_macro_stack.isEmpty();
    if (macro) return;

    bool redoStateChanged = false;
    bool cleanStateChanged = false;

    while (m_index < m_command_list.size()) {
        delete m_command_list.takeLast();
        redoStateChanged = true;
    }

    if (m_clean_index > m_index) {
        m_clean_index = -1; // we've deleted the clean state
        cleanStateChanged = true;
    }

    if (redoStateChanged) {
        emit canRedoChanged(canRedo());
        emit redoTextChanged(redoText());
    }

    if (cleanStateChanged) {
        emit cleanChanged(isClean());
    }
}
Example #2
0
void QUndoStack::clear()
{
    Q_D(QUndoStack);

    if (d->command_list.isEmpty())
        return;

    bool was_clean = isClean();

    d->macro_stack.clear();
    qDeleteAll(d->command_list);
    d->command_list.clear();

    d->index = 0;
    d->clean_index = 0;

    emit indexChanged(0);
    emit canUndoChanged(false);
    emit undoTextChanged(QString());
    emit canRedoChanged(false);
    emit redoTextChanged(QString());

    if (!was_clean)
        emit cleanChanged(true);
}
Example #3
0
void UndoStack::setClean() noexcept
{
    if (isClean())
        return;

    mCleanIndex = mCurrentIndex;

    emit cleanChanged(true);
}
Example #4
0
void UndoStack::redo() throw (Exception)
{
    if (!canRedo())
        return;

    mCommands[mCurrentIndex]->redo(); // throws an exception on error
    mCurrentIndex++;

    // emit signals
    emit undoTextChanged(getUndoText());
    emit redoTextChanged(getRedoText());
    emit canUndoChanged(canUndo());
    emit canRedoChanged(canRedo());
    emit cleanChanged(isClean());
}
Example #5
0
void UndoStack::undo() throw (Exception)
{
    if ((!canUndo()) || (mCommandActive)) // if a command is active, undo() is not allowed
        return;

    mCommands[mCurrentIndex-1]->undo(); // throws an exception on error
    mCurrentIndex--;

    // emit signals
    emit undoTextChanged(getUndoText());
    emit redoTextChanged(getRedoText());
    emit canUndoChanged(canUndo());
    emit canRedoChanged(canRedo());
    emit cleanChanged(isClean());
}
Example #6
0
void UndoStack::abortCommand() throw (Exception)
{
    Q_ASSERT(mCurrentIndex == mCommands.count());

    if (!mCommandActive)
        throw LogicError(__FILE__, __LINE__, QString(), tr("No command active!"));

    mCommands.last()->undo(); // throws an exception on error
    mCurrentIndex--;
    mCommandActive = false;
    delete mCommands.takeLast(); // delete and remove the aborted command from the stack

    // emit signals
    emit undoTextChanged(getUndoText());
    emit redoTextChanged(tr("Redo"));
    emit canUndoChanged(canUndo());
    emit canRedoChanged(false);
    emit cleanChanged(isClean());
    emit commandAborted(); // this is important!
}
Example #7
0
void KUndo2QStack::clear()
{
    if (m_command_list.isEmpty())
        return;

    bool was_clean = isClean();

    m_macro_stack.clear();
    qDeleteAll(m_command_list);
    m_command_list.clear();

    m_index = 0;
    m_clean_index = 0;

    emit indexChanged(0);
    emit canUndoChanged(false);
    emit undoTextChanged(QString());
    emit canRedoChanged(false);
    emit redoTextChanged(QString());

    if (!was_clean)
        emit cleanChanged(true);
}