Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
QmitkUSAbstractCustomWidget.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 
20 #include <usModuleContext.h>
21 
23 {
24  static std::string s = "ork.mitk.services.UltrasoundCustomWidget.deviceClass";
25  return s;
26 }
27 
29  : QWidget(parent), m_PrototypeServiceFactory(0), m_IsClonedForQt(false)
30 {
31 }
32 
34 {
35  delete m_PrototypeServiceFactory;
36 }
37 
39 {
40  m_Device = device;
41 
42  if ( device ) { this->OnDeviceSet(); }
43 }
44 
46 {
47  return m_Device;
48 }
49 
51 {
52  QmitkUSAbstractCustomWidget* clonedWidget = this->Clone(parent);
53  clonedWidget->Initialize(); // initialize the Qt stuff of the widget
54  clonedWidget->m_IsClonedForQt = true; // set flag that this object was really cloned
55  return clonedWidget;
56 }
57 
59 {
60  us::ServiceProperties result;
61 
63 
64  return result;
65 }
66 
67 void QmitkUSAbstractCustomWidget::showEvent ( QShowEvent * event )
68 {
69  // using object from micro service directly in Qt without cloning it first
70  // can cause problems when Qt deletes this object -> throw an exception to
71  // show that object should be cloned before
72  if ( ! m_IsClonedForQt )
73  {
74  MITK_ERROR << "Object wasn't cloned with CloneForQt() before using as QWidget.";
75  mitkThrow() << "Object wasn't cloned with CloneForQt() before using as QWidget.";
76  }
77 
78  QWidget::showEvent(event);
79 }
virtual void OnDeviceSet()=0
Called every time a mitk::USDevice was set with QmitkUSAbstractCustomWidget::SetDevice(). A sublcass can implement this function to handle initialiation actions necessary when a device was set.
void showEvent(QShowEvent *event) override
Overwritten Qt even method. It is checked if the object was cloned with QmitkUSAbstractCustomWidget::...
QmitkUSAbstractCustomWidget * CloneForQt(QWidget *parent=0) const
Return pointer to copy of the object. Internally use of QmitkUSAbstractCustomWidget::Clone() with add...
#define MITK_ERROR
Definition: mitkLogMacros.h:24
void SetDevice(mitk::USDevice::Pointer device)
us::ServiceProperties GetServiceProperties() const
Returns the properties of the micro service. Properties consist of just the device class of the corre...
mitk::USDevice::Pointer GetDevice() const
static std::string US_DEVICE_PROPKEY_CLASS()
Property key for the class name of corresponding us device object.
#define mitkThrow()
virtual void Initialize()=0
Method for initializing the Qt stuff of the widget (setupUI, connect). This method will be called in ...
Abstract superclass for all custom control widgets of mitk::USDevice classes.
US_UNORDERED_MAP_TYPE< std::string, Any > ServiceProperties
virtual QmitkUSAbstractCustomWidget * Clone(QWidget *parent=0) const =0
Subclass must implement this method to return a pointer to a copy of the object.
virtual std::string GetDeviceClass() const =0
Subclass must implement this method to return device class of corresponding mitk::USDevice.