Slicer  4.11
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLColorModel.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 __qMRMLColorModel_h
22 #define __qMRMLColorModel_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 
34 class vtkMRMLNode;
35 class vtkMRMLColorNode;
36 class vtkMRMLColorLogic;
37 class QAction;
38 
39 class qMRMLColorModelPrivate;
40 
41 //------------------------------------------------------------------------------
42 class QMRML_WIDGETS_EXPORT qMRMLColorModel : public QStandardItemModel
43 {
44  Q_OBJECT
45  QVTK_OBJECT
46  Q_ENUMS(ItemDataRole)
47  Q_PROPERTY(bool noneEnabled READ noneEnabled WRITE setNoneEnabled)
48 
54  Q_PROPERTY(int colorColumn READ colorColumn WRITE setColorColumn)
59  Q_PROPERTY(int labelColumn READ labelColumn WRITE setLabelColumn)
64  Q_PROPERTY(int opacityColumn READ opacityColumn WRITE setOpacityColumn)
70  Q_PROPERTY(int checkableColumn READ checkableColumn WRITE setCheckableColumn)
71 
72 public:
73  typedef QAbstractItemModel Superclass;
74  qMRMLColorModel(QObject *parent=nullptr);
75  ~qMRMLColorModel() override;
76 
80  ColorEntryRole = Qt::UserRole,
82  ColorRole
83  };
84 
85 
86  void setMRMLColorNode(vtkMRMLColorNode* node);
87  vtkMRMLColorNode* mrmlColorNode()const;
88 
91  void setNoneEnabled(bool enable);
92  bool noneEnabled()const;
93 
94  int colorColumn()const;
95  void setColorColumn(int column);
96 
97  int labelColumn()const;
98  void setLabelColumn(int column);
99 
100  int opacityColumn()const;
101  void setOpacityColumn(int column);
102 
103  int checkableColumn()const;
104  void setCheckableColumn(int column);
105 
109  inline int colorFromIndex(const QModelIndex &index)const;
113  int colorFromItem(QStandardItem* item)const;
114 
115  QStandardItem* itemFromColor(int color, int column = 0)const;
116  QModelIndexList indexes(int color)const;
117 
118  inline QColor qcolorFromIndex(const QModelIndex& nodeIndex)const;
119  inline QColor qcolorFromItem(QStandardItem* nodeItem)const;
120  QColor qcolorFromColor(int color)const;
121 
124  QString nameFromColor(int colorEntry)const;
127  int colorFromName(const QString& name)const;
128 
131  QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override;
132 
133 protected slots:
134  void onMRMLColorNodeModified(vtkObject* node);
135  void onItemChanged(QStandardItem * item);
136 
137 protected:
138 
139  qMRMLColorModel(qMRMLColorModelPrivate* pimpl, QObject *parent=nullptr);
140  virtual void updateItemFromColor(QStandardItem* item, int color, int column);
141  virtual void updateColorFromItem(int color, QStandardItem* item);
142  virtual void updateNode();
143 
144  static void onMRMLNodeEvent(vtkObject* vtk_obj, unsigned long event,
145  void* client_data, void* call_data);
146 protected:
147  QScopedPointer<qMRMLColorModelPrivate> d_ptr;
148 
149 private:
150  Q_DECLARE_PRIVATE(qMRMLColorModel);
151  Q_DISABLE_COPY(qMRMLColorModel);
152 };
153 
154 // -----------------------------------------------------------------------------
155 int qMRMLColorModel::colorFromIndex(const QModelIndex &nodeIndex)const
156 {
157  return this->colorFromItem(this->itemFromIndex(nodeIndex));
158 }
159 
160 // -----------------------------------------------------------------------------
161 QColor qMRMLColorModel::qcolorFromIndex(const QModelIndex &nodeIndex)const
162 {
163  return this->qcolorFromItem(this->itemFromIndex(nodeIndex));
164 }
165 
166 // -----------------------------------------------------------------------------
167 QColor qMRMLColorModel::qcolorFromItem(QStandardItem* nodeItem)const
168 {
169  return this->qcolorFromColor(this->colorFromItem(nodeItem));
170 }
171 
172 #endif
QColor qcolorFromIndex(const QModelIndex &nodeIndex) const
QScopedPointer< qMRMLColorModelPrivate > d_ptr
int colorFromItem(QStandardItem *item) const
QColor qcolorFromItem(QStandardItem *nodeItem) const
MRML logic class for color manipulation.
QColor qcolorFromColor(int color) const
Abstract MRML node to represent color information.
QAbstractItemModel Superclass
int colorFromIndex(const QModelIndex &index) const
Abstract Superclass for all specific types of MRML nodes.
Definition: vtkMRMLNode.h:167