|
Canorus 0.0
|
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 () |
| CAUndoCommand * | undoCommand (CADocument *d) |
| CAUndoCommand * | redoCommand (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 |
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.
| CAUndo::CAUndo | ( | ) |
References _undoCommand.
|
virtual |
| 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.
References _undoStack, and undoIndex().
Referenced by redo().


| bool CAUndo::canUndo | ( | CADocument * | d | ) |
Returns True, if changes to the current document have been made and undo is possible. False otherwise.
References _undoStack, and undoIndex().
Referenced by undo().


| 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().


|
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().

|
inline |
References _undoStack.
| 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.
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().


| 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().


| 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().


| 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().

| 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.
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().


| 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().


| CAUndoCommand * CAUndo::redoCommand | ( | CADocument * | d | ) |
|
inline |
| 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().


| CAUndoCommand * CAUndo::undoCommand | ( | CADocument * | d | ) |
|
inline |
References _undoIndex, and undoStack().
Referenced by canRedo(), canUndo(), createUndoStack(), pushUndoCommand(), redo(), and undo().


|
inline |
References _undoStack.
Referenced by deleteUndoStack(), CAUndoToolButton::showButtons(), and undoIndex().

| void CAUndo::updateLastUndoCommand | ( | CAUndoCommand * | c | ) |
|
private |
Referenced by CAUndo(), clearUndoCommand(), createUndoCommand(), and pushUndoCommand().
|
private |
Referenced by undoIndex().
|
private |
Referenced by canRedo(), canUndo(), changeDocument(), containsUndoStack(), createUndoStack(), deleteUndoStack(), getAllDocuments(), pushUndoCommand(), redo(), removeUndoStack(), undo(), and undoStack().