Slicer  4.10
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)
68  Q_PROPERTY (int transformColumn READ transformColumn WRITE setTransformColumn)
71  Q_PROPERTY (int idColumn READ idColumn WRITE setIDColumn)
72 
73 public:
74  typedef QStandardItemModel Superclass;
75  qMRMLSubjectHierarchyModel(QObject *parent=0);
76  virtual ~qMRMLSubjectHierarchyModel();
77 
79  {
81  SubjectHierarchyItemIDRole = Qt::UserRole + 1,
88  LastRole
89  };
90 
91  int nameColumn()const;
92  void setNameColumn(int column);
93 
94  int visibilityColumn()const;
95  void setVisibilityColumn(int column);
96 
97  int colorColumn()const;
98  void setColorColumn(int column);
99 
100  int transformColumn()const;
101  void setTransformColumn(int column);
102 
103  int idColumn()const;
104  void setIDColumn(int column);
105 
106  virtual Qt::DropActions supportedDropActions()const;
107  virtual QMimeData* mimeData(const QModelIndexList& indexes)const;
108  virtual bool dropMimeData(const QMimeData *data, Qt::DropAction action,
109  int row, int column, const QModelIndex &parent);
110 
111  Q_INVOKABLE virtual void setMRMLScene(vtkMRMLScene* scene);
112  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
113 
114  vtkMRMLSubjectHierarchyNode* subjectHierarchyNode()const;
115 
117  QStandardItem* subjectHierarchySceneItem()const;
119  QModelIndex subjectHierarchySceneIndex()const;
120  virtual bool canBeAChild(vtkIdType itemID)const;
121  virtual bool canBeAParent(vtkIdType itemID)const;
122 
123  vtkIdType subjectHierarchyItemFromIndex(const QModelIndex &index)const;
124  vtkIdType subjectHierarchyItemFromItem(QStandardItem* item)const;
125  QModelIndex indexFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
126  QStandardItem* itemFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
127 
129  QModelIndexList indexes(vtkIdType itemID)const;
130 
131  Q_INVOKABLE virtual vtkIdType parentSubjectHierarchyItem(vtkIdType itemID)const;
134  Q_INVOKABLE virtual int subjectHierarchyItemIndex(vtkIdType itemID)const;
136  Q_INVOKABLE virtual bool reparent(vtkIdType itemID, vtkIdType newParentID);
138  Q_INVOKABLE virtual bool moveToRow(vtkIdType itemID, int newRow);
141  Q_INVOKABLE bool isAncestorItem(vtkIdType child, vtkIdType ancestor)const;
144  Q_INVOKABLE bool isAffiliatedItem(vtkIdType itemA, vtkIdType itemB)const;
145 
146 signals:
148  void aboutToReparentByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
150  void reparentedByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
152  void subjectHierarchyAboutToBeUpdated();
154  void subjectHierarchyUpdated();
156  void requestExpandItem(vtkIdType itemID);
158  void requestCollapseItem(vtkIdType itemID);
160  void requestSelectItems(QList<vtkIdType> itemIDs);
162  void invalidateFilter();
163 
164 public slots:
166  void onRemoveTransformsFromBranchOfCurrentItem();
167 
169  void onHardenTransformOnBranchOfCurrentItem();
170 
171 protected slots:
172  virtual void onSubjectHierarchyItemAdded(vtkIdType itemID);
173  virtual void onSubjectHierarchyItemAboutToBeRemoved(vtkIdType itemID);
174  virtual void onSubjectHierarchyItemRemoved(vtkIdType itemID);
175  virtual void onSubjectHierarchyItemModified(vtkIdType itemID);
176 
177  virtual void onMRMLSceneImported(vtkMRMLScene* scene);
178  virtual void onMRMLSceneClosed(vtkMRMLScene* scene);
179  virtual void onMRMLSceneStartBatchProcess(vtkMRMLScene* scene);
180  virtual void onMRMLSceneEndBatchProcess(vtkMRMLScene* scene);
181  virtual void onMRMLNodeRemoved(vtkMRMLNode* node);
182 
183  virtual void onItemChanged(QStandardItem* item);
184  virtual void delayedItemChanged();
185 
188  void updateColumnCount();
189 
190 protected:
191  qMRMLSubjectHierarchyModel(qMRMLSubjectHierarchyModelPrivate* pimpl, QObject *parent=0);
192 
194  virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);
195 
196  virtual void updateFromSubjectHierarchy();
197  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID);
198  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID, QStandardItem* parent, int row=-1);
199 
200  virtual QFlags<Qt::ItemFlag> subjectHierarchyItemFlags(vtkIdType itemID, int column)const;
201 
202  virtual void updateItemFromSubjectHierarchyItem(
203  QStandardItem* item, vtkIdType shItemID, int column );
204  virtual void updateItemDataFromSubjectHierarchyItem(
205  QStandardItem* item, vtkIdType shItemID, int column );
206  virtual void updateSubjectHierarchyItemFromItem(
207  vtkIdType shItemID, QStandardItem* item );
208  virtual void updateSubjectHierarchyItemFromItemData(
209  vtkIdType shItemID, QStandardItem* item );
210 
212  void updateModelItems(vtkIdType itemID);
213 
214  static void onEvent(vtkObject* caller, unsigned long event, void* clientData, void* callData);
215 
217  virtual int maxColumnId()const;
218 
219 protected:
220  QScopedPointer<qMRMLSubjectHierarchyModelPrivate> d_ptr;
221 
222 private:
223  Q_DECLARE_PRIVATE(qMRMLSubjectHierarchyModel);
224  Q_DISABLE_COPY(qMRMLSubjectHierarchyModel);
225 };
226 
227 void printStandardItem(QStandardItem* item, const QString& offset);
228 
229 #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:54
Item model for subject hierarchy.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:138