Medical Imaging Interaction Toolkit  2018.4.99-389bf124
Medical Imaging Interaction Toolkit
QmitkDataStorageHistoryModel.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 
14 
15 #include "mitkWeakPointer.h"
16 #include <deque>
17 #include <algorithm>
18 #include <mutex>
19 
24 using NodeHistoryType = std::deque< const mitk::DataNode* >;
25 
28 std::mutex _historyMutex;
29 
31 {
32 }
33 
35 {
36  std::vector<mitk::DataNode::Pointer> dataNodes;
37  if (!m_DataStorage.IsExpired())
38  {
39  auto dataStorage = m_DataStorage.Lock();
40  if (dataStorage.IsNotNull())
41  {
42  mitk::DataStorage::SetOfObjects::ConstPointer nodesCandidats;
43  if (m_NodePredicate.IsNotNull())
44  {
45  nodesCandidats = dataStorage->GetSubset(m_NodePredicate);
46  }
47  else
48  {
49  nodesCandidats = dataStorage->GetAll();
50  }
51 
52  const std::lock_guard<std::mutex> lock(_historyMutex);
53 
54  for (auto historyNode : _nodeHistory)
55  {
56  auto finding = std::find(nodesCandidats->begin(), nodesCandidats->end(), historyNode);
57  if (finding != nodesCandidats->end())
58  {
59  dataNodes.push_back(*finding);
60  }
61  }
62  }
63  }
64 
65  // update the model, so that it will be filled with the nodes of the new data storage
66  beginResetModel();
67  m_DataNodes = dataNodes;
68  endResetModel();
69 }
70 
72 {
73  const std::lock_guard<std::mutex> lock(_historyMutex);
74 
75  auto finding = std::find(std::begin(_nodeHistory), std::end(_nodeHistory), node);
76  while (finding != std::end(_nodeHistory))
77  {
78  _nodeHistory.erase(finding);
79  finding = std::find(std::begin(_nodeHistory), std::end(_nodeHistory), node);
80  }
81 
82  _nodeHistory.push_front(node);
83 }
84 
86 {
87  const std::lock_guard<std::mutex> lock(_historyMutex);
88  _nodeHistory.clear();
89 }
itk::SmartPointer< T > Lock() const
The &#39;QmitkDataStorageDefaultListModel&#39; is a basic list model, derived from the &#39;QmitkAbstractDataStor...
NodeHistoryType _nodeHistory
std::vector< mitk::DataNode::Pointer > m_DataNodes
mitk::NodePredicateBase::ConstPointer m_NodePredicate
bool IsExpired() const noexcept
std::deque< const mitk::DataNode *> NodeHistoryType
static void AddNodeToHistory(mitk::DataNode *node)
std::mutex _historyMutex
Class for nodes of the DataTree.
Definition: mitkDataNode.h:57
mitk::WeakPointer< mitk::DataStorage > m_DataStorage