Canorus 0.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CAUndo Class Reference

Undo/Redo support. More...

#include <undo.h>

Public Member Functions

 CAUndo ()
 
virtual ~CAUndo ()
 
bool canUndo (CADocument *)
 
bool canRedo (CADocument *)
 
void undo (CADocument *)
 
void redo (CADocument *)
 
bool containsUndoStack (CADocument *d)
 
void createUndoStack (CADocument *d)
 
QList< CAUndoCommand * > * undoStack (CADocument *d)
 
int & undoIndex (CADocument *d)
 
void removeUndoStack (CADocument *d)
 
void deleteUndoStack (CADocument *doc)
 
void createUndoCommand (CADocument *d, QString text)
 
void pushUndoCommand ()
 
CAUndoCommandundoCommand (CADocument *d)
 
CAUndoCommandredoCommand (CADocument *d)
 
void updateLastUndoCommand (CAUndoCommand *c)
 
void changeDocument (CADocument *, CADocument *)
 
QList< CADocument * > getAllDocuments (CADocument *d)
 

Private Member Functions

void clearUndoCommand ()
 

Private Attributes

CAUndoCommand_undoCommand
 
QHash< CADocument *, QList< CAUndoCommand * > * > _undoStack
 
QHash< QList< CAUndoCommand * > *, int > _undoIndex
 

Detailed Description

Undo/Redo support.

Copyright (c) 2007, Matevž Jekovec, Canorus development team All Rights Reserved. See AUTHORS for a complete list of authors.

Licensed under the GNU GENERAL PUBLIC LICENSE. See COPYING for details.

This class implements undo and redo Canorus functionality.

The object is usually created upon Canorus startup and is accessed via CACanorus::undo(). Every main window which wants to have undo and redo capabilities should have one undo stack for its document. Undo stack consists of one or more undo commands called upon undo/redo events (commands actions then make changes to the actual documents).

Here, undo stack is implemented as a pair of QList<CAUndoCommand*> and an index of the current undo command (ie. the command which gets called next time the user presses the Undo button).

Usage of undo/redo: 1) Create undo stack when creating/opening a new document by calling CAUndo::createUndoStack() 2) Before each action (insertion, removal, editing of elements), call CAUndo::createUndoCommand() and pass the current document to be saved for that action. 3) If the action was successful, commit the command by calling CAUndo::pushUndoCommand(). If not, do nothing - non-pushed commands will get deleted when createUndoCommand() will be issued the next time. 4) For undo/redo, simply call CAUndo::undoStack()->undo(). 5) When destroying the document, also destroy the undo stack (which also destroys all its commands) by calling CAUndo::deleteUndoStack(). This is not done automatically because CADocument is part of the data model and CAUndo part of the controller.

See also
CAUndoCommand

Constructor & Destructor Documentation

◆ CAUndo()

CAUndo::CAUndo ( )

References _undoCommand.

◆ ~CAUndo()

CAUndo::~CAUndo ( )
virtual

Member Function Documentation

◆ canRedo()

bool CAUndo::canRedo ( CADocument d)

Returns True, if changes to the current document have been undone at least once and redo is possible. False otherwise.

See also
canUndo()

References _undoStack, and undoIndex().

Referenced by redo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ canUndo()

bool CAUndo::canUndo ( CADocument d)

Returns True, if changes to the current document have been made and undo is possible. False otherwise.

See also
canRedo()

References _undoStack, and undoIndex().

Referenced by undo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ changeDocument()

void CAUndo::changeDocument ( CADocument oldDoc,
CADocument newDoc 
)

Change the document pointer of an undo stack. This function is called when the document is rebuilt, e.g. when a CanorusML view commits changes.

References _undoStack, and clearUndoCommand().

Referenced by CAMainWin::sourceViewCommit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ clearUndoCommand()

void CAUndo::clearUndoCommand ( )
private

Destroys the undo command if decided not to be put on the stack. Does nothing if undo command is null.

References _undoCommand.

Referenced by changeDocument(), createUndoCommand(), and deleteUndoStack().

Here is the caller graph for this function:

◆ containsUndoStack()

bool CAUndo::containsUndoStack ( CADocument d)
inline

References _undoStack.

◆ createUndoCommand()

void CAUndo::createUndoCommand ( CADocument d,
QString  text 
)

Creates an undo command which is later put on the stack. This function is usually called when making changes to the document in the score - all changes ranging from creation/removal of sheets and editing document properties.

