MCPcopy Create free account
hub / github.com/MITK/MITK / editorEvent

Method editorEvent

Modules/SegmentationUI/src/QmitkLabelColorItemDelegate.cpp:40–69  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

38}
39
40bool QmitkLabelColorItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &,
41 const QModelIndex &index)
42{
43 Q_ASSERT(event);
44 Q_ASSERT(model);
45
46 // make sure that the item is checkable
47 Qt::ItemFlags flags = model->flags(index);
48 if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled))
49 {
50 return false;
51 }
52
53 // make sure that we have the right event type
54 QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event);
55 if (nullptr == mouseEvent || mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton)
56 {
57 return false;
58 }
59
60 QColor oldColor = index.data(Qt::EditRole).value<QColor>();
61 QColor newColor = QColorDialog::getColor(oldColor, nullptr);
62
63 if (newColor.isValid())
64 {
65 return model->setData(index, QVariant(newColor), Qt::EditRole);
66 }
67
68 return false;
69};

Callers

nothing calls this directly

Calls 4

typeMethod · 0.80
flagsMethod · 0.45
dataMethod · 0.45
setDataMethod · 0.45

Tested by

no test coverage detected