Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLSubjectHierarchyModel.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
6  Queen's University, Kingston, ON, Canada. All Rights Reserved.
7 
8  See COPYRIGHT.txt
9  or http://www.slicer.org/copyright/copyright.txt for details.
10 
11  Unless required by applicable law or agreed to in writing, software
12  distributed under the License is distributed on an "AS IS" BASIS,
13  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  See the License for the specific language governing permissions and
15  limitations under the License.
16 
17  This file was originally developed by Csaba Pinter, PerkLab, Queen's University
18  and was supported through the Applied Cancer Research Unit program of Cancer Care
19  Ontario with funds provided by the Ontario Ministry of Health and Long-Term Care
20 
21 ==============================================================================*/
22 
23 #ifndef __qMRMLSubjectHierarchyModel_h
24 #define __qMRMLSubjectHierarchyModel_h
25 
26 // Qt includes
27 #include <QStandardItemModel>
28 
29 // CTK includes
30 #include <ctkPimpl.h>
31 #include <ctkVTKObject.h>
32 
33 // SubjectHierarchy includes
34 #include "qSlicerSubjectHierarchyModuleWidgetsExport.h"
35 
36 class qMRMLSubjectHierarchyModelPrivate;
38 class vtkMRMLNode;
39 class vtkMRMLScene;
40 
49 class Q_SLICER_MODULE_SUBJECTHIERARCHY_WIDGETS_EXPORT qMRMLSubjectHierarchyModel : public QStandardItemModel
50 {
51  Q_OBJECT
52  QVTK_OBJECT
53 
60  Q_PROPERTY (int nameColumn READ nameColumn WRITE setNameColumn)
63  Q_PROPERTY (int visibilityColumn READ visibilityColumn WRITE setVisibilityColumn)
66  Q_PROPERTY(int colorColumn READ colorColumn WRITE setColorColumn)
71  Q_PROPERTY (int transformColumn READ transformColumn WRITE setTransformColumn)
74  Q_PROPERTY (int descriptionColumn READ descriptionColumn WRITE setDescriptionColumn)
77  Q_PROPERTY (int idColumn READ idColumn WRITE setIDColumn)
78 
79 public:
80  typedef QStandardItemModel Superclass;
81  qMRMLSubjectHierarchyModel(QObject *parent=nullptr);
82  ~qMRMLSubjectHierarchyModel() override;
83 
85  {
87  SubjectHierarchyItemIDRole = Qt::UserRole + 1,
94  LastRole
95  };
96 
97  int nameColumn()const;
98  void setNameColumn(int column);
99 
100  int visibilityColumn()const;
101  void setVisibilityColumn(int column);
102 
103  int colorColumn()const;
104  void setColorColumn(int column);
105 
106  int transformColumn()const;
107  void setTransformColumn(int column);
108 
109  int descriptionColumn()const;
110  void setDescriptionColumn(int column);
111 
112  int idColumn()const;
113  void setIDColumn(int column);
114 
115  Qt::DropActions supportedDropActions()const override;
116  QMimeData* mimeData(const QModelIndexList& indexes)const override;
117  bool dropMimeData(const QMimeData *data, Qt::DropAction action,
118  int row, int column, const QModelIndex &parent) override;
119 
120  Q_INVOKABLE virtual void setMRMLScene(vtkMRMLScene* scene);
121  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
122 
123  vtkMRMLSubjectHierarchyNode* subjectHierarchyNode()const;
124 
126  QStandardItem* subjectHierarchySceneItem()const;
128  QModelIndex subjectHierarchySceneIndex()const;
129  virtual bool canBeAChild(vtkIdType itemID)const;
130  virtual bool canBeAParent(vtkIdType itemID)const;
131 
132  vtkIdType subjectHierarchyItemFromIndex(const QModelIndex &index)const;
133  vtkIdType subjectHierarchyItemFromItem(QStandardItem* item)const;
134  QModelIndex indexFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
135  QStandardItem* itemFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
136 
138  QModelIndexList indexes(vtkIdType itemID)const;
139 
140  Q_INVOKABLE virtual vtkIdType parentSubjectHierarchyItem(vtkIdType itemID)const;
143  Q_INVOKABLE virtual int subjectHierarchyItemIndex(vtkIdType itemID)const;
145  Q_INVOKABLE virtual bool reparent(vtkIdType itemID, vtkIdType newParentID);
147  Q_INVOKABLE virtual bool moveToRow(vtkIdType itemID, int newRow);
150  Q_INVOKABLE bool isAncestorItem(vtkIdType child, vtkIdType ancestor)const;
153  Q_INVOKABLE bool isAffiliatedItem(vtkIdType itemA, vtkIdType itemB)const;
154 
155 signals:
157  void aboutToReparentByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
159  void reparentedByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
161  void subjectHierarchyAboutToBeUpdated();
163  void subjectHierarchyUpdated();
165  void requestExpandItem(vtkIdType itemID);
167  void requestCollapseItem(vtkIdType itemID);
169  void requestSelectItems(QList<vtkIdType> itemIDs);
171  void invalidateFilter();
172 
173 public slots:
175  void onRemoveTransformsFromBranchOfCurrentItem();
176 
178  void onHardenTransformOnBranchOfCurrentItem();
179 
180 protected slots:
181  virtual void onSubjectHierarchyItemAdded(vtkIdType itemID);
182  virtual void onSubjectHierarchyItemAboutToBeRemoved(vtkIdType itemID);
183  virtual void onSubjectHierarchyItemRemoved(vtkIdType itemID);
184  virtual void onSubjectHierarchyItemModified(vtkIdType itemID);
185 
186  virtual void onMRMLSceneImported(vtkMRMLScene* scene);
187  virtual void onMRMLSceneClosed(vtkMRMLScene* scene);
188  virtual void onMRMLSceneStartBatchProcess(vtkMRMLScene* scene);
189  virtual void onMRMLSceneEndBatchProcess(vtkMRMLScene* scene);
190  virtual void onMRMLNodeRemoved(vtkMRMLNode* node);
191 
192  virtual void onItemChanged(QStandardItem* item);
193  virtual void delayedItemChanged();
194 
197  void updateColumnCount();
198 
199 protected:
200  qMRMLSubjectHierarchyModel(qMRMLSubjectHierarchyModelPrivate* pimpl, QObject *parent=nullptr);
201 
203  virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);
204 
207  virtual void rebuildFromSubjectHierarchy();
210  virtual void updateFromSubjectHierarchy();
211 
212  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID);
213  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID, QStandardItem* parent, int row=-1);
214 
215  virtual QFlags<Qt::ItemFlag> subjectHierarchyItemFlags(vtkIdType itemID, int column)const;
216 
217  virtual void updateItemFromSubjectHierarchyItem(
218  QStandardItem* item, vtkIdType shItemID, int column );
219  virtual void updateItemDataFromSubjectHierarchyItem(
220  QStandardItem* item, vtkIdType shItemID, int column );
221  virtual void updateSubjectHierarchyItemFromItem(
222  vtkIdType shItemID, QStandardItem* item );
223  virtual void updateSubjectHierarchyItemFromItemData(
224  vtkIdType shItemID, QStandardItem* item );
225 
227  void updateModelItems(vtkIdType itemID);
228 
229  static void onEvent(vtkObject* caller, unsigned long event, void* clientData, void* callData);
230 
232  virtual int maxColumnId()const;
233 
234 protected:
235  QScopedPointer<qMRMLSubjectHierarchyModelPrivate> d_ptr;
236 
237 private:
238  Q_DECLARE_PRIVATE(qMRMLSubjectHierarchyModel);
239  Q_DISABLE_COPY(qMRMLSubjectHierarchyModel);
240 };
241 
242 void printStandardItem(QStandardItem* item, const QString& offset);
243 
244 #endif
QScopedPointer< qMRMLSubjectHierarchyModelPrivate > d_ptr
MRML node ID of the parent transform.
void printStandardItem(QStandardItem *item, const QString &offset)
MRML node to represent a complete subject hierarchy tree.
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:61
Item model for subject hierarchy.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167