Slicer  5.1
Slicer is a multi-platform, free and open source software package for visualization and medical image computing
qMRMLItemDelegate.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 __qMRMLItemDelegate_h
22 #define __qMRMLItemDelegate_h
23 
24 // Qt includes
25 #include <QStyledItemDelegate>
26 
27 // CTK includes
28 class ctkDoubleSpinBox;
29 
30 // qMRML includes
31 #include "qMRMLWidgetsExport.h"
32 
40 class QMRML_WIDGETS_EXPORT qMRMLItemDelegate: public QStyledItemDelegate
41 {
42  Q_OBJECT
43 public:
44  qMRMLItemDelegate(QObject *parent = nullptr);
45  ~qMRMLItemDelegate() override;
46  typedef QStyledItemDelegate Superclass;
47 
48  bool isColor(const QModelIndex& index)const;
49  int colorRole(const QModelIndex& index)const;
50  bool is0To1Value(const QModelIndex& index)const;
51 
52  QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
53  const QModelIndex &index) const override;
54 
55  void setEditorData(QWidget *editor, const QModelIndex &index) const override;
56  void setModelData(QWidget *editor, QAbstractItemModel *model,
57  const QModelIndex &index) const override;
58 
59  QSize sizeHint(const QStyleOptionViewItem &option,
60  const QModelIndex &index) const override;
61 
62  void updateEditorGeometry(QWidget *editor,
63  const QStyleOptionViewItem &option, const QModelIndex &index) const override;
64 
65  bool eventFilter(QObject *object, QEvent *event) override;
66 
67  // We make initStyleOption public so it can be used by qMRMLTreeView
68  using QStyledItemDelegate::initStyleOption;
69 
70 protected slots:
71  void commitSenderData();
72  void commitAndClose();
73 
74 protected:
75  ctkDoubleSpinBox* DummySpinBox;
76 };
77 
78 #endif
ctkDoubleSpinBox * DummySpinBox
Item Delegate for MRML properties Use custom widgets for properties such as colors, opacities... If an index has Qt::DecorationRole set to a QColor, its editor will then be a ctkColorPickerButton linked to a color picker dialog on click If an index has a Qt::EditRole set to a QString that exactly is on the form X.YY where X is 0 or 1 and Y is a digit (0 to 9), then the editor will be a ctkDoubleSpinBox with a slider popping up on mouse hover.
QStyledItemDelegate Superclass