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
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
164 void setVisibilityColumn(int column);
165
167 void setToolTipNameColumn(int column);
168
169 int extraItemColumn()const;
170 void setExtraItemColumn(int column);
171
174 void setPreItems(const QStringList& extraItems, QStandardItem* parent);
175 QStringList preItems(QStandardItem* parent)const;
176
179 void setPostItems(const QStringList& extraItems, QStandardItem* parent);
180 QStringList postItems(QStandardItem* parent)const;
181
184 Qt::DropActions supportedDropActions()const override;
185 QMimeData* mimeData(const QModelIndexList& indexes)const override;
186 bool dropMimeData(const QMimeData *data, Qt::DropAction action,
187 int row, int column, const QModelIndex &parent) override;
188
194 virtual vtkMRMLNode* parentNode(vtkMRMLNode* node)const;
198 virtual int nodeIndex(vtkMRMLNode* node)const;
200 virtual bool canBeAChild(vtkMRMLNode* node)const;
203 virtual bool canBeAParent(vtkMRMLNode* node)const;
206 virtual bool reparent(vtkMRMLNode* node, vtkMRMLNode* newParent);
210 bool isParentNode(vtkMRMLNode* child, vtkMRMLNode* parent)const;
214 bool isAffiliatedNode(vtkMRMLNode* nodeA, vtkMRMLNode* nodeB)const;
215
218 virtual void observeNode(vtkMRMLNode* node);
219
220protected slots:
221
224 virtual void onMRMLSceneNodeAdded(vtkMRMLScene* scene, vtkMRMLNode* node);
226
228 virtual void onMRMLSceneImported(vtkMRMLScene* scene);
230 virtual void onMRMLSceneClosed(vtkMRMLScene* scene);
233
235
236 void onMRMLNodeModified(vtkObject* node);
239 void onMRMLNodeIDChanged(vtkObject* node, void* callData);
240 virtual void onItemChanged(QStandardItem * item);
241 virtual void delayedItemChanged();
242
247
248signals:
252
256
259
262
263protected:
264 qMRMLSceneModel(qMRMLSceneModelPrivate* pimpl, QObject *parent=nullptr);
265
266 virtual void updateScene();
267 virtual void populateScene();
268 virtual QStandardItem* insertNode(vtkMRMLNode* node);
269 virtual QStandardItem* insertNode(vtkMRMLNode* node, QStandardItem* parent, int row = -1);
270
271 virtual bool isANode(const QStandardItem* item)const;
272 virtual QFlags<Qt::ItemFlag> nodeFlags(vtkMRMLNode* node, int column)const;
273
276
281 virtual void updateItemFromNode(QStandardItem* item, vtkMRMLNode* node, int column);
282
298 virtual void updateItemDataFromNode(QStandardItem* item, vtkMRMLNode* node, int column);
303 virtual void updateNodeFromItem(vtkMRMLNode* node, QStandardItem* item);
319 virtual void updateNodeFromItemData(vtkMRMLNode* node, QStandardItem* item);
320
322 void updateNodeItems(vtkMRMLNode* node, const QString& uid);
323
324 static void onMRMLSceneEvent(vtkObject* vtk_obj, unsigned long event,
325 void* client_data, void* call_data);
326
328 virtual int maxColumnId()const;
329protected:
330 QScopedPointer<qMRMLSceneModelPrivate> d_ptr;
331
332private:
333 Q_DECLARE_PRIVATE(qMRMLSceneModel);
334 Q_DISABLE_COPY(qMRMLSceneModel);
335};
337
338void printStandardItem(QStandardItem* item, const QString& offset);
339
340// -----------------------------------------------------------------------------
342{
343 return this->mrmlNodeFromItem(this->itemFromIndex(nodeIndex));
344}
345
346#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
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
@ 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.
QModelIndexList indexes(vtkMRMLNode *node) const
virtual void onMRMLSceneAboutToBeImported(vtkMRMLScene *scene)
void setPostItems(const QStringList &extraItems, QStandardItem *parent)
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)
void setPreItems(const QStringList &extraItems, QStandardItem *parent)
virtual void updateNodeFromItemData(vtkMRMLNode *node, QStandardItem *item)
QStandardItem * itemFromNode(vtkMRMLNode *node, int column=0) const
QVTK_OBJECT NodeTypes listenNodeModifiedEvent
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)
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
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)