Medical Imaging Interaction Toolkit  2023.12.99-b884b24c
Medical Imaging Interaction Toolkit
QmitkDataStorageListModel.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 QmitkDataStorageListModel_h
14 #define QmitkDataStorageListModel_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 // MITK
19 #include "mitkDataStorage.h"
20 #include "mitkNodePredicateBase.h"
21 
22 // Qt
23 #include <QAbstractListModel>
24 
40 
41 class MITKQTWIDGETS_EXPORT QmitkDataStorageListModel : public QAbstractListModel
42 {
43 public:
47  QmitkDataStorageListModel(mitk::DataStorage *dataStorage = nullptr,
48  mitk::NodePredicateBase::Pointer pred = nullptr,
49  QObject *parent = nullptr);
50 
51  ~QmitkDataStorageListModel() override;
52 
54  void SetDataStorage(mitk::DataStorage::Pointer dataStorage);
55 
57  mitk::DataStorage *GetDataStorage() const;
58 
60  void SetPredicate(mitk::NodePredicateBase *pred);
61 
63  mitk::NodePredicateBase *GetPredicate() const;
64 
66  std::vector<mitk::DataNode *> GetDataNodes() const;
67 
69  mitk::DataNode::Pointer getNode(const QModelIndex &index) const;
70 
72  QModelIndex getIndex(const mitk::DataNode *node) const;
73 
75  Qt::ItemFlags flags(const QModelIndex &index) const override;
76 
78  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
79 
81  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
82 
84  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
85 
91  virtual void OnDataStorageNodeAdded(const mitk::DataNode *node);
92 
98  virtual void OnDataStorageNodeRemoved(const mitk::DataNode *node);
99 
103  virtual void OnDataNodeModified(const itk::Object *caller, const itk::EventObject &event);
104 
108  virtual void OnDataModified(const itk::Object *caller, const itk::EventObject &event);
109 
113  virtual void OnDataStorageDeleted(const itk::Object *caller, const itk::EventObject &event);
114 
115 protected:
117  void reset();
118 
120  void AddNodeToInternalList(mitk::DataNode *node);
121 
123  void RemoveNodeFromInternalList(mitk::DataNode *node);
124 
126  void ClearInternalNodeList();
127 
128 private:
129  enum OBSERVER_TUPLE_NAMES
130  {
131  NODE = 0,
132  NODE_OBSERVER = 1,
133  DATA_OBSERVER = 2,
134  };
135 
137  mitk::NodePredicateBase::Pointer m_NodePredicate;
138 
141  mitk::DataStorage *m_DataStorage;
142 
144  unsigned long m_DataStorageDeleteObserverTag;
145 
150  std::vector<std::tuple<mitk::DataNode *, unsigned long, unsigned long>> m_NodesAndObserverTags;
151 
153  bool m_BlockEvents;
154 };
155 
156 #endif
MITKQTWIDGETS_EXPORT
#define MITKQTWIDGETS_EXPORT
Definition: MitkQtWidgetsExports.h:15
mitkDataStorage.h
QmitkDataStorageListModel
Definition: QmitkDataStorageListModel.h:41
itk::SmartPointer< Self >
mitk::NodePredicateBase
Interface for evaluation conditions used in the DataStorage class GetSubset() method.
Definition: mitkNodePredicateBase.h:35
mitkNodePredicateBase.h
MitkQtWidgetsExports.h
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63