comparison widgets/CommandHistory.cpp @ 587:4806715f7a19

Seems to be a bad idea to use plain DEBUG symbol on OS/X (system wants it)
author Chris Cannam
date Tue, 14 Jun 2011 15:27:05 +0100
parents f4960f8ce798
children 1a0dfcbffaf1
comparison
equal deleted inserted replaced
586:1ae54a29e59e 587:4806715f7a19
99 99
100 void 100 void
101 CommandHistory::clear() 101 CommandHistory::clear()
102 { 102 {
103 #ifdef DEBUG_COMMAND_HISTORY 103 #ifdef DEBUG_COMMAND_HISTORY
104 DEBUG << "CommandHistory::clear()" << endl; 104 SVDEBUG << "CommandHistory::clear()" << endl;
105 #endif 105 #endif
106 closeBundle(); 106 closeBundle();
107 m_savedAt = -1; 107 m_savedAt = -1;
108 clearStack(m_undoStack); 108 clearStack(m_undoStack);
109 clearStack(m_redoStack); 109 clearStack(m_redoStack);
141 CommandHistory::addCommand(Command *command, bool execute, bool bundle) 141 CommandHistory::addCommand(Command *command, bool execute, bool bundle)
142 { 142 {
143 if (!command) return; 143 if (!command) return;
144 144
145 #ifdef DEBUG_COMMAND_HISTORY 145 #ifdef DEBUG_COMMAND_HISTORY
146 DEBUG << "CommandHistory::addCommand: " << command->getName().toLocal8Bit().data() << " of type " << typeid(*command).name() << " at " << command << ": execute = " << execute << ", bundle = " << bundle << " (m_currentCompound = " << m_currentCompound << ", m_currentBundle = " << m_currentBundle << ")" << endl; 146 SVDEBUG << "CommandHistory::addCommand: " << command->getName().toLocal8Bit().data() << " of type " << typeid(*command).name() << " at " << command << ": execute = " << execute << ", bundle = " << bundle << " (m_currentCompound = " << m_currentCompound << ", m_currentBundle = " << m_currentBundle << ")" << endl;
147 #endif 147 #endif
148 148
149 if (m_currentCompound) { 149 if (m_currentCompound) {
150 addToCompound(command, execute); 150 addToCompound(command, execute);
151 return; 151 return;
158 closeBundle(); 158 closeBundle();
159 } 159 }
160 160
161 #ifdef DEBUG_COMMAND_HISTORY 161 #ifdef DEBUG_COMMAND_HISTORY
162 if (!m_redoStack.empty()) { 162 if (!m_redoStack.empty()) {
163 DEBUG << "CommandHistory::clearing redo stack" << endl; 163 SVDEBUG << "CommandHistory::clearing redo stack" << endl;
164 } 164 }
165 #endif 165 #endif
166 166
167 // We can't redo after adding a command 167 // We can't redo after adding a command
168 clearStack(m_redoStack); 168 clearStack(m_redoStack);
190 CommandHistory::addToBundle(Command *command, bool execute) 190 CommandHistory::addToBundle(Command *command, bool execute)
191 { 191 {
192 if (m_currentBundle) { 192 if (m_currentBundle) {
193 if (!command || (command->getName() != m_currentBundleName)) { 193 if (!command || (command->getName() != m_currentBundleName)) {
194 #ifdef DEBUG_COMMAND_HISTORY 194 #ifdef DEBUG_COMMAND_HISTORY
195 DEBUG << "CommandHistory::addToBundle: " 195 SVDEBUG << "CommandHistory::addToBundle: "
196 << command->getName() << ": closing current bundle" << endl; 196 << command->getName() << ": closing current bundle" << endl;
197 #endif 197 #endif
198 closeBundle(); 198 closeBundle();
199 } 199 }
200 } 200 }
202 if (!command) return; 202 if (!command) return;
203 203
204 if (!m_currentBundle) { 204 if (!m_currentBundle) {
205 205
206 #ifdef DEBUG_COMMAND_HISTORY 206 #ifdef DEBUG_COMMAND_HISTORY
207 DEBUG << "CommandHistory::addToBundle: " 207 SVDEBUG << "CommandHistory::addToBundle: "
208 << command->getName() << ": creating new bundle" << endl; 208 << command->getName() << ": creating new bundle" << endl;
209 #endif 209 #endif
210 210
211 // need to addCommand before setting m_currentBundle, as addCommand 211 // need to addCommand before setting m_currentBundle, as addCommand
212 // with bundle false will reset m_currentBundle to 0 212 // with bundle false will reset m_currentBundle to 0
217 m_currentBundle = mc; 217 m_currentBundle = mc;
218 m_currentBundleName = command->getName(); 218 m_currentBundleName = command->getName();
219 } 219 }
220 220
221 #ifdef DEBUG_COMMAND_HISTORY 221 #ifdef DEBUG_COMMAND_HISTORY
222 DEBUG << "CommandHistory::addToBundle: " 222 SVDEBUG << "CommandHistory::addToBundle: "
223 << command->getName() << ": adding to bundle" << endl; 223 << command->getName() << ": adding to bundle" << endl;
224 #endif 224 #endif
225 225
226 if (execute) command->execute(); 226 if (execute) command->execute();
227 m_currentBundle->addCommand(command); 227 m_currentBundle->addCommand(command);
241 241
242 void 242 void
243 CommandHistory::closeBundle() 243 CommandHistory::closeBundle()
244 { 244 {
245 #ifdef DEBUG_COMMAND_HISTORY 245 #ifdef DEBUG_COMMAND_HISTORY
246 DEBUG << "CommandHistory::closeBundle" << endl; 246 SVDEBUG << "CommandHistory::closeBundle" << endl;
247 #endif 247 #endif
248 248
249 if (m_currentBundle) emit activity(m_currentBundle->getName()); 249 if (m_currentBundle) emit activity(m_currentBundle->getName());
250 m_currentBundle = 0; 250 m_currentBundle = 0;
251 m_currentBundleName = ""; 251 m_currentBundleName = "";
253 253
254 void 254 void
255 CommandHistory::bundleTimerTimeout() 255 CommandHistory::bundleTimerTimeout()
256 { 256 {
257 #ifdef DEBUG_COMMAND_HISTORY 257 #ifdef DEBUG_COMMAND_HISTORY
258 DEBUG << "CommandHistory::bundleTimerTimeout: bundle is " << m_currentBundle << endl; 258 SVDEBUG << "CommandHistory::bundleTimerTimeout: bundle is " << m_currentBundle << endl;
259 #endif 259 #endif
260 260
261 closeBundle(); 261 closeBundle();
262 } 262 }
263 263
264 void 264 void
265 CommandHistory::addToCompound(Command *command, bool execute) 265 CommandHistory::addToCompound(Command *command, bool execute)
266 { 266 {
267 #ifdef DEBUG_COMMAND_HISTORY 267 #ifdef DEBUG_COMMAND_HISTORY
268 DEBUG << "CommandHistory::addToCompound: " << command->getName().toLocal8Bit().data() << endl; 268 SVDEBUG << "CommandHistory::addToCompound: " << command->getName().toLocal8Bit().data() << endl;
269 #endif 269 #endif
270 if (!m_currentCompound) { 270 if (!m_currentCompound) {
271 DEBUG << "CommandHistory::addToCompound: ERROR: no compound operation in progress!" << endl; 271 SVDEBUG << "CommandHistory::addToCompound: ERROR: no compound operation in progress!" << endl;
272 return; 272 return;
273 } 273 }
274 274
275 if (execute) command->execute(); 275 if (execute) command->execute();
276 m_currentCompound->addCommand(command); 276 m_currentCompound->addCommand(command);
278 278
279 void 279 void
280 CommandHistory::startCompoundOperation(QString name, bool execute) 280 CommandHistory::startCompoundOperation(QString name, bool execute)
281 { 281 {
282 if (m_currentCompound) { 282 if (m_currentCompound) {
283 DEBUG << "CommandHistory::startCompoundOperation: ERROR: compound operation already in progress!" << endl; 283 SVDEBUG << "CommandHistory::startCompoundOperation: ERROR: compound operation already in progress!" << endl;
284 std::cerr << "(name is " << m_currentCompound->getName().toLocal8Bit().data() << ")" << std::endl; 284 std::cerr << "(name is " << m_currentCompound->getName().toLocal8Bit().data() << ")" << std::endl;
285 return; 285 return;
286 } 286 }
287 287
288 closeBundle(); 288 closeBundle();
293 293
294 void 294 void
295 CommandHistory::endCompoundOperation() 295 CommandHistory::endCompoundOperation()
296 { 296 {
297 if (!m_currentCompound) { 297 if (!m_currentCompound) {
298 DEBUG << "CommandHistory::endCompoundOperation: ERROR: no compound operation in progress!" << endl; 298 SVDEBUG << "CommandHistory::endCompoundOperation: ERROR: no compound operation in progress!" << endl;
299 return; 299 return;
300 } 300 }
301 301
302 MacroCommand *toAdd = m_currentCompound; 302 MacroCommand *toAdd = m_currentCompound;
303 m_currentCompound = 0; 303 m_currentCompound = 0;
327 CommandHistory::undo() 327 CommandHistory::undo()
328 { 328 {
329 if (m_undoStack.empty()) return; 329 if (m_undoStack.empty()) return;
330 330
331 #ifdef DEBUG_COMMAND_HISTORY 331 #ifdef DEBUG_COMMAND_HISTORY
332 DEBUG << "CommandHistory::undo()" << endl; 332 SVDEBUG << "CommandHistory::undo()" << endl;
333 #endif 333 #endif
334 334
335 closeBundle(); 335 closeBundle();
336 336
337 Command *command = m_undoStack.top(); 337 Command *command = m_undoStack.top();
353 CommandHistory::redo() 353 CommandHistory::redo()
354 { 354 {
355 if (m_redoStack.empty()) return; 355 if (m_redoStack.empty()) return;
356 356
357 #ifdef DEBUG_COMMAND_HISTORY 357 #ifdef DEBUG_COMMAND_HISTORY
358 DEBUG << "CommandHistory::redo()" << endl; 358 SVDEBUG << "CommandHistory::redo()" << endl;
359 #endif 359 #endif
360 360
361 closeBundle(); 361 closeBundle();
362 362
363 Command *command = m_redoStack.top(); 363 Command *command = m_redoStack.top();
434 CommandStack tempStack; 434 CommandStack tempStack;
435 435
436 for (i = 0; i < limit; ++i) { 436 for (i = 0; i < limit; ++i) {
437 #ifdef DEBUG_COMMAND_HISTORY 437 #ifdef DEBUG_COMMAND_HISTORY
438 Command *command = stack.top(); 438 Command *command = stack.top();
439 DEBUG << "CommandHistory::clipStack: Saving recent command: " << command->getName().toLocal8Bit().data() << " at " << command << endl; 439 SVDEBUG << "CommandHistory::clipStack: Saving recent command: " << command->getName().toLocal8Bit().data() << " at " << command << endl;
440 #endif 440 #endif
441 tempStack.push(stack.top()); 441 tempStack.push(stack.top());
442 stack.pop(); 442 stack.pop();
443 } 443 }
444 444
456 { 456 {
457 while (!stack.empty()) { 457 while (!stack.empty()) {
458 Command *command = stack.top(); 458 Command *command = stack.top();
459 // Not safe to call getName() on a command about to be deleted 459 // Not safe to call getName() on a command about to be deleted
460 #ifdef DEBUG_COMMAND_HISTORY 460 #ifdef DEBUG_COMMAND_HISTORY
461 DEBUG << "CommandHistory::clearStack: About to delete command " << command << endl; 461 SVDEBUG << "CommandHistory::clearStack: About to delete command " << command << endl;
462 #endif 462 #endif
463 delete command; 463 delete command;
464 stack.pop(); 464 stack.pop();
465 } 465 }
466 } 466 }