Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
QmitkPointListViewWidget.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 "QmitkEditPointDialog.h"
20 #include "QmitkPointListModel.h"
21 #include "QmitkStdMultiWidget.h"
22 
23 #include "mitkInteractionConst.h"
24 #include "mitkPointOperation.h"
25 #include "mitkRenderingManager.h"
26 
27 #include <QKeyEvent>
28 
30  : QListWidget(parent), m_TimeStep(0), m_SelfCall(false), m_MultiWidget(NULL)
31 {
32  QListWidget::setAlternatingRowColors(true);
33  // logic
34 
35  QListWidget::setSelectionBehavior(QAbstractItemView::SelectRows);
36  QListWidget::setSelectionMode(QAbstractItemView::SingleSelection);
37 
38  connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(OnItemDoubleClicked(QListWidgetItem *)));
39 
40  connect(this, SIGNAL(currentRowChanged(int)), this, SLOT(OnCurrentRowChanged(int)));
41 }
42 
44 {
45  this->SetPointSet(0); // remove listener
46 }
47 
49 {
50  if (m_PointSet.IsNotNull())
51  {
56  }
57 
58  m_PointSet = pointSet;
59 
60  if (m_PointSet.IsNotNull())
61  {
66  }
67 
68  this->Update();
69 }
70 
72 {
73  return m_PointSet;
74 }
75 
77 {
78  m_TimeStep = t;
79  this->Update();
80 }
81 
83 {
84  return m_TimeStep;
85 }
86 
88 {
89  m_MultiWidget = multiWidget;
90 }
91 
93 {
94  return m_MultiWidget;
95 }
96 
98 {
99  if (!m_SelfCall)
100  this->Update();
101 }
102 
104 {
105  this->SetPointSet(0);
106  this->Update();
107 }
108 
110 {
111  QmitkEditPointDialog _EditPointDialog(this);
112  _EditPointDialog.SetPoint(m_PointSet, this->row(item), m_TimeStep);
113  _EditPointDialog.exec();
114 }
115 
117 {
118  this->Update(true);
119 }
120 
122 {
123  if (m_PointSet.IsNull())
124  return;
125 
126  int key = e->key();
127  switch (key)
128  {
129  case Qt::Key_F2:
130  this->MoveSelectedPointUp();
131  break;
132  case Qt::Key_F3:
133  this->MoveSelectedPointDown();
134  break;
135  case Qt::Key_Delete:
136  this->RemoveSelectedPoint();
137  break;
138  default:
139  break;
140  }
141 }
142 
144 {
145  if (m_PointSet.IsNull())
146  return;
147 
150  mitk::PointOperation *doOp =
151  new mitk::PointOperation(mitk::OpMOVEPOINTUP, m_PointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
153  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
154 }
155 
157 {
158  if (m_PointSet.IsNull())
159  return;
160 
163  mitk::PointOperation *doOp =
164  new mitk::PointOperation(mitk::OpMOVEPOINTDOWN, m_PointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
166  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
167 }
168 
170 {
171  if (m_PointSet.IsNull())
172  return;
173 
176  mitk::PointOperation *doOp =
177  new mitk::PointOperation(mitk::OpREMOVE, m_PointSet->GetPoint(selectedID, m_TimeStep), selectedID, true);
179  mitk::RenderingManager::GetInstance()->RequestUpdateAll(); // Workaround for update problem in Pointset/Mapper
180 }
181 
182 void QmitkPointListViewWidget::Update(bool currentRowChanged)
183 {
184  if (m_SelfCall)
185  return;
186 
187  if (m_PointSet.IsNull())
188  {
189  this->clear();
190  return;
191  }
192 
193  m_SelfCall = true;
194  QString text;
195  int i = 0;
196 
198  for (mitk::PointSet::PointsContainer::Iterator it = pointset->GetPoints()->Begin();
199  it != pointset->GetPoints()->End();
200  ++it)
201  {
202  text = QString("%0: (%1, %2, %3)")
203  .arg(i, 3)
204  .arg(it.Value().GetElement(0), 0, 'f', 3)
205  .arg(it.Value().GetElement(1), 0, 'f', 3)
206  .arg(it.Value().GetElement(2), 0, 'f', 3);
207 
208  if (i == this->count())
209  this->addItem(text); // insert text
210  else
211  this->item(i)->setText(text); // update text
212 
213  if (currentRowChanged)
214  {
215  if (i == this->currentRow())
216  m_PointSet->SetSelectInfo(this->currentRow(), true, m_TimeStep);
217  else
218  m_PointSet->SetSelectInfo(it->Index(), false, m_TimeStep); // select nothing now
219  }
220  ++i;
221  }
222 
223  // remove unnecessary listwidgetitems
224  while (m_PointSet->GetPointSet(m_TimeStep)->GetPoints()->Size() < (unsigned int)this->count())
225  {
226  QListWidgetItem *item = this->takeItem(this->count() - 1);
227  delete item;
228  }
229 
230  // update selection in pointset or in the list widget
231  if (!currentRowChanged)
232  {
234  {
236  std::cerr << "Point set has multiple selected points. This view is not designed for more than one selected point."
237  << std::endl;
238  }
239 
240  int selectedIndex = m_PointSet->SearchSelectedPoint(m_TimeStep);
241  if (selectedIndex != -1) // no selected point is found
242  {
243  this->setCurrentRow(selectedIndex);
244  }
245  }
246  m_SelfCall = false;
247 }
void RemoveListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:397
void AddListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:378
A dialog for editing points directly (coordinates) via TextEdits.
itk::SmartPointer< Self > Pointer
void OnItemDoubleClicked(QListWidgetItem *item)
virtual void ExecuteOperation(Operation *operation) override
executes the given Operation
itkObjectEvent ObjectDelete
AddEvent is emitted when the object pointed to gets deleted.
bool IsNotNull() const
PointType GetPoint(PointIdentifier id, int t=0) const
Get the point with ID id in world coordinates.
void SetMultiWidget(QmitkStdMultiWidget *multiWidget)
assign a QmitkStdMultiWidget for updating render window crosshair
Constants for most interaction classes, due to the generic StateMachines.
mitk::WeakPointer< mitk::PointSet > m_PointSet
virtual void SetSelectInfo(int position, bool selected, int t=0)
DataType::PointIdentifier PointIdentifier
Definition: mitkPointSet.h:135
Data structure which stores a set of points. Superclass of mitk::Mesh.
Definition: mitkPointSet.h:79
virtual DataType::Pointer GetPointSet(int t=0) const
returns the pointset
void Update(bool currentRowChanged=false)
static RenderingManager * GetInstance()
const mitk::PointSet * GetPointSet() const
which point set to work on
virtual int SearchSelectedPoint(int t=0) const
searches a selected point and returns the id of that point. If no point is found, then -1 is returned...
Operation that handles all actions on one Point.
void SetTimeStep(int t)
which time step to display/model
bool IsNull() const
void SetPointSet(mitk::PointSet *pointSet)
assign a point set for observation
void OnCurrentRowChanged(int)
called when the selection of the view widget changes
void keyPressEvent(QKeyEvent *e) override
react to F2, F3 and DEL keys
virtual int GetNumberOfSelected(int t=0) const
returns the number of selected points
void OnPointSetChanged(const itk::Object *)
observer for point set "modified" events
itkObjectEvent ObjectModified
AddEvent is emitted when the object pointed to gets modified.
void OnPointSetDeleted(const itk::Object *)
observer for point set "delete" events
int GetTimeStep() const
which time step to display/model
QmitkPointListViewWidget(QWidget *parent=0)
void RequestUpdateAll(RequestType type=REQUEST_UPDATE_ALL)
QmitkStdMultiWidget * GetMultiWidget() const
return the QmitkStdMultiWidget that is used for updating render window crosshair
QmitkStdMultiWidget * m_MultiWidget
used to position the planes on a selected point
void SetPoint(mitk::PointSet *_PointSet, mitk::PointSet::PointIdentifier _PointId, int timestep=0)