comparison widgets/CommandHistory.cpp @ 585:f4960f8ce798 debug-output

Convert many cerrs to DEBUGs
author Chris Cannam
date Mon, 16 May 2011 17:19:25 +0100
parents 4ba0476ebbb6
children 4806715f7a19
comparison
equal deleted inserted replaced
584:1fe7951a61e8 585:f4960f8ce798
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 std::cerr << "CommandHistory::clear()" << std::endl; 104 DEBUG << "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 std::cerr << "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 << ")" << std::endl; 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;
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 std::cerr << "CommandHistory::clearing redo stack" << std::endl; 163 DEBUG << "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 std::cerr << "CommandHistory::addToBundle: " 195 DEBUG << "CommandHistory::addToBundle: "
196 << command->getName().toStdString() 196 << command->getName() << ": closing current bundle" << endl;
197 << ": closing current bundle" << std::endl;
198 #endif 197 #endif
199 closeBundle(); 198 closeBundle();
200 } 199 }
201 } 200 }
202 201
203 if (!command) return; 202 if (!command) return;
204 203
205 if (!m_currentBundle) { 204 if (!m_currentBundle) {
206 205
207 #ifdef DEBUG_COMMAND_HISTORY 206 #ifdef DEBUG_COMMAND_HISTORY
208 std::cerr << "CommandHistory::addToBundle: " 207 DEBUG << "CommandHistory::addToBundle: "
209 << command->getName().toStdString() 208 << command->getName() << ": creating new bundle" << endl;
210 << ": creating new bundle" << std::endl;
211 #endif 209 #endif
212 210
213 // need to addCommand before setting m_currentBundle, as addCommand 211 // need to addCommand before setting m_currentBundle, as addCommand
214 // with bundle false will reset m_currentBundle to 0 212 // with bundle false will reset m_currentBundle to 0
215 MacroCommand *mc = new BundleCommand(command->getName()); 213 MacroCommand *mc = new BundleCommand(command->getName());
219 m_currentBundle = mc; 217 m_currentBundle = mc;
220 m_currentBundleName = command->getName(); 218 m_currentBundleName = command->getName();
221 } 219 }
222 220
223 #ifdef DEBUG_COMMAND_HISTORY 221 #ifdef DEBUG_COMMAND_HISTORY
224 std::cerr << "CommandHistory::addToBundle: " 222 DEBUG << "CommandHistory::addToBundle: "
225 << command->getName().toStdString() 223 << command->getName() << ": adding to bundle" << endl;
226 << ": adding to bundle" << std::endl;
227 #endif 224 #endif
228 225
229 if (execute) command->execute(); 226 if (execute) command->execute();
230 m_currentBundle->addCommand(command); 227 m_currentBundle->addCommand(command);
231 228
244 241
245 void 242 void
246 CommandHistory::closeBundle() 243 CommandHistory::closeBundle()
247 { 244 {
248 #ifdef DEBUG_COMMAND_HISTORY 245 #ifdef DEBUG_COMMAND_HISTORY
249 std::cerr << "CommandHistory::closeBundle" << std::endl; 246 DEBUG << "CommandHistory::closeBundle" << endl;
250 #endif 247 #endif
251 248
252 if (m_currentBundle) emit activity(m_currentBundle->getName()); 249 if (m_currentBundle) emit activity(m_currentBundle->getName());
253 m_currentBundle = 0; 250 m_currentBundle = 0;
254 m_currentBundleName = ""; 251 m_currentBundleName = "";
256 253
257 void 254 void
258 CommandHistory::bundleTimerTimeout() 255 CommandHistory::bundleTimerTimeout()
259 { 256 {
260 #ifdef DEBUG_COMMAND_HISTORY 257 #ifdef DEBUG_COMMAND_HISTORY
261 std::cerr << "CommandHistory::bundleTimerTimeout: bundle is " << m_currentBundle << std::endl; 258 DEBUG << "CommandHistory::bundleTimerTimeout: bundle is " << m_currentBundle << endl;
262 #endif 259 #endif
263 260
264 closeBundle(); 261 closeBundle();
265 } 262 }
266 263
267 void 264 void
268 CommandHistory::addToCompound(Command *command, bool execute) 265 CommandHistory::addToCompound(Command *command, bool execute)
269 { 266 {
270 #ifdef DEBUG_COMMAND_HISTORY 267 #ifdef DEBUG_COMMAND_HISTORY
271 std::cerr << "CommandHistory::addToCompound: " << command->getName().toLocal8Bit().data() << std::endl; 268 DEBUG << "CommandHistory::addToCompound: " << command->getName().toLocal8Bit().data() << endl;
272 #endif 269 #endif
273 if (!m_currentCompound) { 270 if (!m_currentCompound) {
274 std::cerr << "CommandHistory::addToCompound: ERROR: no compound operation in progress!" << std::endl; 271 DEBUG << "CommandHistory::addToCompound: ERROR: no compound operation in progress!" << endl;
275 return; 272 return;
276 } 273 }
277 274
278 if (execute) command->execute(); 275 if (execute) command->execute();
279 m_currentCompound->addCommand(command); 276 m_currentCompound->addCommand(command);
281 278
282 void 279 void
283 CommandHistory::startCompoundOperation(QString name, bool execute) 280 CommandHistory::startCompoundOperation(QString name, bool execute)
284 { 281 {
285 if (m_currentCompound) { 282 if (m_currentCompound) {
286 std::cerr << "CommandHistory::startCompoundOperation: ERROR: compound operation already in progress!" << std::endl; 283 DEBUG << "CommandHistory::startCompoundOperation: ERROR: compound operation already in progress!" << endl;
287 std::cerr << "(name is " << m_currentCompound->getName().toLocal8Bit().data() << ")" << std::endl; 284 std::cerr << "(name is " << m_currentCompound->getName().toLocal8Bit().data() << ")" << std::endl;
288 return; 285 return;
289 } 286 }
290 287
291 closeBundle(); 288 closeBundle();
296 293
297 void 294 void
298 CommandHistory::endCompoundOperation() 295 CommandHistory::endCompoundOperation()
299 { 296 {
300 if (!m_currentCompound) { 297 if (!m_currentCompound) {
301 std::cerr << "CommandHistory::endCompoundOperation: ERROR: no compound operation in progress!" << std::endl; 298 DEBUG << "CommandHistory::endCompoundOperation: ERROR: no compound operation in progress!" << endl;
302 return; 299 return;
303 } 300 }
304 301
305 MacroCommand *toAdd = m_currentCompound; 302 MacroCommand *toAdd = m_currentCompound;
306 m_currentCompound = 0; 303 m_currentCompound = 0;
330 CommandHistory::undo() 327 CommandHistory::undo()
331 { 328 {
332 if (m_undoStack.empty()) return; 329 if (m_undoStack.empty()) return;
333 330
334 #ifdef DEBUG_COMMAND_HISTORY 331 #ifdef DEBUG_COMMAND_HISTORY
335 std::cerr << "CommandHistory::undo()" << std::endl; 332 DEBUG << "CommandHistory::undo()" << endl;
336 #endif 333 #endif
337 334
338 closeBundle(); 335 closeBundle();
339 336
340 Command *command = m_undoStack.top(); 337 Command *command = m_undoStack.top();
356 CommandHistory::redo() 353 CommandHistory::redo()
357 { 354 {
358 if (m_redoStack.empty()) return; 355 if (m_redoStack.empty()) return;
359 356
360 #ifdef DEBUG_COMMAND_HISTORY 357 #ifdef DEBUG_COMMAND_HISTORY
361 std::cerr << "CommandHistory::redo()" << std::endl; 358 DEBUG << "CommandHistory::redo()" << endl;
362 #endif 359 #endif
363 360
364 closeBundle(); 361 closeBundle();
365 362
366 Command *command = m_redoStack.top(); 363 Command *command = m_redoStack.top();
437 CommandStack tempStack; 434 CommandStack tempStack;
438 435
439 for (i = 0; i < limit; ++i) { 436 for (i = 0; i < limit; ++i) {
440 #ifdef DEBUG_COMMAND_HISTORY 437 #ifdef DEBUG_COMMAND_HISTORY
441 Command *command = stack.top(); 438 Command *command = stack.top();
442 std::cerr << "CommandHistory::clipStack: Saving recent command: " << command->getName().toLocal8Bit().data() << " at " << command << std::endl; 439 DEBUG << "CommandHistory::clipStack: Saving recent command: " << command->getName().toLocal8Bit().data() << " at " << command << endl;
443 #endif 440 #endif
444 tempStack.push(stack.top()); 441 tempStack.push(stack.top());
445 stack.pop(); 442 stack.pop();
446 } 443 }
447 444
459 { 456 {
460 while (!stack.empty()) { 457 while (!stack.empty()) {
461 Command *command = stack.top(); 458 Command *command = stack.top();
462 // 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
463 #ifdef DEBUG_COMMAND_HISTORY 460 #ifdef DEBUG_COMMAND_HISTORY
464 std::cerr << "CommandHistory::clearStack: About to delete command " << command << std::endl; 461 DEBUG << "CommandHistory::clearStack: About to delete command " << command << endl;
465 #endif 462 #endif
466 delete command; 463 delete command;
467 stack.pop(); 464 stack.pop();
468 } 465 }
469 } 466 }