Medical Imaging Interaction Toolkit  2026.06.00
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 
21 #ifndef QmitkDataStorageListModel_h
22 #define QmitkDataStorageListModel_h
23 
24 #include <MitkQtWidgetsExports.h>
25 
26 // MITK
27 #include <mitkDataStorage.h>
28 #include <mitkNodePredicateBase.h>
29 
30 // Qt
31 #include <QAbstractListModel>
32 
48 
49 class MITKQTWIDGETS_EXPORT QmitkDataStorageListModel : public QAbstractListModel
50 {
51 public:
56  mitk::NodePredicateBase::Pointer pred = nullptr,
57  QObject *parent = nullptr);
58 
60 
62  void SetDataStorage(mitk::DataStorage::Pointer dataStorage);
63 
66 
69 
72 
74  std::vector<mitk::DataNode *> GetDataNodes() const;
75 
77  mitk::DataNode::Pointer getNode(const QModelIndex &index) const;
78 
80  QModelIndex getIndex(const mitk::DataNode *node) const;
81 
83  Qt::ItemFlags flags(const QModelIndex &index) const override;
84 
86  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
87 
89  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
90 
92  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
93 
99  virtual void OnDataStorageNodeAdded(const mitk::DataNode *node);
100 
106  virtual void OnDataStorageNodeRemoved(const mitk::DataNode *node);
107 
111  virtual void OnDataNodeModified(const itk::Object *caller, const itk::EventObject &event);
112 
116  virtual void OnDataModified(const itk::Object *caller, const itk::EventObject &event);
117 
121  virtual void OnDataStorageDeleted(const itk::Object *caller, const itk::EventObject &event);
122 
123 protected:
125  void reset();
126 
129 
132 
135 
136 private:
137  enum OBSERVER_TUPLE_NAMES
138  {
139  NODE = 0,
140  NODE_OBSERVER = 1,
141  DATA_OBSERVER = 2,
142  };
143 
145  mitk::NodePredicateBase::Pointer m_NodePredicate;
146 
149  mitk::DataStorage *m_DataStorage;
150 
152  unsigned long m_DataStorageDeleteObserverTag;
153 
158  std::vector<std::tuple<mitk::DataNode *, unsigned long, unsigned long>> m_NodesAndObserverTags;
159 
161  bool m_BlockEvents;
162 };
163 
164 #endif
#define MITKQTWIDGETS_EXPORT
void AddNodeToInternalList(mitk::DataNode *node)
Internal helper: adds given node to end of list.
virtual void OnDataNodeModified(const itk::Object *caller, const itk::EventObject &event)
std::vector< mitk::DataNode * > GetDataNodes() const
Get all current data nodes.
void ClearInternalNodeList()
Internal helper: Clear complete model list.
Qt::ItemFlags flags(const QModelIndex &index) const override
Implements QAbstractListModel.
void SetPredicate(mitk::NodePredicateBase *pred)
Change the filter predicate.
virtual void OnDataModified(const itk::Object *caller, const itk::EventObject &event)
mitk::DataNode::Pointer getNode(const QModelIndex &index) const
Return the node for given model index.
virtual void OnDataStorageNodeAdded(const mitk::DataNode *node)
void RemoveNodeFromInternalList(mitk::DataNode *node)
Internal helper: remove given node.
mitk::DataStorage * GetDataStorage() const
Get the represented data storage.
QModelIndex getIndex(const mitk::DataNode *node) const
Return the model index of the given node.
void SetDataStorage(mitk::DataStorage::Pointer dataStorage)
Change the data storage to represent.
~QmitkDataStorageListModel() override
virtual void OnDataStorageDeleted(const itk::Object *caller, const itk::EventObject &event)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
Implements QAbstractListModel.
QmitkDataStorageListModel(mitk::DataStorage *dataStorage=nullptr, mitk::NodePredicateBase::Pointer pred=nullptr, QObject *parent=nullptr)
virtual void OnDataStorageNodeRemoved(const mitk::DataNode *node)
mitk::NodePredicateBase * GetPredicate() const
Get the filter predicate in use.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Implements QAbstractListModel.
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
Implements QAbstractListModel.
void reset()
Resets the whole model. Get all nodes matching the predicate from the data storage.
Central node class of the MITK data tree, associating a data object with properties and mappers.
Definition: mitkDataNode.h:72
Abstract data management class that organizes DataNode objects in a directed acyclic graph.
Abstract base class for predicates used to filter DataNode objects in DataStorage queries.