Warning
This function is not thread-safe. createUndoCommand() and pushUndoCommand() should be called from the same thread.

References _undoCommand, and clearUndoCommand().

Referenced by CAPropertiesDialog::applyProperties(), CAMainWin::confirmTextEdit(), CAMainWin::deleteSelection(), CAMainWin::insertMusElementAt(), CAKeybdInput::midiInEventToScore(), CATransposeView::on_uiApply_clicked(), CAMainWin::on_uiAssociatedVoice_activated(), CAMainWin::on_uiClefOffset_valueChanged(), CAMainWin::on_uiContextName_returnPressed(), CAMainWin::on_uiCut_triggered(), CAMainWin::on_uiFBMAccs_toggled(), CAMainWin::on_uiFBMNumber_toggled(), CAMainWin::on_uiFermataType_toggled(), CAMainWin::on_uiFinger_toggled(), CAMainWin::on_uiFingeringOriginal_toggled(), CAMainWin::on_uiFMChordArea_toggled(), CAMainWin::on_uiFMEllipse_toggled(), CAMainWin::on_uiFMFunction_toggled(), CAMainWin::on_uiFMTonicDegree_toggled(), CAMainWin::on_uiHiddenRest_toggled(), CAMainWin::on_uiInstrumentChange_activated(), CAKeySignatureCtl::on_uiKeySig_activated(), CAMainWin::on_uiNewSheet_triggered(), CAMainWin::on_uiNewVoice_triggered(), CAMainWin::on_uiNoteStemDirection_toggled(), CAMainWin::on_uiPlayableLength_toggled(), CAMainWin::on_uiRemoveContext_triggered(), CAMainWin::on_uiRemoveSheet_triggered(), CAMainWin::on_uiRemoveVoice_triggered(), CAMainWin::on_uiRepeatMarkType_toggled(), CAMainWin::on_uiSheetName_returnPressed(), CAMainWin::on_uiStanzaNumber_valueChanged(), CAMainWin::on_uiTabWidget_CAMoveTab(), CAMainWin::on_uiTempoBeat_toggled(), CAMainWin::on_uiTempoBpm_returnPressed(), CAMainWin::on_uiTupletType_toggled(), CAMainWin::on_uiVoiceInstrument_activated(), CAMainWin::on_uiVoiceName_returnPressed(), CAMainWin::on_uiVoiceStemDirection_toggled(), CAMainWin::pasteAt(), CAMainWin::scoreViewKeyPress(), CAMainWin::scoreViewMousePress(), and CAMainWin::sourceViewCommit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createUndoStack()

void CAUndo::createUndoStack ( CADocument doc)

Creates a new undoStack for the given document. This should be called at the beginning when the first main window for the given document is created.

References _undoStack, and undoIndex().

Referenced by CAMainWin::newDocument(), CAMainWin::on_uiImportDocument_triggered(), and CAMainWin::openDocument().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ deleteUndoStack()

void CAUndo::deleteUndoStack ( CADocument doc)

Deletes the undoStack object for the given document. This should be called at the end where no main windows are pointing to the given document anymore.

References _undoStack, clearUndoCommand(), removeUndoStack(), and undoStack().

Referenced by CAMainWin::newDocument(), CAMainWin::on_uiCloseDocument_triggered(), CAMainWin::openDocument(), and CAMainWin::~CAMainWin().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getAllDocuments()

QList< CADocument * > CAUndo::getAllDocuments ( CADocument d)

Gathers a list of all redo and undo instances of the given document d. This function is usually called when adding/removing a resource to/from a document. Because resources are not undoable, they should be the same for all the documents.

References _undoStack.

Referenced by CAResourceCtl::createEmptyResource(), CAResourceCtl::deleteResource(), and CAResourceCtl::importResource().

Here is the caller graph for this function:

◆ pushUndoCommand()

void CAUndo::pushUndoCommand ( )

Call this to add an undo command (created by createUndoCommand()) to the stack. Undo commands after the currently active command will be deleted. undoIndex is updated to the size of the stack - 1.

Warning
This function is not thread-safe. createUndoCommand() and pushUndoCommand() should be called from the same thread and main window.

References _undoCommand, _undoStack, CAUndoCommand::getRedoDocument(), CAUndoCommand::getUndoDocument(), CADocument::setModified(), CAUndoCommand::setRedoDocument(), and undoIndex().

