Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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>
27class QShowEvent;
28
29// CTK includes
30#include <ctkVTKObject.h>
31
32// MRMLWidgets includes
33#include "qMRMLSceneModel.h"
35#include "qMRMLWidgetsExport.h"
36
37class qMRMLTreeViewPrivate;
38class vtkMRMLNode;
39class vtkMRMLScene;
40
45class QMRML_WIDGETS_EXPORT qMRMLTreeView : public QTreeView
46{
47 Q_OBJECT
48 QVTK_OBJECT
58 Q_PROPERTY(QString sceneModelType READ sceneModelType WRITE setSceneModelType)
74 Q_PROPERTY(QStringList nodeTypes READ nodeTypes WRITE setNodeTypes)
83 Q_PROPERTY(QSize minSizeHint READ minSizeHint WRITE setMinSizeHint)
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
118public:
119 typedef QTreeView Superclass;
120
121 qMRMLTreeView(QWidget *parent=nullptr);
122 ~qMRMLTreeView() override;
123
125
130
134 QString sceneModelType()const;
135
142
144 void setSceneModel(qMRMLSceneModel* newSceneModel, const QString& modelType);
147
151 QStringList nodeTypes()const;
152 void setNodeTypes(const QStringList& nodeTypes);
153
158
163
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
210
215 Q_INVOKABLE qMRMLSceneModel* sceneModel()const;
216
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
246public slots:
247 virtual void setMRMLScene(vtkMRMLScene* scene);
248
251 void setSceneModelType(const QString& modelType);
252
258
265
268 inline void setShowAll(bool);
271 inline void setHideAll(bool);
274 inline void setDontHideAll(bool);
275
283 void scrollTo(const QString& displayName);
290
291signals:
293 void currentNodeDeleted(const QModelIndex& index);
294 void currentNodeRenamed(const QString& newName);
296 void decorationClicked(const QModelIndex&);
297
298protected slots:
301 virtual void onSelectionChanged(const QItemSelection & selected,
302 const QItemSelection & deselected);
303
305
306 void updateRootNode(vtkObject* modifiedRootNode);
307
313
317
318 void onCustomContextMenu(const QPoint& point);
319
320protected:
321 qMRMLTreeView(qMRMLTreeViewPrivate* pimpl, QWidget *parent=nullptr);
322
323protected:
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
334private:
335 Q_DECLARE_PRIVATE(qMRMLTreeView);
336 Q_DISABLE_COPY(qMRMLTreeView);
337};
338
339// --------------------------------------------------------------------------
340void qMRMLTreeView::setShowHidden(bool enable)
341{
342 this->sortFilterProxyModel()->setShowHidden(enable);
343}
344
345// --------------------------------------------------------------------------
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// --------------------------------------------------------------------------
365{
366 qDebug() << "DontHide: " << dontHide;
367 this->setHideAll(!dontHide);
368}
369
370#endif
bool isEditMenuActionVisible() const
void onCustomContextMenu(const QPoint &point)
void decorationClicked(const QModelIndex &)
bool renameMenuActionVisible
void currentNodeChanged(vtkMRMLNode *node)
void currentNodeRenamed(const QString &newName)
void setShowHidden(bool)
void setListenNodeModifiedEvent(qMRMLSceneModel::NodeTypes listen)
void showEvent(QShowEvent *show) override
void currentNodeDeleted(const QModelIndex &index)
vtkMRMLNode * rootNode() const
bool editMenuActionVisible
void scrollToNext()
void mousePressEvent(QMouseEvent *event) override
void onNumberOfVisibleIndexChanged()
QSize sizeHint() const override
bool eventFilter(QObject *object, QEvent *e) override
bool fitSizeToVisibleIndexes
static QModelIndex findAncestor(const QModelIndex &index, const QModelIndexList &potentialAncestors)
void setCurrentNode(vtkMRMLNode *node)
void deleteCurrentNode()
void prependSceneMenuAction(QAction *action)
QSize minimumSizeHint() const override
void renameCurrentNode()
void setHideAll(bool)
virtual void toggleVisibility(const QModelIndex &index)
void keyPressEvent(QKeyEvent *event) override
bool isRenameMenuActionVisible() const
QStringList nodeTypes
void setFitSizeToVisibleIndexes(bool)
void mouseReleaseEvent(QMouseEvent *event) override
static bool isAncestor(const QModelIndex &index, const QModelIndex &potentialAncestor)
void editNodeRequested(vtkMRMLNode *node)
QVTK_OBJECTQString sceneModelType
void editCurrentNode()
void loadTreeExpandState()
void setMinSizeHint(QSize min)
void setSceneModelType(const QString &modelType)
void appendSceneMenuAction(QAction *action)
void removeNodeMenuAction(QAction *action)
Remove action from the "NodeMenu".
bool deleteMenuActionVisible
virtual bool clickDecoration(const QModelIndex &index)
vtkMRMLNode * currentNode() const
void setShowRootNode(bool show)
void setEditMenuActionVisible(bool show)
void setSortFilterProxyModel(qMRMLSortFilterProxyModel *newFilterModel)
Customize the filter model.
static QModelIndexList removeChildren(const QModelIndexList &indexes)
Remove indexes that have at least one ancestor in the list.
qMRMLSceneModel::NodeTypes listenNodeModifiedEvent
void setDeleteMenuActionVisible(bool show)
void saveTreeExpandState()
Q_INVOKABLE qMRMLSortFilterProxyModel * sortFilterProxyModel() const
virtual void setMRMLScene(vtkMRMLScene *scene)
void setShowAll(bool)
void setShowScene(bool show)
vtkMRMLScene * mrmlScene() const
void setDontHideAll(bool)
bool isDeleteMenuActionVisible() const
qMRMLTreeView(QWidget *parent=nullptr)
void setSceneModel(qMRMLSceneModel *newSceneModel, const QString &modelType)
Customize the model.
void setRenameMenuActionVisible(bool show)
void setNodeTypes(const QStringList &nodeTypes)
void appendNodeMenuAction(QAction *action)
void prependNodeMenuAction(QAction *action)
void updateRootNode(vtkObject *modifiedRootNode)
void setRootNode(vtkMRMLNode *root)
Q_INVOKABLE qMRMLSceneModel * sceneModel() const
QScopedPointer< qMRMLTreeViewPrivate > d_ptr
void updateGeometries() override
void scrollTo(const QString &displayName)
QTreeView Superclass
virtual void onSelectionChanged(const QItemSelection &selected, const QItemSelection &deselected)
Abstract Superclass for all specific types of MRML nodes.
A set of MRML Nodes that supports serialization and undo/redo.