Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkBoolPropertyWidget.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 <mitkPropertyObserver.h>
16 
17 class _BoolPropertyWidgetImpl : public mitk::PropertyEditor
18 {
19 public:
20  _BoolPropertyWidgetImpl(mitk::BoolProperty *property, QCheckBox *checkBox)
21  : PropertyEditor(property), m_BoolProperty(property), m_CheckBox(checkBox)
22  {
23  }
24 
25  void PropertyChanged() override
26  {
27  if (m_Property)
28  m_CheckBox->setChecked(m_BoolProperty->GetValue());
29  }
30 
31  void PropertyRemoved() override
32  {
33  m_Property = nullptr;
34  m_BoolProperty = nullptr;
35  // display "no certain value"
36  m_CheckBox->blockSignals(true);
37  m_CheckBox->setTristate(true);
38  m_CheckBox->setCheckState(Qt::PartiallyChecked);
39  m_CheckBox->setEnabled(false);
40  m_CheckBox->blockSignals(false);
41  }
42 
43  void ValueChanged(bool value)
44  {
45  this->BeginModifyProperty(); // deregister from events
46  m_BoolProperty->SetValue(value);
47  this->EndModifyProperty(); // again register for events
48  }
49 
50 protected:
51  mitk::BoolProperty *m_BoolProperty;
52  QCheckBox *m_CheckBox;
53 };
54 
55 QmitkBoolPropertyWidget::QmitkBoolPropertyWidget(QWidget *parent) : QCheckBox(parent), m_PropEditorImpl(nullptr)
56 {
57  setEnabled(false);
58 
59  connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggle(bool)));
60 }
61 
62 QmitkBoolPropertyWidget::QmitkBoolPropertyWidget(const QString &text, QWidget *parent)
63  : QCheckBox(text, parent), m_PropEditorImpl(nullptr)
64 {
65  setEnabled(false);
66 
67  connect(this, SIGNAL(toggled(bool)), this, SLOT(onToggle(bool)));
68 }
69 
71 {
72  delete m_PropEditorImpl;
73 }
74 
76 {
77  if (m_PropEditorImpl)
78  {
79  delete m_PropEditorImpl;
80  m_PropEditorImpl = nullptr;
81  }
82 
83  if (!property)
84  {
85  setTristate(true);
86  setCheckState(Qt::PartiallyChecked);
87  setEnabled(false);
88  return;
89  }
90 
91  setEnabled(true);
92  m_PropEditorImpl = new _BoolPropertyWidgetImpl(property, this);
93  m_PropEditorImpl->PropertyChanged();
94 }
95 
97 {
98  if (m_PropEditorImpl)
99  {
100  m_PropEditorImpl->ValueChanged(on);
101  }
102 }
QmitkBoolPropertyWidget(QWidget *parent=nullptr)
virtual void PropertyRemoved()=0
mitk::BaseProperty * m_Property
_BoolPropertyWidgetImpl * m_PropEditorImpl
PropertyEditor(mitk::BaseProperty *)
virtual void PropertyChanged()=0
void SetProperty(mitk::BoolProperty *property)