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