| 605 | } |
| 606 | |
| 607 | bool QCMakeCacheModelDelegate::editorEvent(QEvent* e, |
| 608 | QAbstractItemModel* model, |
| 609 | QStyleOptionViewItem const& option, |
| 610 | QModelIndex const& index) |
| 611 | { |
| 612 | Qt::ItemFlags flags = model->flags(index); |
| 613 | if (!(flags & Qt::ItemIsUserCheckable) || |
| 614 | !(option.state & QStyle::State_Enabled) || |
| 615 | !(flags & Qt::ItemIsEnabled)) { |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | QVariant value = index.data(Qt::CheckStateRole); |
| 620 | if (!value.isValid()) { |
| 621 | return false; |
| 622 | } |
| 623 | |
| 624 | if ((e->type() == QEvent::MouseButtonRelease) || |
| 625 | (e->type() == QEvent::MouseButtonDblClick)) { |
| 626 | // eat the double click events inside the check rect |
| 627 | if (e->type() == QEvent::MouseButtonDblClick) { |
| 628 | return true; |
| 629 | } |
| 630 | } else if (e->type() == QEvent::KeyPress) { |
| 631 | if (static_cast<QKeyEvent*>(e)->key() != Qt::Key_Space && |
| 632 | static_cast<QKeyEvent*>(e)->key() != Qt::Key_Select) { |
| 633 | return false; |
| 634 | } |
| 635 | } else { |
| 636 | return false; |
| 637 | } |
| 638 | |
| 639 | Qt::CheckState state = |
| 640 | (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked ? Qt::Unchecked |
| 641 | : Qt::Checked); |
| 642 | bool success = model->setData(index, state, Qt::CheckStateRole); |
| 643 | if (success) { |
| 644 | this->recordChange(model, index); |
| 645 | } |
| 646 | return success; |
| 647 | } |
| 648 | |
| 649 | bool QCMakeCacheModelDelegate::eventFilter(QObject* object, QEvent* evt) |
| 650 | { |