comparison base/CommandHistory.h @ 47:bac8b14ab355

* Add menu for re-adding existing layers * Fix layer tree window so that it at least approximates correct * Add bundled operations in command history, for use with things like multiple consecutive changes to a parameter value * Disambiguate plugins that happen to have identical descriptions * Add spectral centroid plugin (could use some parameters!) * Some other fixes
author Chris Cannam
date Fri, 17 Mar 2006 17:38:28 +0000
parents 5364a9d338a2
children 39ae3dee27b9
comparison
equal deleted inserted replaced
46:5364a9d338a2 47:bac8b14ab355
30 class Command; 30 class Command;
31 class MacroCommand; 31 class MacroCommand;
32 class QAction; 32 class QAction;
33 class QMenu; 33 class QMenu;
34 class QToolBar; 34 class QToolBar;
35 class QTimer;
35 36
36 /** 37 /**
37 * The CommandHistory class stores a list of executed commands and 38 * The CommandHistory class stores a list of executed commands and
38 * maintains Undo and Redo actions synchronised with those commands. 39 * maintains Undo and Redo actions synchronised with those commands.
39 * 40 *
55 void clear(); 56 void clear();
56 57
57 void registerMenu(QMenu *menu); 58 void registerMenu(QMenu *menu);
58 void registerToolbar(QToolBar *toolbar); 59 void registerToolbar(QToolBar *toolbar);
59 60
60 void addCommand(Command *command, bool execute = true); 61 /**
62 * Add a command to the command history.
63 *
64 * If execute is true, the command will be executed before being
65 * added. Otherwise it will be assumed to have been already
66 * executed -- a command should not be added to the history unless
67 * its work has actually been done somehow!
68 *
69 * If a compound operation is in use (see startCompoundOperation
70 * below), the execute status of the compound operation will
71 * override any value of execute passed to this method.
72 *
73 * If bundle is true, the command will be a candidate for bundling
74 * with any adjacent bundeable commands that have the same name,
75 * into a single compound command. This is useful for small
76 * commands that may be executed repeatedly altering the same data
77 * (e.g. type text, set a parameter) whose number and extent is
78 * not known in advance. The bundle parameter will be ignored if
79 * a compound operation is already in use.
80 */
81 void addCommand(Command *command, bool execute = true, bool bundle = false);
61 82
62 /// Return the maximum number of items in the undo history. 83 /// Return the maximum number of items in the undo history.
63 int getUndoLimit() const { return m_undoLimit; } 84 int getUndoLimit() const { return m_undoLimit; }
64 85
65 /// Set the maximum number of items in the undo history. 86 /// Set the maximum number of items in the undo history.
74 /// Return the maximum number of items visible in undo and redo menus. 95 /// Return the maximum number of items visible in undo and redo menus.
75 int getMenuLimit() const { return m_menuLimit; } 96 int getMenuLimit() const { return m_menuLimit; }
76 97
77 /// Set the maximum number of items in the menus. 98 /// Set the maximum number of items in the menus.
78 void setMenuLimit(int limit); 99 void setMenuLimit(int limit);
100
101 /// Return the time after which a bundle will be closed if nothing is added.
102 int getBundleTimeout() const { return m_bundleTimeout; }
103
104 /// Set the time after which a bundle will be closed if nothing is added.
105 void setBundleTimeout(int msec);
79 106
80 /// Start recording commands to batch up into a single compound command. 107 /// Start recording commands to batch up into a single compound command.
81 void startCompoundOperation(QString name, bool execute); 108 void startCompoundOperation(QString name, bool execute);
82 109
83 /// Finish recording commands and store the compound command. 110 /// Finish recording commands and store the compound command.
107 protected slots: 134 protected slots:
108 void undo(); 135 void undo();
109 void redo(); 136 void redo();
110 void undoActivated(QAction *); 137 void undoActivated(QAction *);
111 void redoActivated(QAction *); 138 void redoActivated(QAction *);
112 139 void bundleTimerTimeout();
140
113 signals: 141 signals:
114 /** 142 /**
115 * Emitted whenever a command has just been executed or 143 * Emitted whenever a command has just been executed or
116 * unexecuted, whether by addCommand, undo, or redo. 144 * unexecuted, whether by addCommand, undo, or redo.
117 */ 145 */
155 int m_undoLimit; 183 int m_undoLimit;
156 int m_redoLimit; 184 int m_redoLimit;
157 int m_menuLimit; 185 int m_menuLimit;
158 int m_savedAt; 186 int m_savedAt;
159 187
160 MacroCommand *m_currentMacro; 188 MacroCommand *m_currentCompound;
161 bool m_executeMacro; 189 bool m_executeCompound;
162 void addToMacro(Command *command); 190 void addToCompound(Command *command);
191
192 MacroCommand *m_currentBundle;
193 QString m_currentBundleName;
194 QTimer *m_bundleTimer;
195 int m_bundleTimeout;
196 void addToBundle(Command *command, bool execute);
197 void closeBundle();
163 198
164 void updateActions(); 199 void updateActions();
165 200
166 void clipCommands(); 201 void clipCommands();
167 202