Medical Imaging Interaction Toolkit  2024.06.00
Medical Imaging Interaction Toolkit
QmitkAbstractDataStorageModel.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 QmitkAbstractDataStorageModel_h
14 #define QmitkAbstractDataStorageModel_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 // mitk core
19 #include <mitkDataStorage.h>
20 #include <mitkNodePredicateBase.h>
21 #include <mitkWeakPointer.h>
22 
23 // qt
24 #include <QAbstractItemModel>
25 
26 /*
27 * @brief This abstract class extends the 'QAbstractItemModel' to accept an 'mitk::DataStorage' and a 'mitk::NodePredicateBase'.
28 * It registers itself as a node event listener of the data storage.
29 * The 'QmitkAbstractDataStorageModel' provides three empty functions, 'NodeAdded', 'NodeChanged' and 'NodeRemoved', that
30 * may be implemented by subclasses. These functions allow to react to the 'AddNodeEvent', 'ChangedNodeEvent' and
31 * 'RemoveNodeEvent' of the data storage. This might be useful to force an update on a custom view to correctly
32 * represent the content of the data storage.
33 *
34 * A concrete implementation of this class is used to store the temporarily shown data nodes of the data storage.
35 * These nodes may be a subset of all the nodes inside the data storage, if a specific node predicate is set.
36 *
37 * A model that implements this class has to return mitk::DataNode::Pointer objects for model indexes when the
38 * role is QmitkDataNodeRole.
39 */
40 class MITKQTWIDGETS_EXPORT QmitkAbstractDataStorageModel : public QAbstractItemModel
41 {
42  Q_OBJECT
43 
44 public:
45 
47  /*
48  * @brief Sets the data storage and adds listener for node events.
49  *
50  * @param dataStorage A pointer to the data storage to set.
51  */
52  void SetDataStorage(mitk::DataStorage* dataStorage);
53 
54  mitk::DataStorage::Pointer GetDataStorage() const;
55  /*
56  * @brief Sets the node predicate and updates the model data, according to the node predicate.
57  *
58  * @param nodePredicate A pointer to node predicate.
59  */
60  void SetNodePredicate(const mitk::NodePredicateBase* nodePredicate);
61 
62  const mitk::NodePredicateBase* GetNodePredicate() const { return m_NodePredicate; }
63 
64 protected:
65 
66  virtual void DataStorageChanged() = 0;
67  virtual void NodePredicateChanged() = 0;
68 
69  virtual void NodeAdded(const mitk::DataNode* node) = 0;
70  virtual void NodeChanged(const mitk::DataNode* node) = 0;
71  virtual void NodeRemoved(const mitk::DataNode* node) = 0;
72 
73  QmitkAbstractDataStorageModel(QObject* parent = nullptr);
74  QmitkAbstractDataStorageModel(mitk::DataStorage* dataStorage, QObject* parent = nullptr);
75 
78 
79 private:
80 
82  void SetDataStorageDeleted();
83 
84  unsigned long m_DataStorageDeletedTag;
85 
86 };
87 
88 #endif
MITKQTWIDGETS_EXPORT
#define MITKQTWIDGETS_EXPORT
Definition: MitkQtWidgetsExports.h:15
mitkDataStorage.h
itk::SmartPointer< Self >
mitk::NodePredicateBase
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Definition: mitkNodePredicateBase.h:35
mitkNodePredicateBase.h
QmitkAbstractDataStorageModel::GetNodePredicate
const mitk::NodePredicateBase * GetNodePredicate() const
Definition: QmitkAbstractDataStorageModel.h:62
QmitkAbstractDataStorageModel::m_NodePredicate
mitk::NodePredicateBase::ConstPointer m_NodePredicate
Definition: QmitkAbstractDataStorageModel.h:77
MitkQtWidgetsExports.h
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
mitkWeakPointer.h
QmitkAbstractDataStorageModel::m_DataStorage
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
Definition: QmitkAbstractDataStorageModel.h:76
mitk::WeakPointer< mitk::DataStorage >
QmitkAbstractDataStorageModel
Definition: QmitkAbstractDataStorageModel.h:40
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63