Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLSubjectHierarchyTreeView.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 __qMRMLSubjectHierarchyTreeView_h
24 #define __qMRMLSubjectHierarchyTreeView_h
25 
26 // Qt includes
27 #include <QTreeView>
28 
29 // CTK includes
30 #include <ctkVTKObject.h>
31 
32 // SubjectHierarchy includes
33 #include "qSlicerSubjectHierarchyModuleWidgetsExport.h"
34 
35 class qMRMLSubjectHierarchyTreeViewPrivate;
38 class vtkMRMLNode;
39 class vtkMRMLScene;
41 class vtkIdList;
42 
44 class Q_SLICER_MODULE_SUBJECTHIERARCHY_WIDGETS_EXPORT qMRMLSubjectHierarchyTreeView : public QTreeView
45 {
46  Q_OBJECT
47  QVTK_OBJECT
48 
53  Q_PROPERTY(bool showRootItem READ showRootItem WRITE setShowRootItem)
57  Q_PROPERTY(bool highlightReferencedItems READ highlightReferencedItems WRITE setHighlightReferencedItems)
59  Q_PROPERTY(bool contextMenuEnabled READ contextMenuEnabled WRITE setContextMenuEnabled)
61  Q_PROPERTY(bool editMenuActionVisible READ editMenuActionVisible WRITE setEditMenuActionVisible)
63  Q_PROPERTY(bool selectRoleSubMenuVisible READ selectRoleSubMenuVisible WRITE setSelectRoleSubMenuVisible)
65  Q_PROPERTY(bool multiSelection READ multiSelection WRITE setMultiSelection)
66  Q_PROPERTY(QStringList levelFilter READ levelFilter WRITE setLevelFilter)
67  Q_PROPERTY(QString nameFilter READ nameFilter WRITE setNameFilter)
68  Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
69  Q_PROPERTY(QStringList hideChildNodeTypes READ hideChildNodeTypes WRITE setHideChildNodeTypes)
70  Q_PROPERTY(bool visibilityColumnVisible READ visibilityColumnVisible WRITE setVisibilityColumnVisible)
71  Q_PROPERTY(bool idColumnVisible READ idColumnVisible WRITE setIdColumnVisible)
72  Q_PROPERTY(bool colorColumnVisible READ colorColumnVisible WRITE setColorColumnVisible)
73  Q_PROPERTY(bool transformColumnVisible READ transformColumnVisible WRITE setTransformColumnVisible)
74  Q_PROPERTY(bool descriptionColumnVisible READ descriptionColumnVisible WRITE setDescriptionColumnVisible)
75 
77  Q_PROPERTY(QStringList includeItemAttributeNamesFilter READ includeItemAttributeNamesFilter WRITE setIncludeItemAttributeNamesFilter)
79  Q_PROPERTY(QStringList includeNodeAttributeNamesFilter READ includeNodeAttributeNamesFilter WRITE setIncludeNodeAttributeNamesFilter)
82  Q_PROPERTY(QStringList excludeItemAttributeNamesFilter READ excludeItemAttributeNamesFilter WRITE setExcludeItemAttributeNamesFilter)
85  Q_PROPERTY(QStringList excludeNodeAttributeNamesFilter READ excludeNodeAttributeNamesFilter WRITE setExcludeNodeAttributeNamesFilter)
86 
89  Q_PROPERTY(QString attributeNameFilter READ attributeNameFilter WRITE setAttributeNameFilter)
94  Q_PROPERTY(QString attributeValueFilter READ attributeValueFilter WRITE setAttributeValueFilter)
95 
96 public:
97  typedef QTreeView Superclass;
98  qMRMLSubjectHierarchyTreeView(QWidget *parent=nullptr);
100 
101 public:
102  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
103  Q_INVOKABLE vtkMRMLSubjectHierarchyNode* subjectHierarchyNode()const;
104 
106  Q_INVOKABLE vtkIdType currentItem()const;
108  QList<vtkIdType> currentItems();
111  Q_INVOKABLE void currentItems(vtkIdList* selectedItems);
112 
114  virtual vtkMRMLNode* currentNode()const;
115 
117  Q_INVOKABLE vtkIdType rootItem()const;
119  bool showRootItem()const;
120 
122  bool multiSelection();
123 
124  QStringList includeItemAttributeNamesFilter()const;
125  QStringList includeNodeAttributeNamesFilter()const;
126  QStringList excludeItemAttributeNamesFilter()const;
127  QStringList excludeNodeAttributeNamesFilter()const;
128  QString attributeValueFilter()const;
129  QString attributeNameFilter()const;
134  Q_INVOKABLE void setAttributeFilter(const QString& attributeName, const QVariant& attributeValue=QVariant());
136  Q_INVOKABLE void removeAttributeFilter();
144  Q_INVOKABLE void addItemAttributeFilter(QString attributeName, QVariant attributeValue=QString(), bool include=true);
146  Q_INVOKABLE void removeItemAttributeFilter(QString attributeName, QVariant attributeValue, bool include);
148  Q_INVOKABLE void removeItemAttributeFilter(QString attributeName, bool include);
157  Q_INVOKABLE void addNodeAttributeFilter(QString attributeName, QVariant attributeValue=QString(), bool include=true, QString className=QString());
159  Q_INVOKABLE void removeNodeAttributeFilter(QString attributeName, QVariant attributeValue, bool include, QString className);
161  Q_INVOKABLE void removeNodeAttributeFilter(QString attributeName, bool include);
162 
163 
165  void setLevelFilter(QStringList &levelFilter);
166  QStringList levelFilter()const;
167 
169  void setNameFilter(QString &nameFilter);
170  QString nameFilter()const;
171 
173  void setNodeTypes(const QStringList& types);
174  QStringList nodeTypes()const;
175 
178  void setHideChildNodeTypes(const QStringList& types);
179  QStringList hideChildNodeTypes()const;
180 
181  Q_INVOKABLE qMRMLSortFilterSubjectHierarchyProxyModel* sortFilterProxyModel()const;
182  Q_INVOKABLE qMRMLSubjectHierarchyModel* model()const;
183 
185  Q_INVOKABLE int displayedItemCount()const;
186 
187  bool highlightReferencedItems()const;
188  bool contextMenuEnabled()const;
189  bool editMenuActionVisible()const;
190  bool selectRoleSubMenuVisible()const;
191 
193  void setVisibilityColumnVisible(bool visible);
194  bool visibilityColumnVisible();
196  void setIdColumnVisible(bool visible);
197  bool idColumnVisible();
199  void setColorColumnVisible(bool visible);
200  bool colorColumnVisible();
202  void setTransformColumnVisible(bool visible);
203  bool transformColumnVisible();
205  void setDescriptionColumnVisible(bool visible);
206  bool descriptionColumnVisible();
207 
208 public slots:
210  virtual void setMRMLScene(vtkMRMLScene* scene);
211 
213  virtual void setCurrentItem(vtkIdType itemID);
215  virtual void setCurrentItems(QList<vtkIdType> items);
217  virtual void setCurrentItems(vtkIdList* items);
219  virtual void setCurrentNode(vtkMRMLNode* node);
220 
222  virtual void setRootItem(vtkIdType itemID);
224  void setShowRootItem(bool show);
225 
227  void renameCurrentItem();
229  void deleteSelectedItems();
231  void toggleVisibilityOfSelectedItems();
233  virtual void editCurrentItem();
234 
236  virtual void expandItem(vtkIdType itemID);
238  virtual void collapseItem(vtkIdType itemID);
239 
241  virtual void selectPluginForCurrentItem();
242 
247  virtual void updateSelectPluginActions();
248 
250  virtual void setMultiSelection(bool multiSelectionOn);
251 
255  void setPluginWhitelist(QStringList whitelist);
259  void setPluginBlacklist(QStringList blacklist);
262  void disablePlugin(QString plugin);
263 
267  bool showContextMenuHint(bool visibility=false);
268 
269  void setHighlightReferencedItems(bool highlightOn);
270  void setContextMenuEnabled(bool enabled);
271  void setEditMenuActionVisible(bool visible);
272  void setSelectRoleSubMenuVisible(bool visible);
273 
275  void resetColumnSizesToDefault();
276 
277 signals:
278  void currentItemChanged(vtkIdType);
279  void currentItemsChanged(QList<vtkIdType>);
280  void currentItemModified(vtkIdType);
281 
282 protected slots:
283  virtual void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
284 
286  virtual void onItemExpanded(const QModelIndex &expandedItemIndex);
288  virtual void onItemCollapsed(const QModelIndex &collapsedItemIndex);
289 
291  virtual void expandToDepthFromContextMenu();
292 
295  virtual void updateRootItem();
296 
298  virtual void onSubjectHierarchyItemModified(vtkObject *caller, void *callData);
300  virtual void onSubjectHierarchyItemTransformModified(vtkObject *caller, void *callData);
301 
303  virtual void onMRMLSceneCloseEnded(vtkObject* sceneObject);
305  virtual void onMRMLSceneStartBatchProcess(vtkObject* sceneObject);
307  virtual void onMRMLSceneEndBatchProcess(vtkObject* sceneObject);
308 
309  void onCustomContextMenu(const QPoint& point);
310 
311  virtual void onTransformActionSelected();
312  virtual void onTransformInteractionInViewToggled(bool show);
313  virtual void onTransformEditProperties();
314  virtual void onCreateNewTransform();
315 
316  void setIncludeItemAttributeNamesFilter(QStringList filter);
317  void setIncludeNodeAttributeNamesFilter(QStringList filter);
318  void setExcludeItemAttributeNamesFilter(QStringList filter);
319  void setExcludeNodeAttributeNamesFilter(QStringList filter);
320  void setAttributeNameFilter(QString& filter);
321  void setAttributeValueFilter(QString& filter);
322 
323 protected:
325  virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);
326 
328  void toggleSubjectHierarchyItemVisibility(vtkIdType itemID);
329 
334  virtual void populateContextMenuForItem(vtkIdType itemID);
336  virtual void populateVisibilityContextMenuForItem(vtkIdType itemID);
338  virtual void populateTransformContextMenuForItem(vtkIdType itemID);
339 
343  virtual bool clickDecoration(QMouseEvent* e);
345  void mousePressEvent(QMouseEvent* e) override;
347  void keyPressEvent(QKeyEvent* e) override;
348 
351  void applyReferenceHighlightForItems(QList<vtkIdType> itemIDs);
352 
355  vtkIdType firstSelectedSubjectHierarchyItemInBranch(vtkIdType itemID);
356 
357  void changeEvent(QEvent* e) override;
358 
359 protected:
360  QScopedPointer<qMRMLSubjectHierarchyTreeViewPrivate> d_ptr;
361 
362 private:
363  Q_DECLARE_PRIVATE(qMRMLSubjectHierarchyTreeView);
364  Q_DISABLE_COPY(qMRMLSubjectHierarchyTreeView);
366 };
367 
368 #endif
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