123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- #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<QDoubleSpinBox *>(editor);
- spinBox->setValue(value);
- }
- void MatterElementItemSpinDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const
- {
- QDoubleSpinBox *spinBox = static_cast<QDoubleSpinBox *>(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<InsideWidget *>(editor);
- iw->setValue(value);
- }
- void MatterElementItemInsideDelegate::setModelData(QWidget *editor, QAbstractItemModel *model,
- const QModelIndex &index) const
- {
- InsideWidget *iw = static_cast<InsideWidget *>(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);
- }
|