Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkLineEditLevelWindowWidget.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 // mitk core
16 #include <mitkRenderingManager.h>
17 
18 // mitk qt widgets
20 
21 // qt
22 #include <QLayout>
23 #include <QLineEdit>
24 #include <QValidator>
25 
26 // itk
27 #include <itkCommand.h>
28 
29 // c++
30 #include <limits>
31 #include <sstream>
32 
33 QmitkLineEditLevelWindowWidget::QmitkLineEditLevelWindowWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
34 {
36 
37  itk::ReceptorMemberCommand<QmitkLineEditLevelWindowWidget>::Pointer command =
38  itk::ReceptorMemberCommand<QmitkLineEditLevelWindowWidget>::New();
39  command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified);
40  m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
41  m_IsObserverTagSet = true;
42 
44 
45  auto layout = new QVBoxLayout(this);
46  layout->setMargin(0);
47  layout->setSpacing(0);
48 
49  m_LevelInput = new QLineEdit(this);
50  m_LevelInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
51  m_LevelInput->setToolTip("Edit this field to change the center of the levelwindow.");
52 
53  m_WindowInput = new QLineEdit(this);
54  m_WindowInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
55  m_WindowInput->setToolTip(
56  "Edit this field to change the span of the levelwindow. This number describes the whole span around the center.");
57 
58  layout->addWidget(m_LevelInput);
59  layout->addWidget(m_WindowInput);
60 
61  // signals and slots connections
62  connect(m_LevelInput, SIGNAL(editingFinished()), this, SLOT(SetLevelValue()));
63  connect(m_WindowInput, SIGNAL(editingFinished()), this, SLOT(SetWindowValue()));
64 
65  // Validator for both LineEdit-widgets, to limit the valid input-range to int.
66  QValidator *validatorWindowInput = new QDoubleValidator(0, std::numeric_limits<double>::max(), 2, this);
67  m_WindowInput->setValidator(validatorWindowInput);
68 
69  this->hide();
70 }
71 
73 {
75  {
76  m_Manager->RemoveObserver(m_ObserverTag);
77  m_IsObserverTagSet = false;
78  }
79 }
80 
81 void QmitkLineEditLevelWindowWidget::OnPropertyModified(const itk::EventObject &)
82 {
83  try
84  {
85  m_LevelWindow = m_Manager->GetLevelWindow();
86  QString level;
87  QString window;
89  {
90  std::stringstream ssLevel;
91  std::stringstream ssWindow;
92  ssLevel << std::setprecision(3) << m_LevelWindow.GetLevel();
93  ssWindow << std::setprecision(3) << m_LevelWindow.GetWindow();
94  level = ssLevel.str().c_str();
95  window = ssWindow.str().c_str();
96  }
97  else
98  {
99  level.setNum((int)(m_LevelWindow.GetLevel()));
100  window.setNum((int)(m_LevelWindow.GetWindow()));
101  }
102  m_LevelInput->setText(level);
103  m_WindowInput->setText(window);
104  m_LevelInput->setEnabled(!m_LevelWindow.IsFixed());
105  m_WindowInput->setEnabled(!m_LevelWindow.IsFixed());
106  this->show();
107  }
108  catch (...)
109  {
110  try
111  {
112  this->hide();
113  }
114  catch (...)
115  {
116  }
117  }
118 }
119 
121 {
122  if (m_IsObserverTagSet)
123  {
124  m_Manager->RemoveObserver(m_ObserverTag);
125  m_IsObserverTagSet = false;
126  }
127  m_Manager = levelWindowManager;
128  if (m_Manager.IsNotNull())
129  {
130  itk::ReceptorMemberCommand<QmitkLineEditLevelWindowWidget>::Pointer command =
131  itk::ReceptorMemberCommand<QmitkLineEditLevelWindowWidget>::New();
132  command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified);
133  m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
134  m_IsObserverTagSet = true;
135  }
136 }
137 
139 {
140  m_Manager->SetDataStorage(ds);
141 }
142 
144 {
145  double level = m_LevelInput->text().toDouble();
147  m_Manager->SetLevelWindow(m_LevelWindow);
149 }
150 
152 {
153  double window = m_WindowInput->text().toDouble();
155  m_Manager->SetLevelWindow(m_LevelWindow);
157 }
158 
159 void QmitkLineEditLevelWindowWidget::contextMenuEvent(QContextMenuEvent *)
160 {
163 }
164 
166 {
167  return m_Manager.GetPointer();
168 }
QLineEdit * m_LevelInput
inputfield for level value
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
Data management class that handles &#39;was created by&#39; relations.
void SetLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
lets this object know about the LevelWindowManager to get all images and tell about changes ...
void SetLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
sets the manager who is responsible to collect and deliver changes on Level/Window ...
void SetDataStorage(mitk::DataStorage *ds)
sets the DataStorage which holds all image-nodes
mitk::LevelWindowManager * GetManager()
returns the manager who is responsible to collect and deliver changes on Level/Window ...
Provides a contextmenu for Level/Window functionality.
void SetWindowValue()
Read the windowInput and change window and slider when the button "ENTER" was pressed in the windowIn...
static RenderingManager * GetInstance()
static T max(T x, T y)
Definition: svm.cpp:56
mitk::LevelWindowManager::Pointer m_Manager
manager who is responsible to collect and deliver changes on Level/Window
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
QmitkLineEditLevelWindowWidget(QWidget *parent=nullptr, Qt::WindowFlags f=nullptr)
constructor
void SetLevelWindow(ScalarType level, ScalarType window, bool expandRangesIfNecessary=true)
QmitkLevelWindowWidgetContextMenu * m_Contextmenu
static Pointer New()
Provides access to the LevelWindowProperty object and LevelWindow of the "current" image...
QLineEdit * m_WindowInput
inputfield for window value
void SetLevelValue()
Read the levelInput and change level and slider when the button "ENTER" was pressed in the windowInpu...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
bool IsFloatingValues() const
Shows if floating values are accepted.