Beispiel #1
0
/// Performs an document-change undo.
void TextUndoStack::undoDocumentChange()
{
    // first make sure ALL controller-changes are back to the document change-level
    QMap<TextEditorController*, int>::iterator itr;
    for( itr = controllerIndexMap_.begin(); itr != controllerIndexMap_.end(); ++itr) {
        TextEditorController* controller = itr.key();
        while( undoControllerChange(controller) ) {};  // undo all controller operations
    }

    // next perform an undo of the document operations
    Change* change = findUndoChange();
    if( change ) {
        Q_ASSERT( change->controllerContext() == 0 );
        change->revert( documentRef_ );

        // next move the pointers to first 'related' change
        for( itr = controllerIndexMap_.begin(); itr != controllerIndexMap_.end(); ++itr) {
            TextEditorController* controller = itr.key();
            controllerIndexMap_[controller] = findUndoIndex( changeIndex_-1, controller ) + 1; // +1 because the pointer points AFTER the found index
        }

        // and finally move the document pointer
        setChangeIndex( findUndoIndex( changeIndex_-1 ) + 1 );  // +1 because the pointer points AFTER the found index
        emit undoExecuted( change);
    }

}
Beispiel #2
0
/// This method undos the given controller change. This method does NOT undo document changes
/// @param controller the controller to undo the change form
/// @return true if a change has been undone.
bool TextUndoStack::undoControllerChange(TextEditorController* controller)
{
    Q_ASSERT(controller);
    int changeIdx = controllerIndexMap_.value(controller)-1;    // -1, because the index is directly AFTER the item
    Change* changeToUndo = findUndoChange( controller );

    if( changeToUndo && changeToUndo->controllerContext() ) {
        Q_ASSERT( changeToUndo->controllerContext() == controller );
        changeToUndo->revert( documentRef_ );
        controllerIndexMap_[controller] = findUndoIndex( changeIdx, controller )+1;
        emit undoExecuted( changeToUndo );
        return true;
    }
    return false;
}