#include "MatterElementItemDelegate.h" MatterElementItemSpinDelegate::MatterElementItemSpinDelegate(QObject *parent) : QStyledItemDelegate(parent) { } QWidget *MatterElementItemSpinDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & /* option */, const QModelIndex & /* index */) const { QDoubleSpinBox *editor = new QDoubleSpinBox(parent); editor->setFrame(false); editor->setMinimum(-10000); editor->setMaximum(10000); return editor; } void MatterElementItemSpinDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { double value = index.model()->data(index, Qt::EditRole).toDouble(); QDoubleSpinBox *spinBox = static_cast(editor); spinBox->setValue(value); } void MatterElementItemSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { QDoubleSpinBox *spinBox = static_cast(editor); spinBox->interpretText(); int value = spinBox->value(); model->setData(index, value, Qt::EditRole); } void MatterElementItemSpinDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex & /*index*/) const { editor->setGeometry(option.rect); } MatterElementItemInsideDelegate::MatterElementItemInsideDelegate(QObject *parent) : QStyledItemDelegate(parent) { } QWidget *MatterElementItemInsideDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex & /*index*/) const { InsideWidget *editor = new InsideWidget(parent); return editor; } void MatterElementItemInsideDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { QString value = index.model()->data(index, Qt::EditRole).toString(); InsideWidget *iw = static_cast(editor); iw->setValue(value); } void MatterElementItemInsideDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { InsideWidget *iw = static_cast(editor); QString value = iw->result(); model->setData(index, value, Qt::EditRole); } void MatterElementItemInsideDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { QRect rect = option.rect; rect.adjust(-10, 0, 10, 50); editor->setGeometry(rect); }