Slicer  5.3
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 
81  Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
85  Q_PROPERTY(QString noneDisplay READ noneDisplay WRITE setNoneDisplay)
86 
87 public:
88  typedef QStandardItemModel Superclass;
89  qMRMLSubjectHierarchyModel(QObject *parent=nullptr);
90  ~qMRMLSubjectHierarchyModel() override;
91 
93  {
95  SubjectHierarchyItemIDRole = Qt::UserRole + 1,
102  LastRole
103  };
104 
105  int nameColumn()const;
106  void setNameColumn(int column);
107 
108  int visibilityColumn()const;
109  void setVisibilityColumn(int column);
110 
111  int colorColumn()const;
112  void setColorColumn(int column);
113 
114  int transformColumn()const;
115  void setTransformColumn(int column);
116 
117  int descriptionColumn()const;
118  void setDescriptionColumn(int column);
119 
120  int idColumn()const;
121  void setIDColumn(int column);
122 
123  bool noneEnabled()const;
124  void setNoneEnabled(bool enable);
125 
126  QString noneDisplay()const;
127  void setNoneDisplay(const QString& displayName);
128 
129  Qt::DropActions supportedDropActions()const override;
130  QMimeData* mimeData(const QModelIndexList& indexes)const override;
131  bool dropMimeData(const QMimeData *data, Qt::DropAction action,
132  int row, int column, const QModelIndex &parent) override;
133 
134  Q_INVOKABLE virtual void setMRMLScene(vtkMRMLScene* scene);
135  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
136 
137  vtkMRMLSubjectHierarchyNode* subjectHierarchyNode()const;
138 
140  QStandardItem* subjectHierarchySceneItem()const;
142  QModelIndex subjectHierarchySceneIndex()const;
143  virtual bool canBeAChild(vtkIdType itemID)const;
144  virtual bool canBeAParent(vtkIdType itemID)const;
145 
146  vtkIdType subjectHierarchyItemFromIndex(const QModelIndex &index)const;
147  vtkIdType subjectHierarchyItemFromItem(QStandardItem* item)const;
148  QModelIndex indexFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
149  QStandardItem* itemFromSubjectHierarchyItem(vtkIdType itemID, int column=0)const;
150 
152  QModelIndexList indexes(vtkIdType itemID)const;
153 
154  Q_INVOKABLE virtual vtkIdType parentSubjectHierarchyItem(vtkIdType itemID)const;
157  Q_INVOKABLE virtual int subjectHierarchyItemIndex(vtkIdType itemID)const;
159  Q_INVOKABLE virtual bool reparent(vtkIdType itemID, vtkIdType newParentID);
161  Q_INVOKABLE virtual bool moveToRow(vtkIdType itemID, int newRow);
164  Q_INVOKABLE bool isAncestorItem(vtkIdType child, vtkIdType ancestor)const;
167  Q_INVOKABLE bool isAffiliatedItem(vtkIdType itemA, vtkIdType itemB)const;
168 
169 signals:
171  void aboutToReparentByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
173  void reparentedByDragAndDrop(vtkIdType itemID, vtkIdType newParentID);
175  void subjectHierarchyAboutToBeUpdated();
177  void subjectHierarchyUpdated();
179  void requestExpandItem(vtkIdType itemID);
181  void requestCollapseItem(vtkIdType itemID);
183  void requestSelectItems(QList<vtkIdType> itemIDs);
185  void invalidateFilter();
186 
187 public slots:
189  void onRemoveTransformsFromBranchOfCurrentItem();
190 
192  void onHardenTransformOnBranchOfCurrentItem();
193 
194 protected slots:
195  virtual void onSubjectHierarchyItemAdded(vtkIdType itemID);
196  virtual void onSubjectHierarchyItemAboutToBeRemoved(vtkIdType itemID);
197  virtual void onSubjectHierarchyItemRemoved(vtkIdType itemID);
198  virtual void onSubjectHierarchyItemModified(vtkIdType itemID);
199 
200  virtual void onMRMLSceneImported(vtkMRMLScene* scene);
201  virtual void onMRMLSceneClosed(vtkMRMLScene* scene);
202  virtual void onMRMLSceneStartBatchProcess(vtkMRMLScene* scene);
203  virtual void onMRMLSceneEndBatchProcess(vtkMRMLScene* scene);
204  virtual void onMRMLNodeRemoved(vtkMRMLNode* node);
205 
206  virtual void onItemChanged(QStandardItem* item);
207  virtual void delayedItemChanged();
208 
211  void updateColumnCount();
212 
213 protected:
214  qMRMLSubjectHierarchyModel(qMRMLSubjectHierarchyModelPrivate* pimpl, QObject *parent=nullptr);
215 
217  virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);
218 
220  virtual void rebuildFromSubjectHierarchy();
221 
222  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID);
223  virtual QStandardItem* insertSubjectHierarchyItem(vtkIdType itemID, QStandardItem* parent, int row=-1);
224 
225  virtual QFlags<Qt::ItemFlag> subjectHierarchyItemFlags(vtkIdType itemID, int column)const;
226 
227  virtual void updateItemFromSubjectHierarchyItem(
228  QStandardItem* item, vtkIdType shItemID, int column );
229  virtual void updateItemDataFromSubjectHierarchyItem(
230  QStandardItem* item, vtkIdType shItemID, int column );
231  virtual void updateSubjectHierarchyItemFromItem(
232  vtkIdType shItemID, QStandardItem* item );
233  virtual void updateSubjectHierarchyItemFromItemData(
234  vtkIdType shItemID, QStandardItem* item );
235 
237  void updateModelItems(vtkIdType itemID);
238 
239  static void onEvent(vtkObject* caller, unsigned long event, void* clientData, void* callData);
240 
242  virtual int maxColumnId()const;
243 
244 protected:
245  QScopedPointer<qMRMLSubjectHierarchyModelPrivate> d_ptr;
246 
247 private:
248  Q_DECLARE_PRIVATE(qMRMLSubjectHierarchyModel);
249  Q_DISABLE_COPY(qMRMLSubjectHierarchyModel);
250 };
251 
252 void printStandardItem(QStandardItem* item, const QString& offset);
253 
254 #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:57
Item model for subject hierarchy.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167