68 lines
1.9 KiB
C++
68 lines
1.9 KiB
C++
#include "spinboxdelegate.h"
|
|
#include <QSpinBox>
|
|
|
|
SpinBoxDelegate::SpinBoxDelegate(QObject *parent)
|
|
: QItemDelegate(parent)
|
|
{
|
|
|
|
}
|
|
|
|
SpinBoxDelegate::~SpinBoxDelegate()
|
|
{
|
|
|
|
}
|
|
void SpinBoxDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option,
|
|
const QModelIndex &index) const
|
|
{
|
|
QItemDelegate::paint(painter, option, index);
|
|
}
|
|
|
|
QSize SpinBoxDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
|
|
{
|
|
return QItemDelegate::sizeHint(option, index);
|
|
}
|
|
|
|
QWidget *SpinBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
|
|
const QModelIndex &index) const
|
|
{
|
|
if (index.isValid() && (index.column() == COMBOXCOL || index.column() == COMBOXCOL+1))
|
|
{
|
|
QSpinBox *editor = new QSpinBox(parent);
|
|
editor->setRange(-180,180);
|
|
editor->installEventFilter(const_cast<SpinBoxDelegate *>(this));
|
|
return editor;
|
|
}
|
|
else
|
|
{
|
|
return QItemDelegate::createEditor(parent, option, index);
|
|
}
|
|
}
|
|
|
|
void SpinBoxDelegate::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();
|
|
QSpinBox *spinbox = static_cast<QSpinBox *>(editor);
|
|
spinbox->setValue(value.toInt());
|
|
}
|
|
else
|
|
{
|
|
QItemDelegate::setEditorData(editor, index);
|
|
}
|
|
}
|
|
|
|
void SpinBoxDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
const QModelIndex &index) const
|
|
{
|
|
if (index.isValid() && (index.column() == COMBOXCOL || index.column() == COMBOXCOL+1))
|
|
{
|
|
QSpinBox *spinbox = static_cast<QSpinBox *>(editor);
|
|
model->setData(index, spinbox->value());
|
|
}
|
|
else
|
|
{
|
|
QItemDelegate::setModelData(editor, model, index);
|
|
}
|
|
}
|