Slicer 5.9
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
Loading...
Searching...
No Matches
qMRMLSceneModel.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 __qMRMLSceneModel_h
22#define __qMRMLSceneModel_h
23
24// Qt includes
25#include <QStandardItemModel>
26
27// CTK includes
28#include <ctkPimpl.h>
29#include <ctkVTKObject.h>
30
31// qMRML includes
32#include "qMRMLWidgetsExport.h"
33
34class vtkMRMLNode;
35class vtkMRMLScene;
36
37class qMRMLSceneModelPrivate;
38
57class QMRML_WIDGETS_EXPORT qMRMLSceneModel : public QStandardItemModel
58{
59 Q_OBJECT
60 QVTK_OBJECT
61
62 Q_ENUMS(NodeTypes)
63
64
70
75 Q_PROPERTY(bool lazyUpdate READ lazyUpdate WRITE setLazyUpdate)
76
80 Q_PROPERTY(int nameColumn READ nameColumn WRITE setNameColumn)
83 Q_PROPERTY(int idColumn READ idColumn WRITE setIDColumn)
96public:
97 typedef QStandardItemModel Superclass;
98 qMRMLSceneModel(QObject* parent = nullptr);
99 ~qMRMLSceneModel() override;
100
121
123 Q_INVOKABLE virtual void setMRMLScene(vtkMRMLScene* scene);
124 Q_INVOKABLE vtkMRMLScene* mrmlScene() const;
125
127 QStandardItem* mrmlSceneItem() const;
128
130 QModelIndex mrmlSceneIndex() const;
131
134 inline vtkMRMLNode* mrmlNodeFromIndex(const QModelIndex& nodeIndex) const;
135 vtkMRMLNode* mrmlNodeFromItem(QStandardItem* nodeItem) const;
136 QModelIndex indexFromNode(vtkMRMLNode* node, int column = 0) const;
137 // Utility function
138 QStandardItem* itemFromNode(vtkMRMLNode* node, int column = 0) const;
139 // Return all the QModelIndexes (all the columns) for a given node
140 QModelIndexList indexes(vtkMRMLNode* node) const;
141
150
151 bool lazyUpdate() const;
152 void setLazyUpdate(bool lazy);
153
154 int nameColumn() const;
155 void setNameColumn(int column);
156
157 int idColumn() const;
158 void setIDColumn(int column);
159
160 int checkableColumn() const;
161 void setCheckableColumn(int column);
162
163 int visibilityColumn() const;
164 void setVisibilityColumn(int column);
165
166 int toolTipNameColumn() const;
167 void setToolTipNameColumn(int column);
168
169 int extraItemColumn() const;
170 void setExtraItemColumn(int column);
171
174 void setPreItems(const QStringList& extraItems, QStandardItem* parent, const QStringList& extraItemsData = QStringList());
175 QStringList preItems(QStandardItem* parent) const;
176 QStringList preItemsData(QStandardItem* parent) const;
177
180 void setPostItems(const QStringList& extraItems, QStandardItem* parent, const QStringList& extraItemsData = QStringList());
181 QStringList postItems(QStandardItem* parent) const;
182 QStringList postItemsData(QStandardItem* parent) const;
183
186 Qt::DropActions supportedDropActions() const override;
187 QMimeData* mimeData(const QModelIndexList& indexes) const override;
188 bool dropMimeData(const QMimeData* data, Qt::DropAction action, int row, int column, const QModelIndex& parent) override;
189
195 virtual vtkMRMLNode* parentNode(vtkMRMLNode* node) const;
199 virtual int nodeIndex(vtkMRMLNode* node) const;
201 virtual bool canBeAChild(vtkMRMLNode* node) const;
204 virtual bool canBeAParent(vtkMRMLNode* node) const;
207 virtual bool reparent(vtkMRMLNode* node, vtkMRMLNode* newParent);
211 bool isParentNode(vtkMRMLNode* child, vtkMRMLNode* parent) const;
215 bool isAffiliatedNode(vtkMRMLNode* nodeA, vtkMRMLNode* nodeB) const;
216
219 virtual void observeNode(vtkMRMLNode* node);
220
221protected slots:
222
225 virtual void onMRMLSceneNodeAdded(vtkMRMLScene* scene, vtkMRMLNode* node);
227
229 virtual void onMRMLSceneImported(vtkMRMLScene* scene);
231 virtual void onMRMLSceneClosed(vtkMRMLScene* scene);
234
236
237 void onMRMLNodeModified(vtkObject* node);
240 void onMRMLNodeIDChanged(vtkObject* node, void* callData);
241 virtual void onItemChanged(QStandardItem* item);
242 virtual void delayedItemChanged();
243
248
249signals:
253
257
260
263
264protected:
265 qMRMLSceneModel(qMRMLSceneModelPrivate* pimpl, QObject* parent = nullptr);
266
267 virtual void updateScene();
268 virtual void populateScene();
269 virtual QStandardItem* insertNode(vtkMRMLNode* node);
270 virtual QStandardItem* insertNode(vtkMRMLNode* node, QStandardItem* parent, int row = -1);
271
272 virtual bool isANode(const QStandardItem* item) const;
273 virtual QFlags<Qt::ItemFlag> nodeFlags(vtkMRMLNode* node, int column) const;
274
277
282 virtual void updateItemFromNode(QStandardItem* item, vtkMRMLNode* node, int column);
283
299 virtual void updateItemDataFromNode(QStandardItem* item, vtkMRMLNode* node, int column);
304 virtual void updateNodeFromItem(vtkMRMLNode* node, QStandardItem* item);
320 virtual void updateNodeFromItemData(vtkMRMLNode* node, QStandardItem* item);
321
323 void updateNodeItems(vtkMRMLNode* node, const QString& uid);
324
325 static void onMRMLSceneEvent(vtkObject* vtk_obj, unsigned long event, void* client_data, void* call_data);
326
328 virtual int maxColumnId() const;
329
330protected:
331 QScopedPointer<qMRMLSceneModelPrivate> d_ptr;
332
333private:
334 Q_DECLARE_PRIVATE(qMRMLSceneModel);
335 Q_DISABLE_COPY(qMRMLSceneModel);
336};
338
339void printStandardItem(QStandardItem* item, const QString& offset);
340
341// -----------------------------------------------------------------------------
343{
344 return this->mrmlNodeFromItem(this->itemFromIndex(nodeIndex));
345}
346
347#endif
virtual bool canBeAChild(vtkMRMLNode *node) const
fast function that only check the type of the node to know if it can be a child.
virtual QFlags< Qt::ItemFlag > nodeFlags(vtkMRMLNode *node, int column) const
QStringList postItemsData(QStandardItem *parent) const
void sceneUpdated()
This signal is sent after the scene is updated.
virtual void onMRMLSceneNodeAboutToBeAdded(vtkMRMLScene *scene, vtkMRMLNode *node)
NodeTypes listenNodeModifiedEvent() const
virtual void observeNode(vtkMRMLNode *node)
QScopedPointer< qMRMLSceneModelPrivate > d_ptr
void setPreItems(const QStringList &extraItems, QStandardItem *parent, const QStringList &extraItemsData=QStringList())
@ LastRole
Must stay the last enum in the list.
@ ExtraItemsRole
Map (QMap<QString, QVariant>) for parent items of extra items.
@ PointerRole
Pointer (as long long) of the item if it is a scene or a node.
@ UIDRole
Unique ID of the item. For nodes, it is the node ID.
virtual void populateScene()
void setExtraItemColumn(int column)
virtual void onMRMLSceneStartBatchProcess(vtkMRMLScene *scene)
virtual bool canBeAParent(vtkMRMLNode *node) const
qMRMLSceneModel(qMRMLSceneModelPrivate *pimpl, QObject *parent=nullptr)
virtual bool reparent(vtkMRMLNode *node, vtkMRMLNode *newParent)
QStringList postItems(QStandardItem *parent) const
void updateNodeItems()
You shouldn't need to call this function.
QStringList preItemsData(QStandardItem *parent) const
QModelIndexList indexes(vtkMRMLNode *node) const
virtual void onMRMLSceneAboutToBeImported(vtkMRMLScene *scene)
virtual void onItemChanged(QStandardItem *item)
virtual void onMRMLSceneImported(vtkMRMLScene *scene)
virtual void updateItemFromNode(QStandardItem *item, vtkMRMLNode *node, int column)
int toolTipNameColumn() const
vtkMRMLNode * mrmlNodeFromItem(QStandardItem *nodeItem) const
bool lazyUpdate() const
void reparentedByDragAndDrop(vtkMRMLNode *node, vtkMRMLNode *newParent)
void setIDColumn(int column)
static void onMRMLSceneEvent(vtkObject *vtk_obj, unsigned long event, void *client_data, void *call_data)
bool isParentNode(vtkMRMLNode *child, vtkMRMLNode *parent) const
void aboutToReparentByDragAndDrop(vtkMRMLNode *node, vtkMRMLNode *newParent)
qMRMLSceneModel(QObject *parent=nullptr)
int visibilityColumn() const
virtual int nodeIndex(vtkMRMLNode *node) const
virtual void onMRMLSceneNodeRemoved(vtkMRMLScene *scene, vtkMRMLNode *node)
void onMRMLSceneDeleted(vtkMRMLScene *scene)
virtual bool isANode(const QStandardItem *item) const
virtual void onMRMLSceneAboutToBeClosed(vtkMRMLScene *scene)
virtual void delayedItemChanged()
QModelIndex indexFromNode(vtkMRMLNode *node, int column=0) const
void updateColumnCount()
void sceneAboutToBeUpdated()
This signal is sent when the scene is about to be updated.
QStandardItem * mrmlSceneItem() const
0 until a valid scene is set
bool isAffiliatedNode(vtkMRMLNode *nodeA, vtkMRMLNode *nodeB) const
vtkMRMLNode * mrmlNodeFromIndex(const QModelIndex &nodeIndex) const
virtual vtkMRMLNode * parentNode(vtkMRMLNode *node) const
QStandardItemModel Superclass
Qt::DropActions supportedDropActions() const override
void setLazyUpdate(bool lazy)
virtual void updateNodeFromItemData(vtkMRMLNode *node, QStandardItem *item)
QStandardItem * itemFromNode(vtkMRMLNode *node, int column=0) const
virtual Q_INVOKABLE void setMRMLScene(vtkMRMLScene *scene)
0 by default
int idColumn() const
void setNameColumn(int column)
virtual void onMRMLSceneNodeAboutToBeRemoved(vtkMRMLScene *scene, vtkMRMLNode *node)
virtual void onMRMLSceneClosed(vtkMRMLScene *scene)
virtual void onMRMLSceneNodeAdded(vtkMRMLScene *scene, vtkMRMLNode *node)
int nameColumn() const
virtual void onMRMLSceneEndBatchProcess(vtkMRMLScene *scene)
virtual void updateScene()
virtual QStandardItem * insertNode(vtkMRMLNode *node)
void setListenNodeModifiedEvent(NodeTypes nodesToListen)
void onMRMLNodeIDChanged(vtkObject *node, void *callData)
QVTK_OBJECTNodeTypes listenNodeModifiedEvent
QStringList preItems(QStandardItem *parent) const
virtual int maxColumnId() const
Must be reimplemented in subclasses that add new column types.
void updateNodeItems(vtkMRMLNode *node, const QString &uid)
Update the items associated with the node and UID.
QModelIndex mrmlSceneIndex() const
invalid until a valid scene is set
void setVisibilityColumn(int column)
virtual void updateNodeFromItem(vtkMRMLNode *node, QStandardItem *item)
int extraItemColumn() const
void setPostItems(const QStringList &extraItems, QStandardItem *parent, const QStringList &extraItemsData=QStringList())
virtual QStandardItem * insertNode(vtkMRMLNode *node, QStandardItem *parent, int row=-1)
int checkableColumn() const
virtual void updateItemDataFromNode(QStandardItem *item, vtkMRMLNode *node, int column)
void setCheckableColumn(int column)
void setToolTipNameColumn(int column)
void onMRMLNodeModified(vtkObject *node)
QMimeData * mimeData(const QModelIndexList &indexes) const override
Q_INVOKABLE vtkMRMLScene * mrmlScene() const
bool dropMimeData(const QMimeData *data, Qt::DropAction action, int row, int column, const QModelIndex &parent) override
Abstract Superclass for all specific types of MRML nodes.
A set of MRML Nodes that supports serialization and undo/redo.
void printStandardItem(QStandardItem *item, const QString &offset)
Q_DECLARE_METATYPE(qSlicerExtensionsManagerModel::ServerAPI)