ENH: Allow clicking anywhere in field to toggle check boxes.
This commit is contained in:
parent
05f4f0e3e6
commit
073b109508
|
@ -317,9 +317,12 @@ bool QCMakeCacheModel::setData (const QModelIndex& idx, const QVariant& value, i
|
|||
QModelIndex QCMakeCacheModel::buddy(const QModelIndex& idx) const
|
||||
{
|
||||
if(idx.column() == 0)
|
||||
{
|
||||
if(this->Properties[idx.row()].Type != QCMakeCacheProperty::BOOL)
|
||||
{
|
||||
return this->index(idx.row(), 1);
|
||||
}
|
||||
}
|
||||
return idx;
|
||||
}
|
||||
|
||||
|
@ -387,6 +390,49 @@ QWidget* QCMakeCacheModelDelegate::createEditor(QWidget* p,
|
|||
return new QLineEdit(p);
|
||||
}
|
||||
|
||||
bool QCMakeCacheModelDelegate::editorEvent(QEvent* event, QAbstractItemModel* model,
|
||||
const QStyleOptionViewItem& option, const QModelIndex& index)
|
||||
{
|
||||
Qt::ItemFlags flags = model->flags(index);
|
||||
if (!(flags & Qt::ItemIsUserCheckable) || !(option.state & QStyle::State_Enabled)
|
||||
|| !(flags & Qt::ItemIsEnabled))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
QVariant value = index.data(Qt::CheckStateRole);
|
||||
if (!value.isValid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if ((event->type() == QEvent::MouseButtonRelease)
|
||||
|| (event->type() == QEvent::MouseButtonDblClick))
|
||||
{
|
||||
// eat the double click events inside the check rect
|
||||
if (event->type() == QEvent::MouseButtonDblClick)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else if (event->type() == QEvent::KeyPress)
|
||||
{
|
||||
if(static_cast<QKeyEvent*>(event)->key() != Qt::Key_Space &&
|
||||
static_cast<QKeyEvent*>(event)->key() != Qt::Key_Select)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Qt::CheckState state = (static_cast<Qt::CheckState>(value.toInt()) == Qt::Checked
|
||||
? Qt::Unchecked : Qt::Checked);
|
||||
return model->setData(index, state, Qt::CheckStateRole);
|
||||
}
|
||||
|
||||
QCMakeCacheFileEditor::QCMakeCacheFileEditor(QWidget* p)
|
||||
: QLineEdit(p)
|
||||
{
|
||||
|
|
|
@ -105,6 +105,8 @@ public:
|
|||
/// create our own editors for cache properties
|
||||
QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option,
|
||||
const QModelIndex& index ) const;
|
||||
bool editorEvent (QEvent* event, QAbstractItemModel* model,
|
||||
const QStyleOptionViewItem& option, const QModelIndex& index);
|
||||
};
|
||||
|
||||
/// Editor widget for editing paths or file paths
|
||||
|
|
Loading…
Reference in New Issue