Medical Imaging Interaction Toolkit  2025.12.02
Medical Imaging Interaction Toolkit
QmitkDataStorageTreeModel.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 QmitkDataStorageTreeModel_h
14 #define QmitkDataStorageTreeModel_h
15 
16 #include <MitkQtWidgetsExports.h>
17 
18 #include <mitkDataStorage.h>
19 #include <mitkNodePredicateBase.h>
20 #include <mitkWeakPointer.h>
21 
22 #include <QAbstractListModel>
23 
24 #include "QmitkCustomVariants.h"
25 #include "QmitkEnums.h"
26 
27 #include <QList>
28 #include <string>
29 #include <vector>
30 
32 
39 class MITKQTWIDGETS_EXPORT QmitkDataStorageTreeModel : public QAbstractItemModel
40 {
41  Q_OBJECT
42 
43  //# CONSTANTS,TYPEDEFS
44 public:
45  static const std::string COLUMN_NAME;
46  static const std::string COLUMN_TYPE;
47  static const std::string COLUMN_VISIBILITY;
48 
49  //# CTORS,DTOR
50 public:
51  QmitkDataStorageTreeModel(mitk::DataStorage *_DataStorage, bool _PlaceNewNodesOnTop = false, QObject *parent = nullptr);
53 
54  //# GETTER
55 public:
60  mitk::DataNode::Pointer GetNode(const QModelIndex &index) const;
64  virtual QList<mitk::DataNode::Pointer> GetNodeSet() const;
68  const mitk::DataStorage::Pointer GetDataStorage() const;
69 
73  bool GetPlaceNewNodesOnTopFlag() { return m_PlaceNewNodesOnTop; }
77  void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop);
78 
79  //# (Re-)implemented from QAbstractItemModel
80  //# Read model
81  Qt::ItemFlags flags(const QModelIndex &index) const override;
82  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
83  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
84  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
85  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
86  //# hierarchical model
91  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
92  QModelIndex parent(const QModelIndex &index) const override;
93  //# editable model
94  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
95  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
97  const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
98  Qt::DropActions supportedDropActions() const override;
99  Qt::DropActions supportedDragActions() const override;
100  QStringList mimeTypes() const override;
101  QMimeData *mimeData(const QModelIndexList &indexes) const override;
102 
103  static QMimeData *mimeDataFromModelIndexList(const QModelIndexList &indexes);
104 
105  //# End of QAbstractItemModel
106 
107  //# SETTER
108 public:
112  void SetDataStorage(mitk::DataStorage *_DataStorage);
122  virtual void AddNode(const mitk::DataNode *node);
126  virtual void RemoveNode(const mitk::DataNode *node);
130  virtual void SetNodeModified(const mitk::DataNode *node);
131 
135  QModelIndex GetIndex(const mitk::DataNode *) const;
136 
138  void SetAllowHierarchyChange(bool allowHierarchyChange);
139 
140 signals:
141 
143 
144  //# MISC
145 protected:
146 
148 
149  QList<TreeItem *> ToTreeItemPtrList(const QMimeData *mimeData);
150  QList<TreeItem *> ToTreeItemPtrList(const QByteArray &ba);
151 
159  TreeItem *TreeItemFromIndex(const QModelIndex &index) const;
163  QModelIndex IndexFromTreeItem(TreeItem *) const;
171  void TreeToVector(TreeItem *parent, std::vector<TreeItem *> &vec) const;
175  void TreeToNodeSet(TreeItem *parent, QList<mitk::DataNode::Pointer> &vec) const;
179  void Update();
180 
181  //# ATTRIBUTES
182 protected:
184  mitk::NodePredicateBase::Pointer m_Predicate;
187 
190 
197 
198 private:
199  void AddNodeInternal(const mitk::DataNode *);
200  void RemoveNodeInternal(const mitk::DataNode *);
204  bool DicomPropertiesExists(const mitk::DataNode &) const;
205 
206  unsigned long m_DataStorageDeletedTag;
207 };
208 
209 #endif
#define MITKQTWIDGETS_EXPORT
mitk::DataNode::Pointer GetNode(const QModelIndex &index) const
Qt::DropActions supportedDropActions() const override
QModelIndex IndexFromTreeItem(TreeItem *) const
Qt::DropActions supportedDragActions() const override
int columnCount(const QModelIndex &parent=QModelIndex()) const override
virtual QList< mitk::DataNode::Pointer > GetNodeSet() const
static const std::string COLUMN_VISIBILITY
~QmitkDataStorageTreeModel() override
virtual void RemoveNode(const mitk::DataNode *node)
QMimeData * mimeData(const QModelIndexList &indexes) const override
QList< TreeItem * > ToTreeItemPtrList(const QByteArray &ba)
QModelIndex parent(const QModelIndex &index) const override
mitk::DataNode * GetParentNode(const mitk::DataNode *node) const
QmitkDataStorageTreeModel(mitk::DataStorage *_DataStorage, bool _PlaceNewNodesOnTop=false, QObject *parent=nullptr)
void TreeToNodeSet(TreeItem *parent, QList< mitk::DataNode::Pointer > &vec) const
const mitk::DataStorage::Pointer GetDataStorage() const
mitk::NodePredicateBase::Pointer m_Predicate
virtual void SetNodeModified(const mitk::DataNode *node)
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
TreeItem * TreeItemFromIndex(const QModelIndex &index) const
QVariant headerData(int section, Qt::Orientation orientation, int role=Qt::DisplayRole) const override
virtual void AddNode(const mitk::DataNode *node)
static QMimeData * mimeDataFromModelIndexList(const QModelIndexList &indexes)
QModelIndex index(int row, int column, const QModelIndex &parent=QModelIndex()) const override
static const std::string COLUMN_TYPE
QModelIndex GetIndex(const mitk::DataNode *) const
void SetDataStorage(mitk::DataStorage *_DataStorage)
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Qt::ItemFlags flags(const QModelIndex &index) const override
QList< TreeItem * > ToTreeItemPtrList(const QMimeData *mimeData)
bool setData(const QModelIndex &index, const QVariant &value, int role=Qt::EditRole) override
int rowCount(const QModelIndex &parent=QModelIndex()) const override
void TreeToVector(TreeItem *parent, std::vector< TreeItem * > &vec) const
static const std::string COLUMN_NAME
bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role=Qt::EditRole) override
void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop)
QStringList mimeTypes() const override
bool m_BlockDataStorageEvents
Flag to block the data storage events if nodes are added/removed by this class.
void SetAllowHierarchyChange(bool allowHierarchyChange)
Set whether to allow hierarchy changes by dragging and dropping.
QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const override
Class for nodes of the DataTree.
Definition: mitkDataNode.h:64
Data management class that handles 'was created by' relations.