Ejemplo n.º 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());
    }
}
Ejemplo n.º 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);
}
Ejemplo n.º 3
0
void KUndo2QStack::setIndex(int idx, bool clean)
{
    bool was_clean = m_index == m_clean_index;
    if (m_lastMergedIndex <= idx) {
        m_lastMergedSetCount = idx - m_lastMergedIndex;

    } else {
        m_lastMergedSetCount = 1;
        m_lastMergedIndex = idx-1;
    }
    if(idx == 0){
        m_lastMergedSetCount = 0;
        m_lastMergedIndex = 0;
    }
    if (idx != m_index) {
        m_index = idx;
        emit indexChanged(m_index);
        emit canUndoChanged(canUndo());
        emit undoTextChanged(undoText());
        emit canRedoChanged(canRedo());
        emit redoTextChanged(redoText());
    }

    if (clean)
        m_clean_index = m_index;

    bool is_clean = m_index == m_clean_index;
    if (is_clean != was_clean)
        emit cleanChanged(is_clean);
}
Ejemplo n.º 4
0
void UndoStack::setClean() noexcept
{
    if (isClean())
        return;

    mCleanIndex = mCurrentIndex;

    emit cleanChanged(true);
}
Ejemplo n.º 5
0
void UndoStack::execCmd(UndoCommand* cmd, bool autoMerge) throw (Exception)
{
    Q_CHECK_PTR(cmd);

    if (mCommandActive)
    {
        delete cmd;
        throw RuntimeError(__FILE__, __LINE__, QString(), tr("Another command is active "
                           "at the moment. Please finish that command to continue."));
    }

    if (mCleanIndex > mCurrentIndex)
        mCleanIndex = -1; // the clean state will no longer exist -> make the index invalid

    // first, delete all commands above the current index (make redo impossible)
    // --> in reverse order (from top to bottom)!
    while (mCurrentIndex < mCommands.count())
        delete mCommands.takeLast();

    Q_ASSERT(mCurrentIndex == mCommands.count());

    try
    {
        cmd->redo(); // throws an exception on error
    }
    catch (Exception& e)
    {
        // delete the command because this UndoStack object will NOT take the ownership
        // over the failed command! and then rethrow the exception...
        delete cmd;
        throw;
    }

    // command successfully executed, try to merge it with the last executed command
    bool merged = false;
    if ((autoMerge) && (mCurrentIndex > 0))
        merged = mCommands[mCurrentIndex-1]->mergeWith(cmd); // try merging the commands

    if (!merged)
    {
        // command was not merged --> add it to the command stack and emit signals
        mCommands.append(cmd);
        mCurrentIndex++;

        // emit signals
        emit undoTextChanged(QString(tr("Undo: %1")).arg(cmd->getText()));
        emit redoTextChanged(tr("Redo"));
        emit canUndoChanged(true);
        emit canRedoChanged(false);
        emit cleanChanged(false);
    }
}
Ejemplo n.º 6
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());
}
Ejemplo n.º 7
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());
}
Ejemplo n.º 8
0
void KUndo2QStack::setIndex(int idx, bool clean)
{
    bool was_clean = m_index == m_clean_index;

    if (idx != m_index) {
        m_index = idx;
        emit indexChanged(m_index);
        emit canUndoChanged(canUndo());
        emit undoTextChanged(undoText());
        emit canRedoChanged(canRedo());
        emit redoTextChanged(redoText());
    }

    if (clean)
        m_clean_index = m_index;

    bool is_clean = m_index == m_clean_index;
    if (is_clean != was_clean)
        emit cleanChanged(is_clean);
}
Ejemplo n.º 9
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!
}
Ejemplo n.º 10
0
    void Editor::on_proxyMessageReceived(QString msg, QVariant data)
    {
        emit messageReceived(msg, data);

        if(msg == "J_EVT_READY") {
            m_loaded = true;
            emit editorReady();
        } else if(msg == "J_EVT_CONTENT_CHANGED")
            emit contentChanged();
        else if(msg == "J_EVT_CLEAN_CHANGED")
            emit cleanChanged(data.toBool());
        else if(msg == "J_EVT_CURSOR_ACTIVITY")
            emit cursorActivity();
        else if(msg == "J_EVT_GOT_FOCUS")
            emit gotFocus();
        else if(msg == "J_EVT_CURRENT_LANGUAGE_CHANGED") {
            QVariantMap map = data.toMap();
            emit currentLanguageChanged(map.value("id").toString(),
                                        map.value("name").toString());
        }
    }
Ejemplo n.º 11
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);
}
Ejemplo n.º 12
0
int QUndoGroup::qt_metacall(QMetaObject::Call _c, int _id, void **_a)
{
    _id = QObject::qt_metacall(_c, _id, _a);
    if (_id < 0)
        return _id;
    if (_c == QMetaObject::InvokeMetaMethod) {
        switch (_id) {
        case 0: activeStackChanged((*reinterpret_cast< QUndoStack*(*)>(_a[1]))); break;
        case 1: indexChanged((*reinterpret_cast< int(*)>(_a[1]))); break;
        case 2: cleanChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 3: canUndoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 4: canRedoChanged((*reinterpret_cast< bool(*)>(_a[1]))); break;
        case 5: undoTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 6: redoTextChanged((*reinterpret_cast< const QString(*)>(_a[1]))); break;
        case 7: undo(); break;
        case 8: redo(); break;
        case 9: setActiveStack((*reinterpret_cast< QUndoStack*(*)>(_a[1]))); break;
        default: ;
        }
        _id -= 10;
    }
    return _id;
}
Ejemplo n.º 13
0
void UndoStack::clear() noexcept
{
    if (mCommands.isEmpty())
        return;

    if (mCommandActive)
        try {abortCommand();} catch (...) {}

    // delete all commands in the stack from top to bottom (newest first, oldest last)!
    while (!mCommands.isEmpty())
        delete mCommands.takeLast();

    mCurrentIndex = 0;
    mCleanIndex = 0;
    mCommandActive = false;

    // emit signals
    emit undoTextChanged(tr("Undo"));
    emit redoTextChanged(tr("Redo"));
    emit canUndoChanged(false);
    emit canRedoChanged(false);
    emit cleanChanged(true);
}