Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
18 
19 #include <QApplication>
20 #include <QEvent>
21 
23 class QmitkCallbackEvent : public QEvent
24 {
25 public:
26  QmitkCallbackEvent(itk::Command *cmd, itk::EventObject *e) : QEvent(QEvent::User), m_Command(cmd), m_Event(e) {}
27  ~QmitkCallbackEvent() { delete m_Event; }
28  itk::Command *command() { return m_Command; }
29  itk::EventObject *itkevent() { return m_Event; }
30 protected:
31  itk::Command::Pointer m_Command;
32  itk::EventObject *m_Event;
33 };
34 
36 {
38 }
39 
41 {
42 }
43 
44 void QmitkCallbackFromGUIThread::CallThisFromGUIThread(itk::Command *cmd, itk::EventObject *e)
45 {
46  QApplication::instance()->postEvent(this, new QmitkCallbackEvent(cmd, e));
47 }
48 
50 {
51  QmitkCallbackEvent *event(dynamic_cast<QmitkCallbackEvent *>(e));
52 
53  if (!event)
54  return false;
55 
56  itk::Command *cmd(event->command());
57 
58  if (cmd)
59  {
60  if (event->itkevent())
61  {
62  cmd->Execute((const itk::Object *)nullptr, // no itk::Object here
63  *(event->itkevent()));
64  }
65  else
66  {
67  const itk::NoEvent dummyEvent;
68  cmd->Execute((const itk::Object *)nullptr, // no itk::Object here
69  dummyEvent);
70  }
71  }
72 
73  return true;
74 }
itk::SmartPointer< Self > Pointer
static void RegisterImplementation(CallbackFromGUIThreadImplementation *implementation)
To be called by a toolkit specific CallbackFromGUIThreadImplementation.
virtual void CallThisFromGUIThread(itk::Command *, itk::EventObject *) override
Change the current application cursor.
virtual bool event(QEvent *e) override