Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkPatientTableInspector.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 
13 // semantic relations UI module
16 
17 // mitk qt widgets module
18 #include "QmitkCustomVariants.h"
19 #include "QmitkEnums.h"
20 
21 // qt
22 #include <QKeyEvent>
23 #include <QSignalMapper>
24 
27 {
28  m_Controls.setupUi(this);
29 
30  QmitkPatientTableHeaderView* patientTableHeaderView = new QmitkPatientTableHeaderView(m_Controls.tableView);
31  m_Controls.tableView->setHorizontalHeader(patientTableHeaderView);
32  m_Controls.tableView->horizontalHeader()->setHighlightSections(false);
33  m_Controls.tableView->horizontalHeader()->setSectionResizeMode(QHeaderView::Fixed);
34  m_Controls.tableView->verticalHeader()->setHighlightSections(false);
35  m_Controls.tableView->verticalHeader()->setSectionResizeMode(QHeaderView::Fixed);
36  m_Controls.tableView->setSelectionMode(QAbstractItemView::SingleSelection);
37  m_Controls.tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
38  m_Controls.tableView->setContextMenuPolicy(Qt::CustomContextMenu);
39 
40  m_StorageModel = new QmitkPatientTableModel(m_Controls.tableView);
41  m_Controls.tableView->setModel(m_StorageModel);
42  m_ItemDelegate = new QmitkTableItemThumbnailDelegate(m_Controls.tableView);
43  //m_Controls.tableView->setItemDelegate(m_ItemDelegate);
44 
45  SetUpConnections();
46 }
47 
49 {
50  return m_Controls.tableView;
51 }
52 
53 const QAbstractItemView* QmitkPatientTableInspector::GetView() const
54 {
55  return m_Controls.tableView;
56 }
57 
59 {
60  m_Controls.tableView->setSelectionMode(mode);
61 }
62 
64 {
65  return m_Controls.tableView->selectionMode();
66 }
67 
69 {
70  m_StorageModel->SetCaseID(caseID);
71 }
72 
74 {
75  m_StorageModel->SetLesion(lesion);
76 }
77 
79 {
80  return m_Controls.tableView->selectionModel();
81 }
82 
84 {
86  {
87  return;
88  }
89 
90  auto dataStorage = m_DataStorage.Lock();
91 
92  m_StorageModel->SetDataStorage(dataStorage);
93  m_StorageModel->SetNodePredicate(m_NodePredicate);
94 
95  m_Connector->SetView(m_Controls.tableView);
96 }
97 
98 void QmitkPatientTableInspector::OnModelUpdated()
99 {
100  m_Controls.tableView->resizeRowsToContents();
101  m_Controls.tableView->resizeColumnsToContents();
102 }
103 
104 void QmitkPatientTableInspector::OnNodeButtonClicked(const QString& nodeType)
105 {
106  m_StorageModel->SetNodeType(nodeType.toStdString());
107 }
108 
109 void QmitkPatientTableInspector::OnDataNodeSelectionChanged(const QList<mitk::DataNode::Pointer>& dataNodeSelection)
110 {
111  if (m_StorageModel->GetLesion().UID.empty())
112  {
113  return;
114  }
115 
116  // if lesion is set, reset to empty lesion to hide the "lesion presence background highlighting" in the model
117  m_StorageModel->SetLesion(mitk::SemanticTypes::Lesion());
118  // need to explicitly set the data node selection
119  SetCurrentSelection(dataNodeSelection);
120 }
121 
122 void QmitkPatientTableInspector::OnItemDoubleClicked(const QModelIndex& itemIndex)
123 {
124  if (itemIndex.isValid())
125  {
126  QVariant qvariantDataNode = m_StorageModel->data(itemIndex, QmitkDataNodeRawPointerRole);
127  if (qvariantDataNode.canConvert<mitk::DataNode*>())
128  {
129  mitk::DataNode* dataNode = qvariantDataNode.value<mitk::DataNode*>();
130  emit DataNodeDoubleClicked(dataNode);
131  }
132  }
133 }
134 
135 void QmitkPatientTableInspector::SetUpConnections()
136 {
137  connect(m_StorageModel, &QmitkPatientTableModel::ModelUpdated, this, &QmitkPatientTableInspector::OnModelUpdated);
138  connect(m_Controls.tableView, &QTableView::customContextMenuRequested, this, &QmitkPatientTableInspector::OnContextMenuRequested);
139 
140  QSignalMapper* nodeButtonSignalMapper = new QSignalMapper(this);
141  nodeButtonSignalMapper->setMapping(m_Controls.imageNodeButton, QString("Image"));
142  nodeButtonSignalMapper->setMapping(m_Controls.segmentationNodeButton, QString("Segmentation"));
143  connect(nodeButtonSignalMapper, static_cast<void (QSignalMapper::*)(const QString&)>(&QSignalMapper::mapped), this, &QmitkPatientTableInspector::OnNodeButtonClicked);
144  connect(m_Controls.imageNodeButton, &QRadioButton::clicked, nodeButtonSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
145  connect(m_Controls.segmentationNodeButton, &QRadioButton::clicked, nodeButtonSignalMapper, static_cast<void(QSignalMapper::*)()>(&QSignalMapper::map));
146  m_Controls.imageNodeButton->setChecked(true);
147 
148  connect(this, &QmitkPatientTableInspector::CurrentSelectionChanged, this, &QmitkPatientTableInspector::OnDataNodeSelectionChanged);
149  connect(m_Controls.tableView, &QTableView::doubleClicked, this, &QmitkPatientTableInspector::OnItemDoubleClicked);
150 }
151 
152 void QmitkPatientTableInspector::keyPressEvent(QKeyEvent* e)
153 {
154  mitk::DataNode* dataNode = nullptr;
155  QModelIndex selectedIndex = m_Controls.tableView->currentIndex();
156  if (selectedIndex.isValid())
157  {
158  QVariant qvariantDataNode = m_StorageModel->data(selectedIndex, QmitkDataNodeRawPointerRole);
159  if (qvariantDataNode.canConvert<mitk::DataNode*>())
160  {
161  dataNode = qvariantDataNode.value<mitk::DataNode*>();
162  }
163  }
164 
165  if (nullptr == dataNode)
166  {
167  return;
168  }
169 
170  int key = e->key();
171  switch (key)
172  {
173  case Qt::Key_Delete:
174  emit OnNodeRemoved(dataNode);
175  break;
176  default:
177  break;
178  }
179 }
QAbstractItemView * GetView() override
itk::SmartPointer< T > Lock() const
void SetSelectionMode(SelectionMode mode) override
void SetDataStorage(mitk::DataStorage *dataStorage)
void SetCaseID(const mitk::SemanticTypes::CaseID &caseID)
Set the current case ID which is needed to access the semantic relations storage. ...
mitk::NodePredicateBase::ConstPointer m_NodePredicate
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
void SetNodeType(const std::string &nodeType)
end override
QItemSelectionModel * GetSelectionModel()
void CurrentSelectionChanged(NodeList nodes)
A signal that will be emitted if the selected node has changed.
void SetCurrentSelection(NodeList selectedNodes)
Transform a list of data nodes into a model selection and set this as a new selection of the selectio...
bool IsExpired() const noexcept
QmitkPatientTableInspector(QWidget *parent=nullptr)
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
void OnNodeRemoved(const mitk::DataNode *)
void SetCaseID(const mitk::SemanticTypes::CaseID &caseID) override
Extends the abstract base class to allow setting the current case ID which is needed to access the se...
void SetLesion(const mitk::SemanticTypes::Lesion &lesion) override
Extends the abstract base class to allow setting the current lesion. The function sets the lesion in ...
MITKMATCHPOINTREGISTRATION_EXPORT ResultImageType::Pointer map(const InputImageType *input, const RegistrationType *registration, bool throwOnOutOfInputAreaError=false, const double &paddingValue=0, const ResultImageGeometryType *resultGeometry=nullptr, bool throwOnMappingError=true, const double &errorValue=0, mitk::ImageMappingInterpolator::Type interpolatorType=mitk::ImageMappingInterpolator::Linear)
void SetLesion(const mitk::SemanticTypes::Lesion &lesion)
Set the current lesion which can be used to show on which images the lesion is visible.
void OnContextMenuRequested(const QPoint &)
void DataNodeDoubleClicked(const mitk::DataNode *)
QAbstractItemView::SelectionMode SelectionMode
SelectionMode GetSelectionMode() const override
std::unique_ptr< QmitkModelViewSelectionConnector > m_Connector
void SetNodePredicate(const mitk::NodePredicateBase *nodePredicate)
The QmitkPatientTableModel is a subclass of the QmitkAbstractSemanticRelationsStorageModel and holds ...
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57