20 #include <QApplication>
22 #include <QDoubleSpinBox>
29 ,
const QModelIndex &index)
const
31 QVariant data = index.data(Qt::DisplayRole);
33 QStyleOptionViewItemV4 opt = option;
34 initStyleOption(&opt, index);
36 QStyle *style = QApplication::style();
39 style->drawItemText(painter, opt.rect.adjusted(0,0,-5,0), Qt::AlignRight | Qt::AlignVCenter, opt.palette,
true, data.toString());
43 ,
const QModelIndex &index)
const
45 QVariant data = index.data(Qt::EditRole);
46 QVariant displayData = index.data(Qt::DisplayRole);
47 QVariant absoluteDose = index.data(Qt::UserRole+1);
51 QDoubleSpinBox* spinBox =
new QDoubleSpinBox(parent);
52 spinBox->setDecimals(2);
53 if (absoluteDose.toBool())
55 spinBox->setSingleStep(0.5);
56 spinBox->setSuffix(QString(
" Gy"));
60 spinBox->setSingleStep(1.0);
61 spinBox->setSuffix(QString(
" %"));
64 spinBox->setMinimum(0.0);
65 spinBox->setMaximum(9999.0);
67 spinBox->installEventFilter( const_cast<QmitkDoseValueDelegate*>(
this) );
73 return new QLabel(displayData.toString(), parent);
79 QVariant data = index.data(Qt::EditRole);
84 QDoubleSpinBox* spinBox = qobject_cast<QDoubleSpinBox *>(editor);
87 spinBox->setValue(data.toDouble());
91 QStyledItemDelegate::setEditorData(editor, index);
97 ,
const QModelIndex &index)
const
99 QVariant data = index.data(Qt::EditRole);
103 QDoubleSpinBox* spinBox = qobject_cast<QDoubleSpinBox *>(editor);
104 double doubleValue = spinBox->value();
106 QVariant doubleValueVariant(doubleValue);
107 model->setData(index, doubleValueVariant);
111 QStyledItemDelegate::setModelData(editor, model, index);
QmitkDoseValueDelegate(QObject *parent=0)
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setEditorData(QWidget *editor, const QModelIndex &index) const
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const