Medical Imaging Interaction Toolkit  2025.12.02
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:
48  mitk::NodePredicateBase::Pointer pred = nullptr,
49  QObject *parent = nullptr);
50 
52 
54  void SetDataStorage(mitk::DataStorage::Pointer dataStorage);
55 
58 
61 
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 
121 
124 
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
#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.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Data management class that handles 'was created by' relations.
Interface for evaluation conditions used in the DataStorage class GetSubset() method.