Slicer  5.0
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLSegmentsModel.h
Go to the documentation of this file.
1 /*==============================================================================
2 
3  Copyright (c) Laboratory for Percutaneous Surgery (PerkLab)
4  Queen's University, Kingston, ON, Canada. All Rights Reserved.
5 
6  See COPYRIGHT.txt
7  or http://www.slicer.org/copyright/copyright.txt for details.
8 
9  Unless required by applicable law or agreed to in writing, software
10  distributed under the License is distributed on an "AS IS" BASIS,
11  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  See the License for the specific language governing permissions and
13  limitations under the License.
14 
15  This file was originally developed by Kyle Sunderland, PerkLab, Queen's University
16  and was supported through CANARIE's Research Software Program, and Cancer
17  Care Ontario.
18 
19 ==============================================================================*/
20 
21 #ifndef __qMRMLSegmentsModel_h
22 #define __qMRMLSegmentsModel_h
23 
24 // Qt includes
25 #include <QStandardItemModel>
26 
27 // CTK includes
28 #include <ctkPimpl.h>
29 #include <ctkVTKObject.h>
30 
31 // Segments includes
32 #include "qSlicerSegmentationsModuleWidgetsExport.h"
33 
34 class qMRMLSegmentsModelPrivate;
36 class vtkMRMLNode;
37 class vtkMRMLScene;
38 class vtkSegment;
39 
46 class Q_SLICER_MODULE_SEGMENTATIONS_WIDGETS_EXPORT qMRMLSegmentsModel : public QStandardItemModel
47 {
48  Q_OBJECT
49  QVTK_OBJECT
50 
52  Q_PROPERTY (int nameColumn READ nameColumn WRITE setNameColumn)
55  Q_PROPERTY (int visibilityColumn READ visibilityColumn WRITE setVisibilityColumn)
58  Q_PROPERTY(int colorColumn READ colorColumn WRITE setColorColumn)
60  Q_PROPERTY (int opacityColumn READ opacityColumn WRITE setOpacityColumn)
62  Q_PROPERTY(int statusColumn READ statusColumn WRITE setStatusColumn)
64  Q_PROPERTY(int layerColumn READ layerColumn WRITE setLayerColumn)
65 
66 public:
67 
69  {
70  SegmentIDRole = Qt::UserRole + 1,
74  };
75 
76  typedef QStandardItemModel Superclass;
77  qMRMLSegmentsModel(QObject *parent=nullptr);
78  ~qMRMLSegmentsModel() override;
79 
80  int nameColumn()const;
81  void setNameColumn(int column);
82  int visibilityColumn()const;
83  void setVisibilityColumn(int column);
84  int colorColumn()const;
85  void setColorColumn(int column);
86  int opacityColumn()const;
87  void setOpacityColumn(int column);
88  int statusColumn()const;
89  void setStatusColumn(int column);
90  int layerColumn()const;
91  void setLayerColumn(int layer);
92 
94  QString segmentIDFromIndex(const QModelIndex &index)const;
95  // Returns the segment ID for the given item
96  QString segmentIDFromItem(QStandardItem* item)const;
97  // Returns the index for the given segment ID
98  QModelIndex indexFromSegmentID(QString segmentID, int column=0)const;
99  // Returns the item for the given segment ID
100  QStandardItem* itemFromSegmentID(QString segmentID, int column=0)const;
101 
103  QModelIndexList indexes(QString segmentID)const;
104 
106  vtkMRMLSegmentationNode* segmentationNode()const;
107  virtual void setSegmentationNode(vtkMRMLSegmentationNode* segmentation);
108 
110  Q_INVOKABLE static QString terminologyTooltipForSegment(vtkSegment* segment);
111 
112 signals:
115  void segmentAboutToBeModified(const QString& segmentID);
116 
118  void requestSelectItems(QList<vtkIdType> itemIDs);
119 
120 protected slots:
122  virtual void onItemChanged(QStandardItem* item);
123 
126  void updateColumnCount();
127 
128 protected:
129  qMRMLSegmentsModel(qMRMLSegmentsModelPrivate* pimpl, QObject *parent=nullptr);
130 
132  virtual void rebuildFromSegments();
134  virtual void updateFromSegments();
135 
136  virtual Qt::ItemFlags segmentFlags(QString segmentID, int column)const;
137 
139  virtual void updateItemFromSegment(QStandardItem* item, QString segmentID, int column );
141  virtual void updateItemDataFromSegment(QStandardItem* item, QString segmentID, int column );
143  virtual void updateSegmentFromItem(QString segmentID, QStandardItem* item );
145  virtual void updateSegmentFromItemData(QString segmentID, QStandardItem* item );
147  void updateItemsFromColumnIndex(int column);
149  void updateItemsFromSegmentID(QString segmentID);
150 
152  void reorderItems();
153 
159  static void onEvent(vtkObject* caller, unsigned long event, void* clientData, void* callData);
160 
162  virtual int maxColumnId()const;
163 
165  virtual void onSegmentAdded(QString segmentID);
167  virtual void onSegmentRemoved(QString segmentID);
169  virtual void onSegmentModified(QString segmentID);
171  virtual void onSegmentOrderModified();
173  virtual void onDisplayNodeModified();
174 
175 protected:
176  QScopedPointer<qMRMLSegmentsModelPrivate> d_ptr;
177 
178 private:
179  Q_DECLARE_PRIVATE(qMRMLSegmentsModel);
180  Q_DISABLE_COPY(qMRMLSegmentsModel);
181 };
182 
183 #endif
This class encapsulates a segment that is part of a segmentation.
Definition: vtkSegment.h:45
QScopedPointer< qMRMLSegmentsModelPrivate > d_ptr
A set of MRML Nodes that supports serialization and undo/redo.
Definition: vtkMRMLScene.h:57
QStandardItemModel Superclass
Item model for segments.
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167
MRML node containing segmentationsSegmentation node stores a set of segments (also known as contours ...