Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkMultiNodeSelectionWidget.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 
15 
16 #include <algorithm>
17 
19 #include "QmitkCustomVariants.h"
20 #include "internal/QmitkNodeSelectionListItemWidget.h"
21 
23 {
24  m_Controls.setupUi(this);
26  m_Overlay->setVisible(false);
27  m_CheckFunction = [](const NodeList &) { return ""; };
28 
30  this->UpdateInfo();
31 
32  connect(m_Controls.btnChange, SIGNAL(clicked(bool)), this, SLOT(OnEditSelection()));
33 }
34 
36 {
37  m_CheckFunction = checkFunction;
38 
39  auto newEmission = this->CompileEmitSelection();
40  auto newCheckResponse = m_CheckFunction(newEmission);
41 
42  if (newCheckResponse.empty() && !m_CheckResponse.empty())
43  {
44  this->EmitSelection(newEmission);
45  }
46  m_CheckResponse = newCheckResponse;
47  this->UpdateInfo();
48 }
49 
51 {
53 
58  dialog->SetSelectionMode(QAbstractItemView::MultiSelection);
59 
60  m_Controls.btnChange->setChecked(true);
61  if (dialog->exec())
62  {
64  }
65  m_Controls.btnChange->setChecked(false);
66 
67  delete dialog;
68 }
69 
71 {
72  if (!m_Controls.list->count())
73  {
74  if (m_IsOptional)
75  {
76  if (this->isEnabled())
77  {
78  m_Overlay->SetOverlayText(QStringLiteral("<font class=\"normal\">") + m_EmptyInfo + QStringLiteral("</font>"));
79  }
80  else
81  {
82  m_Overlay->SetOverlayText(QStringLiteral("<font class=\"disabled\">") + m_EmptyInfo + QStringLiteral("</font>"));
83  }
84  }
85  else
86  {
87  if (this->isEnabled())
88  {
89  m_Overlay->SetOverlayText(QStringLiteral("<font class=\"warning\">") + m_InvalidInfo + QStringLiteral("</font>"));
90  }
91  else
92  {
93  m_Overlay->SetOverlayText(QStringLiteral("<font class=\"disabled\">") + m_InvalidInfo + QStringLiteral("</font>"));
94  }
95  }
96  }
97  else
98  {
99  if (!m_CheckResponse.empty())
100  {
101  m_Overlay->SetOverlayText(QString::fromStdString(m_CheckResponse));
102  }
103  }
104 
105  m_Overlay->setVisible(m_Controls.list->count() == 0 || !m_CheckResponse.empty());
106 
107  for (auto i = 0; i < m_Controls.list->count(); ++i)
108  {
109  auto item = m_Controls.list->item(i);
110  auto widget = qobject_cast<QmitkNodeSelectionListItemWidget*>(m_Controls.list->itemWidget(item));
111  widget->SetClearAllowed(m_IsOptional || m_Controls.list->count() > 1);
112  }
113 }
114 
116 {
117  m_Controls.list->clear();
118  auto currentSelection = this->GetCurrentInternalSelection();
119  for (auto& node : currentSelection)
120  {
121  if (m_NodePredicate.IsNull() || m_NodePredicate->CheckNode(node))
122  {
123  QListWidgetItem *newItem = new QListWidgetItem;
124 
125  newItem->setSizeHint(QSize(0, 40));
126  QmitkNodeSelectionListItemWidget* widget = new QmitkNodeSelectionListItemWidget;
127 
128  widget->SetSelectedNode(node);
129  widget->SetClearAllowed(m_IsOptional || currentSelection.size() > 1);
130 
131  connect(widget, &QmitkNodeSelectionListItemWidget::ClearSelection, this, &QmitkMultiNodeSelectionWidget::OnClearSelection);
132  newItem->setData(Qt::UserRole, QVariant::fromValue<mitk::DataNode::Pointer>(node));
133 
134  m_Controls.list->addItem(newItem);
135  m_Controls.list->setItemWidget(newItem, widget);
136  }
137  }
138 }
139 
141 {
142  this->RemoveNodeFromSelection(node);
143 }
144 
146 {
147  if (event->type() == QEvent::EnabledChange)
148  {
149  this->UpdateInfo();
150  }
151  QmitkAbstractNodeSelectionWidget::changeEvent(event);
152 }
153 
155 {
156  m_CheckResponse = m_CheckFunction(emissionCandidates);
157  return m_CheckResponse.empty();
158 }
itk::SmartPointer< T > Lock() const
void RemoveNodeFromSelection(const mitk::DataNode *node)
Ui_QmitkMultiNodeSelectionWidget m_Controls
QmitkMultiNodeSelectionWidget(QWidget *parent=nullptr)
bool AllowEmissionOfSelection(const NodeList &emissionCandidates) const override
QList< mitk::DataNode::Pointer > NodeList
void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes)
SelectionCheckFunctionType m_CheckFunction
std::function< std::string(const NodeList &)> SelectionCheckFunctionType
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
void SetSelectionMode(SelectionMode mode)
void OnClearSelection(const mitk::DataNode *node)
Widget that allows to show and edit the content of an mitk::IsoDoseLevel instance.
void SetDataStorage(mitk::DataStorage *dataStorage)
Sets the data storage that will be used /monitored by widget.
void SetSelectionCheckFunction(const SelectionCheckFunctionType &checkFunction)
mitk::NodePredicateBase::ConstPointer m_NodePredicate
QmitkSimpleTextOverlayWidget * m_Overlay
virtual void SetNodePredicate(const mitk::NodePredicateBase *nodePredicate)
Sets the node predicate and updates the widget, according to the node predicate.
void SetCurrentSelection(NodeList selectedNodes)
Abstract base class for the selection of data from a data storage.
void EmitSelection(const NodeList &emissionCandidates)
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
void HandleChangeOfInternalSelection(NodeList newInternalSelection)