Medical Imaging Interaction Toolkit  2026.06.00
Medical Imaging Interaction Toolkit
QmitkPropertyItemDelegate.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef QmitkPropertyItemDelegate_h
14 #define QmitkPropertyItemDelegate_h
15 
16 #include <MitkQtWidgetsExports.h>
17 #include <QListView>
18 #include <QStyledItemDelegate>
19 #include <mitkPropertyList.h>
20 #include <mitkWeakPointer.h>
21 
22 class QComboBox;
23 class QLineEdit;
24 class QToolButton;
25 class QResizeEvent;
26 
35 class QmitkColorWidget : public QWidget
36 {
37  Q_OBJECT
38 
39 public:
44  explicit QmitkColorWidget(QWidget *parent = nullptr);
45  ~QmitkColorWidget() override;
46 
51  QColor GetColor() const;
52 
57  void SetColor(QColor color);
58 
59 signals:
61  void ColorPicked();
62 
63 private slots:
64  void OnButtonClicked();
65  void OnLineEditEditingFinished();
66 
67 private:
68  QColor m_Color;
69  QLineEdit *m_LineEdit;
70  QToolButton *m_Button;
71 };
72 
80 class QmitkComboBoxListView : public QListView
81 {
82  Q_OBJECT
83 
84 public:
89  explicit QmitkComboBoxListView(QComboBox *comboBox = nullptr);
91 
92 protected:
93  void paintEvent(QPaintEvent *event) override;
94  void resizeEvent(QResizeEvent *event) override;
95  void initViewItemOption(QStyleOptionViewItem *option) const override;
96 
97 private:
98  QComboBox *m_ComboBox;
99 };
100 
112 class MITKQTWIDGETS_EXPORT QmitkPropertyItemDelegate : public QStyledItemDelegate
113 {
114  Q_OBJECT
115 
116 public:
121  explicit QmitkPropertyItemDelegate(QObject *parent = nullptr);
123 
131  QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
132 
139  void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
140 
146  void setEditorData(QWidget *editor, const QModelIndex &index) const override;
147 
154  void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
155 
160  void SetPropertyList(mitk::PropertyList *propertyList);
161 
162 private slots:
163  void OnComboBoxCurrentIndexChanged(int index);
164  void OnSpinBoxEditingFinished();
165  void OnColorPicked();
166 
167 private:
168  std::string GetPropertyName(const QModelIndex &index) const;
169 
171 };
172 
173 #endif
#define MITKQTWIDGETS_EXPORT
A small widget combining a QLineEdit and a QToolButton for color editing.
QmitkColorWidget(QWidget *parent=nullptr)
Constructs the color widget.
void SetColor(QColor color)
Sets the displayed color.
~QmitkColorWidget() override
void ColorPicked()
Emitted when a new color has been picked via the dialog or line edit.
QColor GetColor() const
Returns the currently selected color.
Custom QListView used as the popup view for combo boxes in property editing.
QmitkComboBoxListView(QComboBox *comboBox=nullptr)
Constructs the list view for the given combo box.
void paintEvent(QPaintEvent *event) override
void initViewItemOption(QStyleOptionViewItem *option) const override
void resizeEvent(QResizeEvent *event) override
~QmitkComboBoxListView() override
Item delegate for editing MITK properties in a QTreeView or QTableView.
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Paints the item, with special handling for color properties.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override
Creates a type-appropriate editor widget for the given model index.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override
Writes the editor widget data back to the model.
void SetPropertyList(mitk::PropertyList *propertyList)
Sets the property list whose properties are being edited.
QmitkPropertyItemDelegate(QObject *parent=nullptr)
Constructs the delegate.
~QmitkPropertyItemDelegate() override
void setEditorData(QWidget *editor, const QModelIndex &index) const override
Sets the editor widget data from the model.
Key-value list holding instances of BaseProperty.