Referenced by CAPropertiesDialog::applyProperties(), CAMainWin::confirmTextEdit(), CAMainWin::deleteSelection(), CAMainWin::insertMusElementAt(), CAKeybdInput::midiInEventToScore(), CATransposeView::on_uiApply_clicked(), CAMainWin::on_uiAssociatedVoice_activated(), CAMainWin::on_uiClefOffset_valueChanged(), CAMainWin::on_uiContextName_returnPressed(), CAMainWin::on_uiCut_triggered(), CAMainWin::on_uiFBMAccs_toggled(), CAMainWin::on_uiFBMNumber_toggled(), CAMainWin::on_uiFermataType_toggled(), CAMainWin::on_uiFinger_toggled(), CAMainWin::on_uiFingeringOriginal_toggled(), CAMainWin::on_uiFMChordArea_toggled(), CAMainWin::on_uiFMEllipse_toggled(), CAMainWin::on_uiFMFunction_toggled(), CAMainWin::on_uiFMTonicDegree_toggled(), CAMainWin::on_uiHiddenRest_toggled(), CAMainWin::on_uiInstrumentChange_activated(), CAKeySignatureCtl::on_uiKeySig_activated(), CAMainWin::on_uiNewSheet_triggered(), CAMainWin::on_uiNewVoice_triggered(), CAMainWin::on_uiNoteStemDirection_toggled(), CAMainWin::on_uiPlayableLength_toggled(), CAMainWin::on_uiRemoveContext_triggered(), CAMainWin::on_uiRemoveSheet_triggered(), CAMainWin::on_uiRemoveVoice_triggered(), CAMainWin::on_uiRepeatMarkType_toggled(), CAMainWin::on_uiSheetName_returnPressed(), CAMainWin::on_uiStanzaNumber_valueChanged(), CAMainWin::on_uiTabWidget_CAMoveTab(), CAMainWin::on_uiTempoBeat_toggled(), CAMainWin::on_uiTempoBpm_returnPressed(), CAMainWin::on_uiTupletType_toggled(), CAMainWin::on_uiVoiceInstrument_activated(), CAMainWin::on_uiVoiceName_returnPressed(), CAMainWin::on_uiVoiceStemDirection_toggled(), CAMainWin::pasteAt(), CAMainWin::scoreViewKeyPress(), CAMainWin::scoreViewMousePress(), CAMainWin::scoreViewMouseRelease(), and CAMainWin::sourceViewCommit().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ redo()

void CAUndo::redo ( CADocument doc)

Redoes the last change made to document. This method already calls CAUndoCommand::redo().

References _undoStack, canRedo(), and undoIndex().

Referenced by CAMainWin::on_uiRedo_toggled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ redoCommand()

CAUndoCommand * CAUndo::redoCommand ( CADocument d)

◆ removeUndoStack()

void CAUndo::removeUndoStack ( CADocument d)
inline

References _undoStack.

Referenced by deleteUndoStack().

Here is the caller graph for this function:

◆ undo()

void CAUndo::undo ( CADocument doc)

Undoes the last change made to document. This method already calls CAUndoCommand::undo().

References _undoStack, canUndo(), and undoIndex().

Referenced by CAMainWin::on_uiUndo_toggled().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ undoCommand()

CAUndoCommand * CAUndo::undoCommand ( CADocument d)

◆ undoIndex()

int & CAUndo::undoIndex ( CADocument d)
inline

References _undoIndex, and undoStack().

Referenced by canRedo(), canUndo(), createUndoStack(), pushUndoCommand(), redo(), and undo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ undoStack()

QList< CAUndoCommand * > * CAUndo::undoStack ( CADocument d)
inline

References _undoStack.

Referenced by deleteUndoStack(), CAUndoToolButton::showButtons(), and undoIndex().

Here is the caller graph for this function:

◆ updateLastUndoCommand()

void CAUndo::updateLastUndoCommand ( CAUndoCommand c)

Member Data Documentation

◆ _undoCommand

CAUndoCommand* CAUndo::_undoCommand
private

◆ _undoIndex

QHash< QList<CAUndoCommand*>*, int > CAUndo::_undoIndex
private

Referenced by undoIndex().

◆ _undoStack

QHash< CADocument*, QList<CAUndoCommand*>* > CAUndo::_undoStack
private

The documentation for this class was generated from the following files: