MCPcopy Create free account
hub / github.com/MITK/MITK / SetCurrentSelection

Method SetCurrentSelection

Modules/QtWidgets/src/QmitkModelViewSelectionConnector.cpp:60–99  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58}
59
60void QmitkModelViewSelectionConnector::SetCurrentSelection(QList<mitk::DataNode::Pointer> selectedNodes)
61{
62 if (nullptr == m_Model || nullptr == m_View)
63 {
64 return;
65 }
66
67 // filter input nodes and return the modified input node list
68 QList<mitk::DataNode::Pointer> filteredNodes = FilterNodeList(selectedNodes);
69
70 bool equal = EqualNodeSelections(this->GetInternalSelectedNodes(), filteredNodes);
71 if (equal)
72 {
73 return;
74 }
75
76 if (!m_SelectOnlyVisibleNodes)
77 {
78 // store the unmodified selection
79 m_NonVisibleSelection = selectedNodes;
80 // remove the nodes in the original selection that are already contained in the filtered input node list
81 // this will keep the selection of the original nodes that are not presented by the current view unmodified, but allows to change the selection of the filtered nodes
82 // later, the nodes of the 'm_NonVisibleSelection' member have to be added again to the list of selected (filtered) nodes, if a selection is sent from the current view (see 'ModelSelectionChanged')
83 auto lambda = [&filteredNodes](mitk::DataNode::Pointer original) { return filteredNodes.contains(original); };
84 m_NonVisibleSelection.erase(std::remove_if(m_NonVisibleSelection.begin(), m_NonVisibleSelection.end(), lambda), m_NonVisibleSelection.end());
85 }
86
87 // create new selection by retrieving the corresponding indices of the (filtered) nodes
88 QItemSelection newCurrentSelection;
89 for (const auto& node : std::as_const(filteredNodes))
90 {
91 QModelIndexList matched = m_Model->match(m_Model->index(0, 0), QmitkDataNodeRole, QVariant::fromValue<mitk::DataNode::Pointer>(node), 1, Qt::MatchRecursive);
92 if (!matched.empty())
93 {
94 newCurrentSelection.select(matched.front(), matched.front());
95 }
96 }
97
98 m_View->selectionModel()->select(newCurrentSelection, QItemSelectionModel::ClearAndSelect);
99}
100
101void QmitkModelViewSelectionConnector::ChangeModelSelection(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/)
102{

Callers

nothing calls this directly

Calls 9

containsMethod · 0.80
matchMethod · 0.80
frontMethod · 0.80
eraseMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
indexMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected