-
Notifications
You must be signed in to change notification settings - Fork 1
/
enableddelegate.cpp
42 lines (34 loc) · 1.24 KB
/
enableddelegate.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*!
* \file enableddelegate.cpp
* \author Simon Coakley
* \date 2012
* \copyright Copyright (c) 2012 University of Sheffield
* \brief Implementation of enabled delegate
*/
#include <QCheckBox>
#include "./enableddelegate.h"
EnabledDelegate::EnabledDelegate(QObject * parent)
: QItemDelegate(parent) {
}
QWidget *EnabledDelegate::createEditor(QWidget *parent,
const QStyleOptionViewItem &/*option*/,
const QModelIndex &/*index*/) const {
QCheckBox *editor = new QCheckBox(parent);
return editor;
}
void EnabledDelegate::setEditorData(QWidget *editor,
const QModelIndex &index) const {
bool value = index.data().toBool();
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
emit(checkBox->setChecked(value));
}
void EnabledDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
const QModelIndex &index) const {
QCheckBox *checkBox = static_cast<QCheckBox*>(editor);
bool value = checkBox->isChecked();
model->setData(index, value, Qt::EditRole);
}
void EnabledDelegate::updateEditorGeometry(QWidget *editor,
const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const {
editor->setGeometry(option.rect);
}