Slicer  5.0
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 
78  Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
82  Q_PROPERTY(QString noneDisplay READ noneDisplay WRITE setNoneDisplay)
83 
85  Q_PROPERTY(QStringList includeItemAttributeNamesFilter READ includeItemAttributeNamesFilter WRITE setIncludeItemAttributeNamesFilter)
87  Q_PROPERTY(QStringList includeNodeAttributeNamesFilter READ includeNodeAttributeNamesFilter WRITE setIncludeNodeAttributeNamesFilter)
90  Q_PROPERTY(QStringList excludeItemAttributeNamesFilter READ excludeItemAttributeNamesFilter WRITE setExcludeItemAttributeNamesFilter)
93  Q_PROPERTY(QStringList excludeNodeAttributeNamesFilter READ excludeNodeAttributeNamesFilter WRITE setExcludeNodeAttributeNamesFilter)
94 
97  Q_PROPERTY(QString attributeNameFilter READ attributeNameFilter WRITE setAttributeNameFilter)
102  Q_PROPERTY(QString attributeValueFilter READ attributeValueFilter WRITE setAttributeValueFilter)
103 
104 public:
105  typedef QTreeView Superclass;
106  qMRMLSubjectHierarchyTreeView(QWidget *parent=nullptr);
107  ~qMRMLSubjectHierarchyTreeView() override;
108 
109 public:
110  Q_INVOKABLE vtkMRMLScene* mrmlScene()const;
111  Q_INVOKABLE vtkMRMLSubjectHierarchyNode* subjectHierarchyNode()const;
112 
114  Q_INVOKABLE vtkIdType currentItem()const;
116  QList<vtkIdType> currentItems();
119  Q_INVOKABLE void currentItems(vtkIdList* selectedItems);
120 
122  virtual vtkMRMLNode* currentNode()const;
123 
125  Q_INVOKABLE vtkIdType rootItem()const;
127  bool showRootItem()const;
128 
130  bool multiSelection();
131 
132  QStringList includeItemAttributeNamesFilter()const;
133  QStringList includeNodeAttributeNamesFilter()const;
134  QStringList excludeItemAttributeNamesFilter()const;
135  QStringList excludeNodeAttributeNamesFilter()const;
136  QString attributeValueFilter()const;
137  QString attributeNameFilter()const;
142  Q_INVOKABLE void setAttributeFilter(const QString& attributeName, const QVariant& attributeValue=QVariant());
144  Q_INVOKABLE void removeAttributeFilter();
152  Q_INVOKABLE void addItemAttributeFilter(QString attributeName, QVariant attributeValue=QString(), bool include=true);
154  Q_INVOKABLE void removeItemAttributeFilter(QString attributeName, QVariant attributeValue, bool include);
156  Q_INVOKABLE void removeItemAttributeFilter(QString attributeName, bool include);
165  Q_INVOKABLE void addNodeAttributeFilter(QString attributeName, QVariant attributeValue=QString(), bool include=true, QString className=QString());
167  Q_INVOKABLE void removeNodeAttributeFilter(QString attributeName, QVariant attributeValue, bool include, QString className);
169  Q_INVOKABLE void removeNodeAttributeFilter(QString attributeName, bool include);
170 
171 
173  void setLevelFilter(QStringList &levelFilter);
174  QStringList levelFilter()const;
175 
177  void setNameFilter(QString &nameFilter);
178  QString nameFilter()const;
179 
181  void setNodeTypes(const QStringList& types);
182  QStringList nodeTypes()const;
183 
186  void setHideChildNodeTypes(const QStringList& types);
187  QStringList hideChildNodeTypes()const;
188 
189  Q_INVOKABLE qMRMLSortFilterSubjectHierarchyProxyModel* sortFilterProxyModel()const;
190  Q_INVOKABLE qMRMLSubjectHierarchyModel* model()const;
191 
193  Q_INVOKABLE int displayedItemCount()const;
194 
195  bool highlightReferencedItems()const;
196  bool contextMenuEnabled()const;
197  bool editMenuActionVisible()const;
198  bool selectRoleSubMenuVisible()const;
199  bool noneEnabled()const;
200  QString noneDisplay()const;
201 
203  void setVisibilityColumnVisible(bool visible);
204  bool visibilityColumnVisible();
206  void setIdColumnVisible(bool visible);
207  bool idColumnVisible();
209  void setColorColumnVisible(bool visible);
210  bool colorColumnVisible();
212  void setTransformColumnVisible(bool visible);
213  bool transformColumnVisible();
215  void setDescriptionColumnVisible(bool visible);
216  bool descriptionColumnVisible();
217 
218 public slots:
220  virtual void setMRMLScene(vtkMRMLScene* scene);
221 
223  virtual void setCurrentItem(vtkIdType itemID);
225  virtual void setCurrentItems(QList<vtkIdType> items);
227  virtual void setCurrentItems(vtkIdList* items);
229  virtual void setCurrentNode(vtkMRMLNode* node);
230 
232  virtual void setRootItem(vtkIdType itemID);
234  void setShowRootItem(bool show);
235 
237  void renameCurrentItem();
239  void deleteSelectedItems();
241  void toggleVisibilityOfSelectedItems();
243  virtual void editCurrentItem();
244 
246  virtual void expandItem(vtkIdType itemID);
248  virtual void collapseItem(vtkIdType itemID);
249 
251  virtual void selectPluginForCurrentItem();
252 
257  virtual void updateSelectPluginActions();
258 
260  virtual void setMultiSelection(bool multiSelectionOn);
261 
265  void setPluginWhitelist(QStringList whitelist);
269  void setPluginBlacklist(QStringList blacklist);
272  void disablePlugin(QString plugin);
273 
277  bool showContextMenuHint(bool visibility=false);
278 
279  void setHighlightReferencedItems(bool highlightOn);
280  void setContextMenuEnabled(bool enabled);
281  void setEditMenuActionVisible(bool visible);
282  void setSelectRoleSubMenuVisible(bool visible);
283  void setNoneEnabled(bool enable);
284  void setNoneDisplay(const QString& displayName);
285 
287  void resetColumnSizesToDefault();
288 
289  void setIncludeItemAttributeNamesFilter(QStringList filter);
290  void setIncludeNodeAttributeNamesFilter(QStringList filter);
291  void setExcludeItemAttributeNamesFilter(QStringList filter);
292  void setExcludeNodeAttributeNamesFilter(QStringList filter);
293  void setAttributeNameFilter(QString& filter);
294  void setAttributeValueFilter(QString& filter);
295 
296 signals:
297  void currentItemChanged(vtkIdType);
298  void currentItemsChanged(QList<vtkIdType>);
299  void currentItemModified(vtkIdType);
300 
301 protected slots:
302  virtual void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
303  virtual void onCurrentSelection(const QModelIndex &currentItemIndex);
304 
306  virtual void onItemExpanded(const QModelIndex &expandedItemIndex);
308  virtual void onItemCollapsed(const QModelIndex &collapsedItemIndex);
309 
311  virtual void expandToDepthFromContextMenu();
312 
315  virtual void updateRootItem();
316 
318  virtual void onSubjectHierarchyItemModified(vtkObject *caller, void *callData);
320  virtual void onSubjectHierarchyItemTransformModified(vtkObject *caller, void *callData);
321 
323  virtual void onMRMLSceneStartClose(vtkObject* sceneObject);
325  virtual void onMRMLSceneEndClose(vtkObject* sceneObject);
327  virtual void onMRMLSceneStartBatchProcess(vtkObject* sceneObject);
329  virtual void onMRMLSceneEndBatchProcess(vtkObject* sceneObject);
330 
331  void onCustomContextMenu(const QPoint& point);
332 
333  virtual void onTransformActionSelected();
334  virtual void onTransformInteractionInViewToggled(bool show);
335  virtual void onTransformEditProperties();
336  virtual void onCreateNewTransform();
337 
338 protected:
340  virtual void setSubjectHierarchyNode(vtkMRMLSubjectHierarchyNode* shNode);
341 
343  void toggleSubjectHierarchyItemVisibility(vtkIdType itemID);
344 
349  virtual void populateContextMenuForItem(vtkIdType itemID);
351  virtual void populateVisibilityContextMenuForItem(vtkIdType itemID);
353  virtual void populateTransformContextMenuForItem(vtkIdType itemID);
354 
358  virtual bool clickDecoration(QMouseEvent* e);
360  void mousePressEvent(QMouseEvent* e) override;
362  void keyPressEvent(QKeyEvent* e) override;
363 
366  void applyReferenceHighlightForItems(QList<vtkIdType> itemIDs);
367 
370  vtkIdType firstSelectedSubjectHierarchyItemInBranch(vtkIdType itemID);
371 
372  void changeEvent(QEvent* e) override;
373 
374 protected:
375  QScopedPointer<qMRMLSubjectHierarchyTreeViewPrivate> d_ptr;
376 
377 private:
378  Q_DECLARE_PRIVATE(qMRMLSubjectHierarchyTreeView);
379  Q_DISABLE_COPY(qMRMLSubjectHierarchyTreeView);
381 };
382 
383 #endif
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