Medical Imaging Interaction Toolkit  2024.12.00
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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);
52  ~QmitkDataStorageTreeModel() override;
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;
96  bool dropMimeData(
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);
116  void SetDataStorageDeleted();
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 
142  void nodeVisibilityChanged();
143 
144  //# MISC
145 protected:
146 
148 
149  QList<TreeItem *> ToTreeItemPtrList(const QMimeData *mimeData);
150  QList<TreeItem *> ToTreeItemPtrList(const QByteArray &ba);
151 
155  void AdjustLayerProperty();
159  TreeItem *TreeItemFromIndex(const QModelIndex &index) const;
163  QModelIndex IndexFromTreeItem(TreeItem *) const;
167  mitk::DataNode *GetParentNode(const mitk::DataNode *node) 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:
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
QmitkDataStorageTreeModel::m_Predicate
mitk::NodePredicateBase::Pointer m_Predicate
Definition: QmitkDataStorageTreeModel.h:184
QmitkDataStorageTreeModel::COLUMN_VISIBILITY
static const std::string COLUMN_VISIBILITY
Definition: QmitkDataStorageTreeModel.h:47
QmitkDataStorageTreeModelInternalItem
Definition: QmitkDataStorageTreeModelInternalItem.h:26
QmitkDataStorageTreeModel::COLUMN_NAME
static const std::string COLUMN_NAME
Definition: QmitkDataStorageTreeModel.h:45
MITKQTWIDGETS_EXPORT
#define MITKQTWIDGETS_EXPORT
Definition: MitkQtWidgetsExports.h:15
QmitkDataStorageTreeModel::GetPlaceNewNodesOnTopFlag
bool GetPlaceNewNodesOnTopFlag()
Definition: QmitkDataStorageTreeModel.h:73
mitkDataStorage.h
itk::SmartPointer< Self >
QmitkDataStorageTreeModel::m_PlaceNewNodesOnTop
bool m_PlaceNewNodesOnTop
Definition: QmitkDataStorageTreeModel.h:185
QmitkDataStorageTreeModel::m_AllowHierarchyChange
bool m_AllowHierarchyChange
Definition: QmitkDataStorageTreeModel.h:196
mitkNodePredicateBase.h
QmitkDataStorageTreeModel::m_DataStorage
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
Definition: QmitkDataStorageTreeModel.h:183
MitkQtWidgetsExports.h
QmitkEnums.h
mitk::DataStorage
Data management class that handles 'was created by' relations.
Definition: mitkDataStorage.h:43
mitkWeakPointer.h
QmitkDataStorageTreeModel::m_Root
TreeItem * m_Root
Definition: QmitkDataStorageTreeModel.h:186
QmitkDataStorageTreeModel::COLUMN_TYPE
static const std::string COLUMN_TYPE
Definition: QmitkDataStorageTreeModel.h:46
mitk::WeakPointer< mitk::DataStorage >
QmitkCustomVariants.h
QmitkDataStorageTreeModel::m_BlockDataStorageEvents
bool m_BlockDataStorageEvents
Flag to block the data storage events if nodes are added/removed by this class.
Definition: QmitkDataStorageTreeModel.h:189
mitk::DataNode
Class for nodes of the DataTree.
Definition: mitkDataNode.h:63
QmitkDataStorageTreeModel
Definition: QmitkDataStorageTreeModel.h:39