Medical Imaging Interaction Toolkit  2016.11.0
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,
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 
19 
20 #include <mitkRenderingManager.h>
21 
22 #include <QLayout>
23 #include <QLineEdit>
24 #include <QValidator>
25 #include <itkCommand.h>
26 #include <limits>
27 #include <sstream>
28 
29 using namespace std;
30 
34 QmitkLineEditLevelWindowWidget::QmitkLineEditLevelWindowWidget(QWidget *parent, Qt::WindowFlags f) : QWidget(parent, f)
35 {
37 
40  command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified);
41  m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
42  m_IsObserverTagSet = true;
43 
45 
46  auto layout = new QVBoxLayout(this);
47  layout->setMargin(0);
48  layout->setSpacing(0);
49 
50  m_LevelInput = new QLineEdit(this);
51  m_LevelInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
52  m_LevelInput->setToolTip("Edit this field to change the center of the levelwindow.");
53  // m_LevelInput->setFrameShape( QLineEdit::LineEditPanel );
54  // m_LevelInput->setFrameShadow( QLineEdit::Sunken );
55 
56  m_WindowInput = new QLineEdit(this);
57  m_WindowInput->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred));
58  m_WindowInput->setToolTip(
59  "Edit this field to change the span of the levelwindow. This number describes the whole span around the center.");
60  // m_WindowInput->setFrameShape( QLineEdit::LineEditPanel );
61  // m_WindowInput->setFrameShadow( QLineEdit::Sunken );
62 
63  layout->addWidget(m_LevelInput);
64  layout->addWidget(m_WindowInput);
65 
66  // signals and slots connections
67  connect(m_LevelInput, SIGNAL(editingFinished()), this, SLOT(SetLevelValue()));
68  connect(m_WindowInput, SIGNAL(editingFinished()), this, SLOT(SetWindowValue()));
69 
70  // Validator for both LineEdit-widgets, to limit the valid input-range to int.
71  // QValidator* validatorWindowInput = new QIntValidator(1, 20000000, this);
72  QValidator *validatorWindowInput = new QDoubleValidator(0, numeric_limits<double>::max(), 2, this);
73  m_WindowInput->setValidator(validatorWindowInput);
74 
75  // QValidator* validatorLevelInput = new QIntValidator(-10000000, 10000000, this);
76  // QValidator* validatorLevelInput = new QDoubleValidator(numeric_limits<double>::min(),
77  // numeric_limits<double>::max(), 2, this);
78  // m_LevelInput->setValidator(validatorLevelInput);
79 
80  this->hide();
81 }
82 
84 {
86  {
87  m_Manager->RemoveObserver(m_ObserverTag);
88  m_IsObserverTagSet = false;
89  }
90 }
91 
92 void QmitkLineEditLevelWindowWidget::OnPropertyModified(const itk::EventObject &)
93 {
94  try
95  {
96  m_LevelWindow = m_Manager->GetLevelWindow();
97  // setValidator();
98  QString level;
99  QString window;
101  {
102  std::stringstream ssLevel;
103  std::stringstream ssWindow;
104  ssLevel << std::setprecision(3) << m_LevelWindow.GetLevel();
105  ssWindow << std::setprecision(3) << m_LevelWindow.GetWindow();
106  level = ssLevel.str().c_str();
107  window = ssWindow.str().c_str();
108  }
109  else
110  {
111  level.setNum((int)(m_LevelWindow.GetLevel()));
112  window.setNum((int)(m_LevelWindow.GetWindow()));
113  }
114  m_LevelInput->setText(level);
115  m_WindowInput->setText(window);
116  m_LevelInput->setEnabled(!m_LevelWindow.IsFixed());
117  m_WindowInput->setEnabled(!m_LevelWindow.IsFixed());
118  this->show();
119  }
120  catch (...)
121  {
122  try
123  {
124  this->hide();
125  }
126  catch (...)
127  {
128  }
129  }
130 }
131 
133 {
134  if (m_IsObserverTagSet)
135  {
136  m_Manager->RemoveObserver(m_ObserverTag);
137  m_IsObserverTagSet = false;
138  }
139  m_Manager = levelWindowManager;
140  if (m_Manager.IsNotNull())
141  {
144  command->SetCallbackFunction(this, &QmitkLineEditLevelWindowWidget::OnPropertyModified);
145  m_ObserverTag = m_Manager->AddObserver(itk::ModifiedEvent(), command);
146  m_IsObserverTagSet = true;
147  }
148 }
149 
151 {
152  m_Manager->SetDataStorage(ds);
153 }
154 
155 // read the levelInput and change level and slider when the button "ENTER" was pressed in the windowInput-LineEdit
157 {
158  double level = m_LevelInput->text().toDouble();
160  m_Manager->SetLevelWindow(m_LevelWindow);
162 }
163 
164 // read the windowInput and change window and slider when the button "ENTER" was pressed in the windowInput-LineEdit
166 {
167  double window = m_WindowInput->text().toDouble();
169  m_Manager->SetLevelWindow(m_LevelWindow);
171 }
172 
173 void QmitkLineEditLevelWindowWidget::contextMenuEvent(QContextMenuEvent *)
174 {
177 }
178 
180 {
181  return m_Manager.GetPointer();
182 }
QLineEdit * m_LevelInput
inputfield for level value
Data management class that handles 'was created by' relations.
itk::SmartPointer< Self > Pointer
void setLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
lets this object know about the LevelWindowManager to get all images and tell about changes ...
bool IsFloatingValues() const
Shows if floating values are accepted.
STL namespace.
void SetDataStorage(mitk::DataStorage *ds)
sets the DataStorage which holds all image-nodes
void setLevelWindowManager(mitk::LevelWindowManager *levelWindowManager)
sets the manager who is responsible to collect and deliver changes on Level/Window ...
mitk::LevelWindowManager * GetManager()
returns the manager who is responsible to collect and deliver changes on Level/Window ...
Provides a contextmenu for Level/Window functionality.
bool IsFixed() const
void SetWindowValue()
called when return is pressed in windowinput field
static RenderingManager * GetInstance()
static T max(T x, T y)
Definition: svm.cpp:70
mitk::LevelWindowManager::Pointer m_Manager
manager who is responsible to collect and deliver changes on Level/Window
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()
called when return is pressed in levelinput field
ScalarType GetWindow() const
returns the current window size, i.e the range size of the current grey value interval ...
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
ScalarType GetLevel() const
method that returns the level value, i.e. the center of the current grey value interval ...
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.