Slicer  4.10
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
59  Q_PROPERTY(QString sceneModelType READ sceneModelType WRITE setSceneModelType)
65  Q_PROPERTY(qMRMLSceneModel::NodeTypes listenNodeModifiedEvent READ listenNodeModifiedEvent WRITE setListenNodeModifiedEvent)
75  Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
78  Q_PROPERTY(bool fitSizeToVisibleIndexes READ fitSizeToVisibleIndexes WRITE setFitSizeToVisibleIndexes)
84  Q_PROPERTY(QSize minSizeHint READ minSizeHint WRITE setMinSizeHint)
88  Q_PROPERTY(bool renameMenuActionVisible READ isRenameMenuActionVisible WRITE setRenameMenuActionVisible)
92  Q_PROPERTY(bool deleteMenuActionVisible READ isDeleteMenuActionVisible WRITE setDeleteMenuActionVisible)
96  Q_PROPERTY(bool editMenuActionVisible READ isEditMenuActionVisible WRITE setEditMenuActionVisible)
101  Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden)
107  Q_PROPERTY(bool showScene READ showScene WRITE setShowScene)
117  Q_PROPERTY(bool showRootNode READ showRootNode WRITE setShowRootNode)
118 
119 public:
120  typedef QTreeView Superclass;
121 
122  qMRMLTreeView(QWidget *parent=0);
123  virtual ~qMRMLTreeView();
124 
125  vtkMRMLScene* mrmlScene()const;
126 
130  vtkMRMLNode* currentNode()const;
131 
135  QString sceneModelType()const;
136 
139  void setListenNodeModifiedEvent(qMRMLSceneModel::NodeTypes listen);
142  qMRMLSceneModel::NodeTypes listenNodeModifiedEvent()const;
143 
145  void setSceneModel(qMRMLSceneModel* newSceneModel, const QString& modelType);
147  void setSortFilterProxyModel(qMRMLSortFilterProxyModel* newFilterModel);
148 
152  QStringList nodeTypes()const;
153  void setNodeTypes(const QStringList& nodeTypes);
154 
157  bool isRenameMenuActionVisible()const;
158  void setRenameMenuActionVisible(bool show);
159 
162  bool isDeleteMenuActionVisible()const;
163  void setDeleteMenuActionVisible(bool show);
164 
167  bool isEditMenuActionVisible()const;
168  void setEditMenuActionVisible(bool show);
169 
173  void appendNodeMenuAction(QAction* action);
174 
176  void prependNodeMenuAction(QAction* action);
177 
181  void appendSceneMenuAction(QAction* action);
182 
184  void prependSceneMenuAction(QAction* action);
185 
187  void removeNodeMenuAction(QAction* action);
188 
191  inline void setShowHidden(bool);
192  inline bool showHidden()const;
193 
196  void setShowRootNode(bool show);
199  bool showRootNode()const;
200 
203  void setShowScene(bool show);
206  bool showScene()const;
207 
210  vtkMRMLNode* rootNode()const;
211 
215  Q_INVOKABLE qMRMLSortFilterProxyModel* sortFilterProxyModel()const;
216  Q_INVOKABLE qMRMLSceneModel* sceneModel()const;
217 
220  void setFitSizeToVisibleIndexes(bool);
221  bool fitSizeToVisibleIndexes()const;
222 
223  void setMinSizeHint(QSize min);
224  QSize minSizeHint()const;
225 
228  static bool isAncestor(const QModelIndex& index, const QModelIndex& potentialAncestor);
229 
232  static QModelIndex findAncestor(const QModelIndex& index, const QModelIndexList& potentialAncestors);
233 
235  static QModelIndexList removeChildren(const QModelIndexList& indexes);
236 
237  virtual QSize minimumSizeHint()const;
238  virtual QSize sizeHint()const;
239 
240  virtual void showEvent(QShowEvent* show);
241  virtual bool eventFilter(QObject* object, QEvent* e);
242 
243  virtual bool clickDecoration(const QModelIndex& index);
244 
245  using QTreeView::scrollTo;
246 
247 public slots:
248  virtual void setMRMLScene(vtkMRMLScene* scene);
249 
252  void setSceneModelType(const QString& modelType);
253 
258  void setRootNode(vtkMRMLNode* root);
259 
262  void setCurrentNode(vtkMRMLNode* node);
263  void deleteCurrentNode();
264  void editCurrentNode();
265  void renameCurrentNode();
266 
269  inline void setShowAll(bool);
272  inline void setHideAll(bool);
275  inline void setDontHideAll(bool);
276 
284  void scrollTo(const QString& displayName);
290  void scrollToNext();
291 
292 signals:
293  void currentNodeChanged(vtkMRMLNode* node);
294  void currentNodeDeleted(const QModelIndex& index);
295  void currentNodeRenamed(const QString& newName);
296  void editNodeRequested(vtkMRMLNode* node);
297  void decorationClicked(const QModelIndex&);
298 
299 protected slots:
302  virtual void onSelectionChanged(const QItemSelection & selected,
303  const QItemSelection & deselected);
304 
305  void onNumberOfVisibleIndexChanged();
306 
307  void updateRootNode(vtkObject* modifiedRootNode);
308 
313  void saveTreeExpandState();
314 
317  void loadTreeExpandState();
318 
319 protected:
320  qMRMLTreeView(qMRMLTreeViewPrivate* pimpl, QWidget *parent=0);
321 
322 protected:
323  QScopedPointer<qMRMLTreeViewPrivate> d_ptr;
324 
325  // reimplemented for performance issues
326  virtual void updateGeometries();
327  virtual void mousePressEvent(QMouseEvent* event);
328  virtual void mouseReleaseEvent(QMouseEvent* event);
329  virtual void keyPressEvent(QKeyEvent* event);
330 
331  virtual void toggleVisibility(const QModelIndex& index);
332 
333 private:
334  Q_DECLARE_PRIVATE(qMRMLTreeView);
335  Q_DISABLE_COPY(qMRMLTreeView);
336 };
337 
338 // --------------------------------------------------------------------------
339 void qMRMLTreeView::setShowHidden(bool enable)
340 {
341  this->sortFilterProxyModel()->setShowHidden(enable);
342 }
343 
344 // --------------------------------------------------------------------------
345 bool qMRMLTreeView::showHidden()const
346 {
347  return this->sortFilterProxyModel()->showHidden();
348 }
349 
350 // --------------------------------------------------------------------------
352 {
353  this->sortFilterProxyModel()->setShowAll(show);
354 }
355 
356 // --------------------------------------------------------------------------
358 {
359  this->sortFilterProxyModel()->setHideAll(hide);
360 }
361 #include <QDebug>
362 // --------------------------------------------------------------------------
363 void qMRMLTreeView::setDontHideAll(bool dontHide)
364 {
365  qDebug() << "DontHide: " << dontHide;
366  this->setHideAll(!dontHide);
367 }
368 
369 #endif
void setShowAll(bool)
void setDontHideAll(bool)
QTreeView Superclass
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:54
void setHideAll(bool)
void setShowHidden(bool)
bool showHidden() const
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:138