| 58 | } |
| 59 | |
| 60 | void 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 | |
| 101 | void QmitkModelViewSelectionConnector::ChangeModelSelection(const QItemSelection& /*selected*/, const QItemSelection& /*deselected*/) |
| 102 | { |