KDE3Support
K3CommandHistory Class Reference
The command history stores a (user) configurable amount of Commands. More...
#include <k3command.h>

Public Slots | |
virtual void | documentSaved () |
virtual void | redo () |
virtual void | undo () |
Signals | |
void | commandExecuted (K3Command *command) |
void | commandHistoryChanged () |
void | documentRestored () |
Public Member Functions | |
void | addCommand (K3Command *command, bool execute=true) |
void | clear () |
bool | isRedoAvailable () const |
bool | isUndoAvailable () const |
K3CommandHistory (KActionCollection *actionCollection, bool withMenus=true) | |
K3CommandHistory () | |
K3Command * | presentCommand () const |
QList< K3Command * > | redoCommands (int maxCommands=0) const |
int | redoLimit () const |
void | setRedoLimit (int limit) |
void | setUndoLimit (int limit) |
QList< K3Command * > | undoCommands (int maxCommands=0) const |
int | undoLimit () const |
void | updateActions () |
virtual | ~K3CommandHistory () |
Detailed Description
The command history stores a (user) configurable amount of Commands.It keeps track of its size and deletes commands if it gets too large. The user can set a maximum undo and a maximum redo limit (e.g. max. 50 undo / 30 redo commands). The K3CommandHistory keeps track of the "borders" and deletes commands, if appropriate. It also activates/deactivates the undo/redo actions in the menu and changes the text according to the name of the command.
Note: you might want to use the QUndo framework instead. It didn't exist when K3Command was written.
Definition at line 180 of file k3command.h.
Constructor & Destructor Documentation
K3CommandHistory::K3CommandHistory | ( | ) |
Creates a command history, to store commands.
This constructor doesn't create actions, so you need to call undo and redo yourself.
Definition at line 148 of file k3command.cpp.
K3CommandHistory::K3CommandHistory | ( | KActionCollection * | actionCollection, | |
bool | withMenus = true | |||
) |
Creates a command history, to store commands.
This also creates an undo and a redo action, in the actionCollection
, using the standard names ("edit_undo" and "edit_redo").
- Parameters:
-
withMenus if true, the actions will display a menu when plugged into a toolbar. actionCollection the parent collection
Definition at line 154 of file k3command.cpp.
K3CommandHistory::~K3CommandHistory | ( | ) | [virtual] |
Member Function Documentation
void K3CommandHistory::addCommand | ( | K3Command * | command, | |
bool | execute = true | |||
) |
Adds a command to the history.
Call this for each command
you create. Unless you set execute
to false, this will also execute the command. This means, most of the application's code will look like MyCommand * cmd = new MyCommand( parameters ); m_historyCommand.addCommand( cmd );
Note that the command history takes ownership of the command, it will delete it when the undo limit is reached, or when deleting the command history itself.
Definition at line 187 of file k3command.cpp.
void K3CommandHistory::clear | ( | ) |
Erases all the undo/redo history.
Use this when reloading the data, for instance, since this invalidates all the commands.
Definition at line 179 of file k3command.cpp.
void K3CommandHistory::commandExecuted | ( | K3Command * | command | ) | [signal] |
Emitted every time a command is executed (whether by addCommand, undo or redo).
You can use this to update the GUI, for instance.
- Parameters:
-
command was executed
void K3CommandHistory::commandHistoryChanged | ( | ) | [signal] |
Emitted whenever the command history has changed, i.e.
after addCommand, undo or redo. This is used by the actions to update themselves.
void K3CommandHistory::documentRestored | ( | ) | [signal] |
Emitted every time we reach the index where you saved the document for the last time.
See documentSaved
void K3CommandHistory::documentSaved | ( | ) | [virtual, slot] |
Remembers when you saved the document.
Call this right after saving the document. As soon as the history reaches the current index again (via some undo/redo operations) it will emit documentRestored If you implemented undo/redo properly the document is the same you saved before.
Definition at line 247 of file k3command.cpp.
bool K3CommandHistory::isRedoAvailable | ( | ) | const |
- Returns:
- true if redo is available i.e. there is at least one command that can be redone right now
Definition at line 306 of file k3command.cpp.
bool K3CommandHistory::isUndoAvailable | ( | ) | const |
- Returns:
- true if undo is available, i.e. there is at least one command that can be undone right now
Definition at line 301 of file k3command.cpp.
K3Command * K3CommandHistory::presentCommand | ( | ) | const |
- Returns:
- the present command, i.e. the one that undo() would unexecute. This can be used to e.g. show selection.
Definition at line 211 of file k3command.cpp.
void K3CommandHistory::redo | ( | ) | [virtual, slot] |
Redoes the last undone action.
Call this if you don't use the builtin KActions.
Definition at line 234 of file k3command.cpp.
- Returns:
- the list of next
maxCommands
actions that will be redone by redo() The returned list is empty if !isRedoAvailable(). Otherwise the list starts with the next command to redo.
- Parameters:
-
maxCommands maximum number of commands requested. 0 means no maximum, all stored redo commands (within redoLimit()) are returned.
Definition at line 322 of file k3command.cpp.
int K3CommandHistory::redoLimit | ( | ) | const |
- Returns:
- the maximum number of items in the redo history
Definition at line 339 of file k3command.cpp.
void K3CommandHistory::setRedoLimit | ( | int | limit | ) |
void K3CommandHistory::setUndoLimit | ( | int | limit | ) |
void K3CommandHistory::undo | ( | ) | [virtual, slot] |
Undoes the last action.
Call this if you don't use the builtin KActions.
Definition at line 218 of file k3command.cpp.
- Returns:
- the list of next
maxCommands
actions that will be undone by undo() The returned list is empty if !isUndoAvailable(). Otherwise the list starts with the next command to undo, i.e. the order of the commands in the list is the reverse of the chronological order of the commands.
- Parameters:
-
maxCommands maximum number of commands requested. 0 means no maximum, all stored undo commands (within undoLimit()) are returned.
Definition at line 311 of file k3command.cpp.
int K3CommandHistory::undoLimit | ( | ) | const |
- Returns:
- the maximum number of items in the undo history
Definition at line 334 of file k3command.cpp.
void K3CommandHistory::updateActions | ( | ) |
Enable or disable the undo and redo actions.
This isn't usually necessary, but this method can be useful if you disable all actions (to go to a "readonly" state), and then want to come back to a readwrite mode.
Definition at line 295 of file k3command.cpp.
The documentation for this class was generated from the following files: