MCPcopy Create free account
hub / github.com/MITK/MITK / SetHandler

Method SetHandler

Plugins/org.blueberry.core.commands/src/berryCommand.cpp:407–464  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

405}
406
407bool Command::SetHandler(const IHandler::Pointer handler)
408{
409 if (handler == this->handler)
410 {
411 return false;
412 }
413
414 // Swap the state around.
415 const QList<QString> stateIds(this->GetStateIds());
416 for (int i = 0; i < stateIds.size(); ++i)
417 {
418 const QString stateId = stateIds[i];
419 if (IObjectWithState::Pointer stateHandler = this->handler.Cast<IObjectWithState>())
420 {
421 stateHandler->RemoveState(stateId);
422 }
423 if (IObjectWithState::Pointer stateHandler = handler.Cast<IObjectWithState>())
424 {
425 const State::Pointer stateToAdd(this->GetState(stateId));
426 stateHandler->AddState(stateId, stateToAdd);
427 }
428 }
429
430 bool enabled = this->IsEnabled();
431 if (this->handler)
432 {
433 this->handler->RemoveHandlerListener(this->GetHandlerListener());
434 }
435
436 // Update the handler, and flush the string representation.
437 this->handler = handler;
438 if (this->handler)
439 {
440 this->handler->AddHandlerListener(this->GetHandlerListener());
441 }
442 this->str = "";
443
444 // Debugging output
445 if ((DEBUG_HANDLERS)
446 && ((DEBUG_HANDLERS_COMMAND_ID.isEmpty()) || (DEBUG_HANDLERS_COMMAND_ID == id)))
447 {
448 QString buffer("Command('");
449 buffer += id + "') has changed to ";
450 if (!handler) {
451 buffer += "no handler";
452 } else {
453 buffer += "\'" + handler->ToString() + "' as its handler";
454 }
455 CommandTracing::PrintTrace("HANDLERS", buffer);
456 }
457
458 // Send notification
459 CommandEvent::Pointer cmdEvent(new CommandEvent(Command::Pointer(this), false, false, false, true,
460 false, false, false, false, enabled != this->IsEnabled()));
461 this->FireCommandChanged(cmdEvent);
462
463 return true;
464}

Callers 5

~RestoreHandlerStateMethod · 0.80
~RestoreHandlerMethod · 0.80
UpdateCommandMethod · 0.80

Calls 11

IsEnabledMethod · 0.95
GetHandlerListenerMethod · 0.95
FireCommandChangedMethod · 0.95
RemoveHandlerListenerMethod · 0.80
AddHandlerListenerMethod · 0.80
GetStateIdsMethod · 0.45
sizeMethod · 0.45
RemoveStateMethod · 0.45
GetStateMethod · 0.45
AddStateMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected