Medical Imaging Interaction Toolkit  2025.08.99-f7084adb
Medical Imaging Interaction Toolkit
QmitkSynchronizedWidgetConnector.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 #ifndef QmitkSynchronizedWidgetConnector_h
14 #define QmitkSynchronizedWidgetConnector_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 // mitk core
19 #include <mitkDataNode.h>
20 
21 // mitk qt widgets
23 
24 // qt
25 #include <QList>
26 
27 /*
28 * @brief This class connects different 'QmitkSynchronizedNodeSelectionWidget', such that
29 * they can synchronize their current node selection and their current selection mode.
30 *
31 * In order to synchronize a new node selection widget with other already connected
32 * node selection widgets, 'ConnectWidget(const QmitkSynchronizedNodeSelectionWidget*)' has to be used.
33 * In order to desynchronize a node selection widget,
34 * 'DisconnectWidget(const QmitkSynchronizedNodeSelectionWidget*)' has to be used.
35 * If a new node selection has been connected / synchronized,
36 * 'SynchronizeWidget(QmitkSynchronizedNodeSelectionWidget*' can be used to initially set
37 * the current selection and the current selection mode.
38 * For this, both values are stored in this class internally.
39 */
41 {
42  Q_OBJECT
43 
44 public:
45 
47 
49 
50  /*
51  * @brief This function connects the different signals and slots of this instance and the given
52  * given node selection widget, such that changes to the current list of nodes
53  * and the selection mode can be forwarded or received.
54  * The connections are as follows:
55  * - QmitkAbstractNodeSelectionWidget::CurrentSelectionChanged
56  * -> QmitkSynchronizedWidgetConnector::ChangeSelection
57  * - QmitkSynchronizedWidgetConnector::NodeSelectionChanged
58  * -> QmitkAbstractNodeSelectionWidget::SetCurrentSelection
59  * - QmitkSynchronizedNodeSelectionWidget::SelectionModeChanged
60  * -> QmitkSynchronizedWidgetConnector::ChangeSelectionMode
61  * - QmitkSynchronizedWidgetConnector::SelectionModeChanged
62  * -> QmitkSynchronizedNodeSelectionWidget::SetSelectAll
63  *
64  * @param nodeSelectionWidget The synchronized node selection widget to be connected / synchronized.
65  */
66  void ConnectWidget(const QmitkSynchronizedNodeSelectionWidget* nodeSelectionWidget);
67  /*
68  * @brief This function disconnects the different signals and slot of this instance and the given
69  * given node selection widget, such that changes to the current list of nodes
70  * and the selection mode cannot be forwarded or received anymore.
71  *
72  * @param nodeSelectionWidget The synchronized node selection widget to be disconnected / desynchronized.
73  */
74  void DisconnectWidget(const QmitkSynchronizedNodeSelectionWidget* nodeSelectionWidget);
75  /*
76  * @brief This function sets the current selection and the selection mode of the given node selection widget
77  * to the values of this instance. The required values are stored in this class internally.
78  * It can be used to newly initialize the given node selection widget.
79  *
80  * @param nodeSelectionWidget The synchronized node selection widget for which the
81  * current selection and the selection mode should be set.
82  */
83  void SynchronizeWidget(QmitkSynchronizedNodeSelectionWidget* nodeSelectionWidget) const;
84  /*
85  * @brief Get the current internal node selection.
86  *
87  * @return NodeList The current internal node selection stored as a member variable.
88  */
89  NodeList GetNodeSelection() const;
90  /*
91  * @brief Get the current internal selection mode.
92  *
93  * @return The current internal selection mode stored as a member variable.
94  */
95  bool GetSelectionMode() const;
96 
97 Q_SIGNALS:
98  /*
99  * @brief A signal that will be emitted by the 'ChangeSelection'-slot.
100  * This happens if a new selection / list of nodes is set from outside of this class,
101  * e.g. from a QmitkSynchronizedNodeSelectionWidget.
102  * This signal is connected to the 'SetCurrentSelection'-slot of each
103  * QmitkSynchronizedNodeSelectionWidget to propagate the new selection.
104  *
105  * @param nodes A list of data nodes that are newly selected.
106  */
107  void NodeSelectionChanged(NodeList nodes);
108  /*
109  * @brief A signal that will be emitted by the 'ChangeSelectionMode'-slot.
110  * This happens if the selection mode is change from outside of this class,
111  * e.g. from a QmitkSynchronizedNodeSelectionWidget.
112  * This signal is connected to the 'SetSelectAll'-slot of each
113  * QmitkSynchronizedNodeSelectionWidget to propagate the selection mode.
114  *
115  * @param selectAll True, if the selection mode is changed to "select all" nodes.
116  * False otherwise.
117  */
118  void SelectionModeChanged(bool selectAll);
119 
120  void NodeVisibilityChanged(mitk::DataNode::Pointer node, const bool visibility);
121  void NodesLayerMoved(QSet<mitk::DataNode*> movedNodes, const int targetLayer);
122 
123 public Q_SLOTS:
124  /*
125  * @brief Set a new internal selection and send this new selection to connected
126  * QmitkSynchronizedNodeSelectionWidgets using the 'NodeSelectionChanged'-signal.
127  *
128  * This slot itself is connected to the 'CurrentSelectionChanged'-signal of each
129  * QmitkSynchronizedNodeSelectionWidget to receive a new selection.
130  *
131  * @param nodes A list of data nodes that are newly selected.
132  */
133  void ChangeSelection(NodeList nodes);
134 
135  /*
136  * @brief Set a new selection mode and send this new selection mode to connected
137  * QmitkSynchronizedNodeSelectionWidgets using the 'SelectionModeChanged'-signal.
138  *
139  * This slot itself is connected to the 'SelectionModeChanged'-signal of each
140  * QmitkSynchronizedNodeSelectionWidget to receive a new selection mode.
141  *
142  * @param selectAll True, if the selection mode is changed to "select all" nodes.
143  * False otherwise.
144  */
145  void ChangeSelectionMode(bool selectAll);
146 
147  /*
148  * @brief When the visibility of a node is changed in a connected widget,
149  * update the internal set of invisible selected nodes.
150  * This information is needed to fully synchronize newly connected widgets.
151  * @param node A pointer to the data node for which visibility was toggled.
152  * @param visibility The new visibility of the respective data node.
153  */
154  void OnNodeVisibilityChanged(mitk::DataNode::Pointer node, bool visibility);
155 
156  /*
157  * @brief Decrease the internal counter of connections to keep track of how many
158  * QmitkSynchronizedNodeSelectionWidgets are synchronized.
159  *
160  * This slot itself is connected to the 'DeregisterSynchronization'-signal of each
161  * QmitkSynchronizedNodeSelectionWidget to get notified when a synchronized
162  * widget is deleted.
163  */
164  void DeregisterWidget();
165 
166 private:
167 
168  NodeList m_InternalSelection;
169  std::set<mitk::DataNode*> m_InternalInvisibles;
170  bool m_SelectAll;
171  unsigned int m_ConnectionCounter;
172 
173 };
174 
175 #endif
MITKQTWIDGETS_EXPORT
#define MITKQTWIDGETS_EXPORT
Definition: MitkQtWidgetsExports.h:15
QmitkSynchronizedNodeSelectionWidget::NodeList
QmitkAbstractNodeSelectionWidget::NodeList NodeList
Definition: QmitkSynchronizedNodeSelectionWidget.h:51
QmitkSynchronizedWidgetConnector::NodeList
QmitkSynchronizedNodeSelectionWidget::NodeList NodeList
Definition: QmitkSynchronizedWidgetConnector.h:46
itk::SmartPointer< Self >
QmitkSynchronizedWidgetConnector
Definition: QmitkSynchronizedWidgetConnector.h:40
QmitkSynchronizedNodeSelectionWidget.h
QmitkSynchronizedNodeSelectionWidget
Definition: QmitkSynchronizedNodeSelectionWidget.h:42
MitkQtWidgetsExports.h
mitkDataNode.h