1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
/**
\page commands Commands
To implement undo and redo functionality, every possible action
by the user for editing and manipulating the document is encapsulated
in a command (based on QUndoCommand).
There is one command class (which will be instantiated) for every unique
action. You need to reimplement the redo() and undo() methods
of QUndoCommand.
Each command is created from the user interface.
The commands working on cell ranges, i.e. derivatives of KSpread::AbstractRegionCommand,
have to check whether the operation is allowed before execution. Cells may be
protected or locked as elements of matrices. KSpread::AbstractRegionCommand::execute
takes care of that. If the operation is not allowed, the command will neither
get executed nor added to the undo stack.
All other commands can be added directly to the undo stack by using
KoDocument::addCommand or KoCanvasBase::addCommand, which executes the operation immediately.
This is an example of typical use of a command NOT processing cell ranges:
\code
QUndoCommand* command = new KSpread::RenameSheetCommand( sheet, name );
doc->addCommand( command );
\endcode
This is an example of typical use of a command, which works on a cell range:
\code
KSpread::CommentCommand* command = new KSpread::CommentCommand();
command->setSheet( sheet );
command->setName( i18n( "Add Comment" ) );
command->setComment( comment );
command->add( cellRegion );
command->execute();
\endcode
Then whenever the user triggers an "undo", the corresponding
undo() method of the command is called by the undo action,
thereby reverting the previously executed command. Similar thing
happens for the "redo".
All command classes reside in the subdirectory commands/.
\sa KoDocument::addCommand
*/
|