Slicer  5.2
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLTreeView.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Program: 3D Slicer
4 
5  Copyright (c) Kitware Inc.
6 
7  See COPYRIGHT.txt
8  or http://www.slicer.org/copyright/copyright.txt for details.
9 
10  Unless required by applicable law or agreed to in writing, software
11  distributed under the License is distributed on an "AS IS" BASIS,
12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  See the License for the specific language governing permissions and
14  limitations under the License.
15 
16  This file was originally developed by Julien Finet, Kitware Inc.
17  and was partially funded by NIH grant 3P41RR013218-12S1
18 
19 ==============================================================================*/
20 
21 #ifndef __qMRMLTreeView_h
22 #define __qMRMLTreeView_h
23 
24 // Qt includes
25 #include <QTreeView>
26 //#include <QStyledItemDelegate>
27 class QShowEvent;
28 
29 // CTK includes
30 #include <ctkVTKObject.h>
31 
32 // MRMLWidgets includes
33 #include "qMRMLSceneModel.h"
35 #include "qMRMLWidgetsExport.h"
36 
37 class qMRMLTreeViewPrivate;
38 class vtkMRMLNode;
39 class vtkMRMLScene;
40 
45 class QMRML_WIDGETS_EXPORT qMRMLTreeView : public QTreeView
46 {
47  Q_OBJECT
48  QVTK_OBJECT
58  Q_PROPERTY(QString sceneModelType READ sceneModelType WRITE setSceneModelType)
64  Q_PROPERTY(qMRMLSceneModel::NodeTypes listenNodeModifiedEvent READ listenNodeModifiedEvent WRITE setListenNodeModifiedEvent)
74  Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
77  Q_PROPERTY(bool fitSizeToVisibleIndexes READ fitSizeToVisibleIndexes WRITE setFitSizeToVisibleIndexes)
83  Q_PROPERTY(QSize minSizeHint READ minSizeHint WRITE setMinSizeHint)
87  Q_PROPERTY(bool renameMenuActionVisible READ isRenameMenuActionVisible WRITE setRenameMenuActionVisible)
91  Q_PROPERTY(bool deleteMenuActionVisible READ isDeleteMenuActionVisible WRITE setDeleteMenuActionVisible)
95  Q_PROPERTY(bool editMenuActionVisible READ isEditMenuActionVisible WRITE setEditMenuActionVisible)
100  Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden)
106  Q_PROPERTY(bool showScene READ showScene WRITE setShowScene)
116  Q_PROPERTY(bool showRootNode READ showRootNode WRITE setShowRootNode)
117 
118 public:
119  typedef QTreeView Superclass;
120 
121  qMRMLTreeView(QWidget *parent=nullptr);
122  ~qMRMLTreeView() override;
123 
124  vtkMRMLScene* mrmlScene()const;
125 
129  vtkMRMLNode* currentNode()const;
130 
134  QString sceneModelType()const;
135 
138  void setListenNodeModifiedEvent(qMRMLSceneModel::NodeTypes listen);
141  qMRMLSceneModel::NodeTypes listenNodeModifiedEvent()const;
142 
144  void setSceneModel(qMRMLSceneModel* newSceneModel, const QString& modelType);
146  void setSortFilterProxyModel(qMRMLSortFilterProxyModel* newFilterModel);
147 
151  QStringList nodeTypes()const;
152  void setNodeTypes(const QStringList& nodeTypes);
153 
156  bool isRenameMenuActionVisible()const;
157  void setRenameMenuActionVisible(bool show);
158 
161  bool isDeleteMenuActionVisible()const;
162  void setDeleteMenuActionVisible(bool show);
163 
166  bool isEditMenuActionVisible()const;
167  void setEditMenuActionVisible(bool show);
168 
172  void appendNodeMenuAction(QAction* action);
173 
175  void prependNodeMenuAction(QAction* action);
176 
180  void appendSceneMenuAction(QAction* action);
181 
183  void prependSceneMenuAction(QAction* action);
184 
186  void removeNodeMenuAction(QAction* action);
187 
190  inline void setShowHidden(bool);
191  inline bool showHidden()const;
192 
195  void setShowRootNode(bool show);
198  bool showRootNode()const;
199 
202  void setShowScene(bool show);
205  bool showScene()const;
206 
209  vtkMRMLNode* rootNode()const;
210 
214  Q_INVOKABLE qMRMLSortFilterProxyModel* sortFilterProxyModel()const;
215  Q_INVOKABLE qMRMLSceneModel* sceneModel()const;
216 
219  void setFitSizeToVisibleIndexes(bool);
220  bool fitSizeToVisibleIndexes()const;
221 
222  void setMinSizeHint(QSize min);
223  QSize minSizeHint()const;
224 
227  static bool isAncestor(const QModelIndex& index, const QModelIndex& potentialAncestor);
228 
231  static QModelIndex findAncestor(const QModelIndex& index, const QModelIndexList& potentialAncestors);
232 
234  static QModelIndexList removeChildren(const QModelIndexList& indexes);
235 
236  QSize minimumSizeHint()const override;
237  QSize sizeHint()const override;
238 
239  void showEvent(QShowEvent* show) override;
240  bool eventFilter(QObject* object, QEvent* e) override;
241 
242  virtual bool clickDecoration(const QModelIndex& index);
243 
244  using QTreeView::scrollTo;
245 
246 public slots:
247  virtual void setMRMLScene(vtkMRMLScene* scene);
248 
251  void setSceneModelType(const QString& modelType);
252 
257  void setRootNode(vtkMRMLNode* root);
258 
261  void setCurrentNode(vtkMRMLNode* node);
262  void deleteCurrentNode();
263  void editCurrentNode();
264  void renameCurrentNode();
265 
268  inline void setShowAll(bool);
271  inline void setHideAll(bool);
274  inline void setDontHideAll(bool);
275 
283  void scrollTo(const QString& displayName);
289  void scrollToNext();
290 
291 signals:
292  void currentNodeChanged(vtkMRMLNode* node);
293  void currentNodeDeleted(const QModelIndex& index);
294  void currentNodeRenamed(const QString& newName);
295  void editNodeRequested(vtkMRMLNode* node);
296  void decorationClicked(const QModelIndex&);
297 
298 protected slots:
301  virtual void onSelectionChanged(const QItemSelection & selected,
302  const QItemSelection & deselected);
303 
304  void onNumberOfVisibleIndexChanged();
305 
306  void updateRootNode(vtkObject* modifiedRootNode);
307 
312  void saveTreeExpandState();
313 
316  void loadTreeExpandState();
317 
318  void onCustomContextMenu(const QPoint& point);
319 
320 protected:
321  qMRMLTreeView(qMRMLTreeViewPrivate* pimpl, QWidget *parent=nullptr);
322 
323 protected:
324  QScopedPointer<qMRMLTreeViewPrivate> d_ptr;
325 
326  // reimplemented for performance issues
327  void updateGeometries() override;
328  void mousePressEvent(QMouseEvent* event) override;
329  void mouseReleaseEvent(QMouseEvent* event) override;
330  void keyPressEvent(QKeyEvent* event) override;
331 
332  virtual void toggleVisibility(const QModelIndex& index);
333 
334 private:
335  Q_DECLARE_PRIVATE(qMRMLTreeView);
336  Q_DISABLE_COPY(qMRMLTreeView);
337 };
338 
339 // --------------------------------------------------------------------------
340 void qMRMLTreeView::setShowHidden(bool enable)
341 {
342  this->sortFilterProxyModel()->setShowHidden(enable);
343 }
344 
345 // --------------------------------------------------------------------------
346 bool qMRMLTreeView::showHidden()const
347 {
348  return this->sortFilterProxyModel()->showHidden();
349 }
350 
351 // --------------------------------------------------------------------------
353 {
354  this->sortFilterProxyModel()->setShowAll(show);
355 }
356 
357 // --------------------------------------------------------------------------
359 {
360  this->sortFilterProxyModel()->setHideAll(hide);
361 }
362 #include <QDebug>
363 // --------------------------------------------------------------------------
364 void qMRMLTreeView::setDontHideAll(bool dontHide)
365 {
366  qDebug() << "DontHide: " << dontHide;
367  this->setHideAll(!dontHide);
368 }
369 
370 #endif
void setShowAll(bool)
void setDontHideAll(bool)
QTreeView Superclass
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
void setHideAll(bool)
void setShowHidden(bool)
bool showHidden() const
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167