| 58 | } |
| 59 | |
| 60 | bool QmitkDoseVisualStyleDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, |
| 61 | const QModelIndex &index) |
| 62 | { |
| 63 | Q_ASSERT(event); |
| 64 | Q_ASSERT(model); |
| 65 | |
| 66 | // make sure that the item is checkable |
| 67 | Qt::ItemFlags flags = model->flags(index); |
| 68 | if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled)) |
| 69 | { |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | // make sure that we have the right event type |
| 74 | QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event); |
| 75 | if (!mouseEvent) |
| 76 | { |
| 77 | return false; |
| 78 | } |
| 79 | else |
| 80 | { |
| 81 | if (mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton) |
| 82 | { |
| 83 | return false; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | bool newState = !(index.data(Qt::EditRole).toBool()); |
| 88 | |
| 89 | return model->setData(index, QVariant(newState), Qt::EditRole); |
| 90 | }; |