Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef QMITKDATASTORAGETREEMODEL_H_
18 #define QMITKDATASTORAGETREEMODEL_H_
19 
20 #include <MitkQtWidgetsExports.h>
21 
22 #include <mitkDataStorage.h>
23 #include <mitkNodePredicateBase.h>
24 #include <mitkWeakPointer.h>
25 
26 #include <QAbstractListModel>
27 
28 #include "QmitkCustomVariants.h"
29 #include "QmitkEnums.h"
30 
31 #include <QList>
32 #include <string>
33 #include <vector>
34 
36 class MITKQTWIDGETS_EXPORT QmitkDataStorageTreeModel : public QAbstractItemModel
37 {
38  //# CONSTANTS,TYPEDEFS
39 public:
40  static const std::string COLUMN_NAME;
41  static const std::string COLUMN_TYPE;
42  static const std::string COLUMN_VISIBILITY;
43 
44  //# CTORS,DTOR
45 public:
46  QmitkDataStorageTreeModel(mitk::DataStorage *_DataStorage, bool _PlaceNewNodesOnTop = false, QObject *parent = 0);
48 
49  //# GETTER
50 public:
55  mitk::DataNode::Pointer GetNode(const QModelIndex &index) const;
59  virtual QList<mitk::DataNode::Pointer> GetNodeSet() const;
64 
68  bool GetPlaceNewNodesOnTopFlag() { return m_PlaceNewNodesOnTop; }
72  void SetPlaceNewNodesOnTop(bool _PlaceNewNodesOnTop);
73 
74  //# (Re-)implemented from QAbstractItemModel
75  //# Read model
76  Qt::ItemFlags flags(const QModelIndex &index) const override;
77  QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
78  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
79  int rowCount(const QModelIndex &parent = QModelIndex()) const override;
80  int columnCount(const QModelIndex &parent = QModelIndex()) const override;
81  //# hierarchical model
86  QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override;
87  QModelIndex parent(const QModelIndex &index) const override;
88  //# editable model
89  bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
90  bool setHeaderData(int section, Qt::Orientation orientation, const QVariant &value, int role = Qt::EditRole) override;
91  bool dropMimeData(
92  const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override;
93  Qt::DropActions supportedDropActions() const override;
94  Qt::DropActions supportedDragActions() const override;
95  QStringList mimeTypes() const override;
96  QMimeData *mimeData(const QModelIndexList &indexes) const override;
97 
98  static QMimeData *mimeDataFromModelIndexList(const QModelIndexList &indexes);
99 
100  //# End of QAbstractItemModel
101 
102  //# SETTER
103 public:
107  void SetDataStorage(mitk::DataStorage *_DataStorage);
111  void SetDataStorageDeleted(const itk::Object *_DataStorage);
117  virtual void AddNode(const mitk::DataNode *node);
121  virtual void RemoveNode(const mitk::DataNode *node);
125  virtual void SetNodeModified(const mitk::DataNode *node);
126 
130  QModelIndex GetIndex(const mitk::DataNode *) const;
131 
133  void SetAllowHierarchyChange(bool allowHierarchyChange);
134 
135  //# MISC
136 protected:
140  class TreeItem
141  {
142  public:
146  TreeItem(mitk::DataNode *_DataNode, TreeItem *_Parent = 0);
151  virtual ~TreeItem();
155  int IndexOfChild(const TreeItem *item) const;
159  TreeItem *GetChild(int index) const;
163  TreeItem *Find(const mitk::DataNode *_DataNode) const;
167  int GetChildCount() const;
171  int GetIndex() const;
175  TreeItem *GetParent() const;
179  mitk::DataNode::Pointer GetDataNode() const;
183  std::vector<TreeItem *> GetChildren() const;
184 
188  void AddChild(TreeItem *item);
192  void RemoveChild(TreeItem *item);
197  void InsertChild(TreeItem *item, int index = -1);
199  void SetParent(TreeItem *_Parent);
203  void Delete();
204 
205  protected:
207  std::vector<TreeItem *> m_Children;
209  };
210 
211  QList<TreeItem *> ToTreeItemPtrList(const QMimeData *mimeData);
212  QList<TreeItem *> ToTreeItemPtrList(const QByteArray &ba);
213 
217  void AdjustLayerProperty();
221  TreeItem *TreeItemFromIndex(const QModelIndex &index) const;
225  QModelIndex IndexFromTreeItem(TreeItem *) const;
229  mitk::DataNode *GetParentNode(const mitk::DataNode *node) const;
233  void TreeToVector(TreeItem *parent, std::vector<TreeItem *> &vec) const;
237  void TreeToNodeSet(TreeItem *parent, QList<mitk::DataNode::Pointer> &vec) const;
241  void Update();
242 
243  //# ATTRIBUTES
244 protected:
249 
252 
259 
260 private:
261  void AddNodeInternal(const mitk::DataNode *);
262  void RemoveNodeInternal(const mitk::DataNode *);
266  bool DicomPropertiesExists(const mitk::DataNode &) const;
267 };
268 
269 #endif /* QMITKDATASTORAGETREEMODEL_H_ */
Data management class that handles 'was created by' relations.
static void Update(vtkPolyData *)
Definition: mitkSurface.cpp:35
static mitk::DataStorage::Pointer GetDataStorage()
#define MITKQTWIDGETS_EXPORT
bool m_BlockDataStorageEvents
Flag to block the data storage events if nodes are added/removed by this class.
static const std::string COLUMN_TYPE
static const std::string COLUMN_VISIBILITY
#define AddNode(name)
mitk::WeakPointer< mitk::DataStorage > m_DataStorage
static const std::string COLUMN_NAME
mitk::NodePredicateBase::Pointer m_Predicate
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66