Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkCallbackFromGUIThread.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
14 
15 #include <QApplication>
16 #include <QEvent>
17 
19 class QmitkCallbackEvent : public QEvent
20 {
21 public:
22  QmitkCallbackEvent(itk::Command *cmd, itk::EventObject *e) : QEvent(QEvent::User), m_Command(cmd), m_Event(e) {}
23  ~QmitkCallbackEvent() override { delete m_Event; }
24  itk::Command *command() { return m_Command; }
25  itk::EventObject *itkevent() { return m_Event; }
26 protected:
27  itk::Command::Pointer m_Command;
28  itk::EventObject *m_Event;
29 };
30 
32 {
34 }
35 
37 {
38 }
39 
40 void QmitkCallbackFromGUIThread::CallThisFromGUIThread(itk::Command *cmd, itk::EventObject *e)
41 {
42  QApplication::instance()->postEvent(this, new QmitkCallbackEvent(cmd, e));
43 }
44 
46 {
47  QmitkCallbackEvent *event(dynamic_cast<QmitkCallbackEvent *>(e));
48 
49  if (!event)
50  return false;
51 
52  itk::Command *cmd(event->command());
53 
54  if (cmd)
55  {
56  if (event->itkevent())
57  {
58  cmd->Execute((const itk::Object *)nullptr, // no itk::Object here
59  *(event->itkevent()));
60  }
61  else
62  {
63  const itk::NoEvent dummyEvent;
64  cmd->Execute((const itk::Object *)nullptr, // no itk::Object here
65  dummyEvent);
66  }
67  }
68 
69  return true;
70 }
static void RegisterImplementation(CallbackFromGUIThreadImplementation *implementation)
To be called by a toolkit specific CallbackFromGUIThreadImplementation.
void CallThisFromGUIThread(itk::Command *, itk::EventObject *) override
Change the current application cursor.