Medical Imaging Interaction Toolkit  2018.4.99-f51274ea
Medical Imaging Interaction Toolkit
QmitkAbstractDataStorageModel.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 
16  : QAbstractItemModel(parent)
17  , m_DataStorage(nullptr)
18  , m_NodePredicate(nullptr)
19 {
20  // nothing here
21 }
22 
24  : QAbstractItemModel(parent)
25  , m_DataStorage(nullptr)
26  , m_NodePredicate(nullptr)
27 {
28  SetDataStorage(dataStorage);
29 }
30 
32 {
33  if (!m_DataStorage.IsExpired())
34  {
35  auto dataStorage = m_DataStorage.Lock();
36 
37  if (dataStorage.IsNotNull())
38  {
39  // remove Listener for the data storage itself
40  dataStorage->RemoveObserver(m_DataStorageDeletedTag);
41 
42  // remove listener from data storage
43  dataStorage->AddNodeEvent.RemoveListener(
45  dataStorage->RemoveNodeEvent.RemoveListener(
47  dataStorage->ChangedNodeEvent.RemoveListener(
49  }
50  }
51 }
52 
54 {
55  if (m_DataStorage == dataStorage)
56  {
57  return;
58  }
59 
60  if (!m_DataStorage.IsExpired())
61  {
62  auto dataStorage = m_DataStorage.Lock();
63 
64  if (dataStorage.IsNotNull())
65  {
66  // remove Listener for the data storage itself
67  dataStorage->RemoveObserver(m_DataStorageDeletedTag);
68 
69  // remove listener from old data storage
70  dataStorage->AddNodeEvent.RemoveListener(
72  dataStorage->RemoveNodeEvent.RemoveListener(
74  dataStorage->ChangedNodeEvent.RemoveListener(
76  }
77  }
78 
79  m_DataStorage = dataStorage;
80 
81  if (!m_DataStorage.IsExpired())
82  {
83  auto dataStorage = m_DataStorage.Lock();
84 
85  if (dataStorage.IsNotNull())
86  {
87  // add Listener for the data storage itself
88  auto command = itk::SimpleMemberCommand<QmitkAbstractDataStorageModel>::New();
89  command->SetCallbackFunction(this, &QmitkAbstractDataStorageModel::SetDataStorageDeleted);
90  m_DataStorageDeletedTag = dataStorage->AddObserver(itk::DeleteEvent(), command);
91 
92  // add listener for new data storage
93  dataStorage->AddNodeEvent.AddListener(
95  dataStorage->RemoveNodeEvent.AddListener(
97  dataStorage->ChangedNodeEvent.AddListener(
99  }
100  }
101  // update model if the data storage has been changed
103 }
104 
106 {
107  if (m_DataStorage.IsExpired())
108  {
109  return nullptr;
110  }
111 
112  return m_DataStorage.Lock().GetPointer();
113 }
114 
115 void QmitkAbstractDataStorageModel::SetDataStorageDeleted()
116 {
117  this->SetDataStorage(nullptr);
118 }
119 
121 {
122  if (m_NodePredicate == nodePredicate)
123  {
124  return;
125  }
126 
127  m_NodePredicate = nodePredicate;
128  // update model if the node predicate has been changed
130 }
Data management class that handles &#39;was created by&#39; relations.
itk::SmartPointer< T > Lock() const
virtual void NodePredicateChanged()=0
void SetDataStorage(mitk::DataStorage *dataStorage)
QmitkAbstractDataStorageModel(QObject *parent=nullptr)
virtual void DataStorageChanged()=0
virtual void NodeChanged(const mitk::DataNode *node)=0
mitk::NodePredicateBase::ConstPointer m_NodePredicate
mitk::DataStorage::Pointer m_DataStorage
bool IsExpired() const noexcept
void AddListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:374
DataStorageEvent AddNodeEvent
AddEvent is emitted whenever a new node has been added to the DataStorage.
virtual void NodeRemoved(const mitk::DataNode *node)=0
virtual void NodeAdded(const mitk::DataNode *node)=0
DataStorageEvent RemoveNodeEvent
RemoveEvent is emitted directly before a node is removed from the DataStorage.
void RemoveListener(const AbstractDelegate &delegate) const
Definition: mitkMessage.h:393
DataStorageEvent ChangedNodeEvent
ChangedEvent is emitted directly after a node was changed.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
void SetNodePredicate(const mitk::NodePredicateBase *nodePredicate)
mitk::WeakPointer< mitk::DataStorage > m_DataStorage