Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkAbstractNodeSelectionWidget.h
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 
14 #ifndef QMITK_ABSTRACT_NODE_SELECTION_WIDGET_H
15 #define QMITK_ABSTRACT_NODE_SELECTION_WIDGET_H
16 
17 #include <mitkDataStorage.h>
18 #include <mitkWeakPointer.h>
19 #include <mitkNodePredicateBase.h>
20 
21 #include <MitkQtWidgetsExports.h>
22 
23 #include <QWidget>
24 
26 class QAbstractItemVew;
27 
33 {
34  Q_OBJECT
35 
36 public:
37  explicit QmitkAbstractNodeSelectionWidget(QWidget* parent = nullptr);
38  virtual ~QmitkAbstractNodeSelectionWidget() override;
39 
45  void SetDataStorage(mitk::DataStorage* dataStorage);
46 
53  void SetNodePredicate(const mitk::NodePredicateBase* nodePredicate);
54 
55  const mitk::NodePredicateBase* GetNodePredicate() const;
56 
57  QString GetInvalidInfo() const;
58  QString GetEmptyInfo() const;
59  QString GetPopUpTitel() const;
60  QString GetPopUpHint() const;
61 
62  bool GetSelectionIsOptional() const;
63 
64  bool GetSelectOnlyVisibleNodes() const;
65 
66  using NodeList = QList<mitk::DataNode::Pointer>;
67 
69  NodeList GetSelectedNodes() const;
70 
71 Q_SIGNALS:
72  /*
73  * @brief A signal that will be emitted if the selected node has changed.
74  *
75  * @par nodes A list of data nodes that are newly selected.
76  */
77  void CurrentSelectionChanged(NodeList nodes);
78 
79 public Q_SLOTS:
80  /*
81  * @brief Change the selection modus of the item view's selection model.
82  *
83  * If true, an incoming selection will be filtered (reduced) to only those nodes that are visible by the current view.
84  * An outgoing selection can then at most contain the filtered nodes.
85  * If false, the incoming non-visible selection will be stored and later added to the outgoing selection,
86  * to include the original selection that could not be modified.
87  * The part of the original selection, that is non-visible are the nodes, that do not fullfill the predicate.
88  *
89  * @par selectOnlyVisibleNodes The bool value to define the selection modus.
90  */
91  void SetSelectOnlyVisibleNodes(bool selectOnlyVisibleNodes);
92 
93  /*
94  * @brief Transform a list of data nodes into a model selection and set this as a new selection of the
95  * selection model of the private member item view.
96  *
97  * The function filters the given list of nodes according to the 'm_SelectOnlyVisibleNodes' member variable. If
98  * necessary, the non-visible nodes are stored. This is done if 'm_SelectOnlyVisibleNodes' is false: In this case
99  * the selection may be filtered and only a subset of the selected nodes may be visible and therefore (de-)selectable
100  * in the data storage viewer. By storing the non-visible nodes it is possible to send the new, modified selection
101  * but also include the selected nodes from the original selection that could not be modified (see 'SetSelectOnlyVisibleNodes').
102  *
103  * @par nodes A list of data nodes that should be newly selected.
104  */
105  void SetCurrentSelection(NodeList selectedNodes);
106 
110  void SetInvalidInfo(QString info);
111 
115  void SetEmptyInfo(QString info);
116 
119  void SetPopUpTitel(QString info);
120 
123  void SetPopUpHint(QString info);
124 
127  void SetSelectionIsOptional(bool isOptional);
128 
129 protected Q_SLOTS:
133  void RemoveNodeFromSelection(const mitk::DataNode* node);
134 
135 protected:
137  virtual void UpdateInfo() = 0;
138 
142  virtual void OnNodePredicateChanged();
143 
146  virtual void OnDataStorageChanged();
147 
150  virtual void OnInternalSelectionChanged();
151 
154  virtual void OnNodeAddedToStorage(const mitk::DataNode* node);
155 
159  virtual void OnNodeRemovedFromStorage(const mitk::DataNode* node);
160 
167  void HandleChangeOfInternalSelection(NodeList newInternalSelection);
168 
172  NodeList CompileEmitSelection() const;
173 
179  virtual void ReviseSelectionChanged(const NodeList& oldInternalSelection, NodeList& newInternalSelection);
180 
185  virtual bool AllowEmissionOfSelection(const NodeList& emissionCandidates) const;
186 
189  void EmitSelection(const NodeList& emissionCandidates);
190 
191  void SetCurrentInternalSelection(NodeList selectedNodes);
192  const NodeList& GetCurrentInternalSelection() const;
193  const NodeList& GetCurrentExternalSelection() const;
194 
197 
198  QString m_InvalidInfo;
199  QString m_EmptyInfo;
200  QString m_PopUpTitel;
201  QString m_PopUpHint;
202 
207 
208 private:
210  void SetDataStorageDeleted();
211 
214  void NodeAddedToStorage(const mitk::DataNode* node);
215 
220  void NodeRemovedFromStorage(const mitk::DataNode* node);
221 
222  void OnNodeModified(const itk::Object * /*caller*/, const itk::EventObject &);
223 
224  void AddNodeObserver(mitk::DataNode* node);
225  void RemoveNodeObserver(mitk::DataNode* node);
226 
227  unsigned long m_DataStorageDeletedTag;
228 
229  NodeList m_CurrentInternalSelection;
230  NodeList m_CurrentExternalSelection;
231 
232  NodeList m_LastEmission;
233  bool m_LastEmissionAllowance;
234 
235  using NodeObserverTagMapType = std::map<const mitk::DataNode*, unsigned long>;
236  NodeObserverTagMapType m_NodeObserverTags;
237 
239  bool m_RecursionGuard;
240 };
241 #endif // QmitkAbstractNodeSelectionWidget_H
Data management class that handles &#39;was created by&#39; relations.
MITK_QT_APP QList< mitk::DataNode::Pointer > GetSelectedNodes(berry::IWorkbenchPartSite::Pointer workbenchPartSite)
QList< mitk::DataNode::Pointer > NodeList
#define MITKQTWIDGETS_EXPORT
static void info(const char *fmt,...)
Definition: svm.cpp:86
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
mitk::NodePredicateBase::ConstPointer m_NodePredicate
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Abstract base class for the selection of data from a data storage.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57