Medical Imaging Interaction Toolkit  2018.4.99-87d68d9f
Medical Imaging Interaction Toolkit
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 (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 
16 {
17  static std::string s = "org.mitk.services.UltrasoundCustomWidget.deviceClass";
18  return s;
19 }
20 
22  : QWidget(parent), m_IsClonedForQt(false)
23 {
24 }
25 
27 {
28 }
29 
31 {
32  m_Device = device;
33 
34  if ( device ) { this->OnDeviceSet(); }
35 }
36 
38 {
39  return m_Device;
40 }
41 
43 {
44  QmitkUSAbstractCustomWidget* clonedWidget = this->Clone(parent);
45  clonedWidget->Initialize(); // initialize the Qt stuff of the widget
46  clonedWidget->m_IsClonedForQt = true; // set flag that this object was really cloned
47  return clonedWidget;
48 }
49 
51 {
52  us::ServiceProperties result;
53 
55 
56  return result;
57 }
58 
59 void QmitkUSAbstractCustomWidget::showEvent ( QShowEvent * event )
60 {
61  // using object from micro service directly in Qt without cloning it first
62  // can cause problems when Qt deletes this object -> throw an exception to
63  // show that object should be cloned before
64  if ( ! m_IsClonedForQt )
65  {
66  MITK_ERROR << "Object wasn't cloned with CloneForQt() before using as QWidget.";
67  mitkThrow() << "Object wasn't cloned with CloneForQt() before using as QWidget.";
68  }
69 
70  QWidget::showEvent(event);
71 }
virtual QmitkUSAbstractCustomWidget * Clone(QWidget *parent=nullptr) const =0
Subclass must implement this method to return a pointer to a copy of the object.
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::...
#define MITK_ERROR
Definition: mitkLogMacros.h:20
void SetDevice(mitk::USDevice::Pointer device)
static std::string US_DEVICE_PROPKEY_CLASS()
Property key for the class name of corresponding us device object.
#define mitkThrow()
us::ServiceProperties GetServiceProperties() const
Returns the properties of the micro service. Properties consist of just the device class of the corre...
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
QmitkUSAbstractCustomWidget(QWidget *parent=nullptr)
QmitkUSAbstractCustomWidget * CloneForQt(QWidget *parent=nullptr) const
Return pointer to copy of the object. Internally use of QmitkUSAbstractCustomWidget::Clone() with add...
mitk::USDevice::Pointer GetDevice() const
virtual std::string GetDeviceClass() const =0
Subclass must implement this method to return device class of corresponding mitk::USDevice.