init
This commit is contained in:
73
device/workfileedit/checkboxdelegate.cpp
Normal file
73
device/workfileedit/checkboxdelegate.cpp
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "checkboxdelegate.h"
|
||||
#include <QCheckBox>
|
||||
|
||||
CheckBoxDelegate::CheckBoxDelegate(QObject *parent)
|
||||
: QItemDelegate(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
CheckBoxDelegate::~CheckBoxDelegate()
|
||||
{
|
||||
|
||||
}
|
||||
void CheckBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
QItemDelegate::paint(painter, option, index);
|
||||
}
|
||||
|
||||
QSize CheckBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
||||
{
|
||||
return QItemDelegate::sizeHint(option, index);
|
||||
}
|
||||
|
||||
QWidget *CheckBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid() && (index.column() == COMBOXCOL || index.column() == COMBOXCOL+1))
|
||||
{
|
||||
QCheckBox *editor = new QCheckBox(parent);
|
||||
editor->installEventFilter(const_cast<CheckBoxDelegate *>(this));
|
||||
return editor;
|
||||
}
|
||||
else
|
||||
{
|
||||
return QItemDelegate::createEditor(parent, option, index);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckBoxDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid() && (index.column() == COMBOXCOL || index.column() == COMBOXCOL+1))
|
||||
{
|
||||
QString value = index.model()->data(index, Qt::DisplayRole).toString();
|
||||
QCheckBox *checkbox = static_cast<QCheckBox *>(editor);
|
||||
if (value.toInt() == 1)
|
||||
checkbox->setCheckState(Qt::Checked);
|
||||
else
|
||||
checkbox->setCheckState(Qt::Unchecked);
|
||||
}
|
||||
else
|
||||
{
|
||||
QItemDelegate::setEditorData(editor, index);
|
||||
}
|
||||
}
|
||||
|
||||
void CheckBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
||||
const QModelIndex &index) const
|
||||
{
|
||||
if (index.isValid() && (index.column() == COMBOXCOL || index.column() == COMBOXCOL+1))
|
||||
{
|
||||
QCheckBox *checkbox = static_cast<QCheckBox *>(editor);
|
||||
|
||||
if (checkbox->isChecked())
|
||||
model->setData(index, 1);
|
||||
else
|
||||
model->setData(index, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
QItemDelegate::setModelData(editor, model, index);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user