| 53 | } |
| 54 | |
| 55 | bool QmitkLabelToggleItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &, |
| 56 | const QModelIndex &index) |
| 57 | { |
| 58 | Q_ASSERT(event); |
| 59 | Q_ASSERT(model); |
| 60 | |
| 61 | // make sure that the item is checkable |
| 62 | Qt::ItemFlags flags = model->flags(index); |
| 63 | if (!(flags & Qt::ItemIsEditable) || !(flags & Qt::ItemIsEnabled)) |
| 64 | { |
| 65 | return false; |
| 66 | } |
| 67 | |
| 68 | // make sure that we have the right event type |
| 69 | QMouseEvent* mouseEvent = dynamic_cast<QMouseEvent*>(event); |
| 70 | if (nullptr == mouseEvent || mouseEvent->type() != QEvent::MouseButtonRelease || mouseEvent->button() != Qt::LeftButton) |
| 71 | { |
| 72 | return false; |
| 73 | } |
| 74 | |
| 75 | auto visVar = index.data(Qt::EditRole); |
| 76 | auto data = visVar.isValid() |
| 77 | ? QVariant(!(visVar.toBool())) |
| 78 | : QVariant(true); |
| 79 | return model->setData(index, data, Qt::EditRole); |
| 80 | |
| 81 | return false; |
| 82 | }; |