| 49 | } |
| 50 | |
| 51 | QWidget *QmitkMapPropertyDelegate::createEditor(QWidget *parent, |
| 52 | const QStyleOptionViewItem &option, |
| 53 | const QModelIndex &index) const |
| 54 | { |
| 55 | QVariant data = index.data(Qt::EditRole); |
| 56 | QVariant displayData = index.data(Qt::DisplayRole); |
| 57 | QString name = index.model()->data(index.model()->index(index.row(), index.column() - 1)).value<QString>(); |
| 58 | |
| 59 | if (data.isValid()) |
| 60 | { |
| 61 | QWidget *editorWidget = nullptr; |
| 62 | |
| 63 | if (data.typeId() == QMetaType::Int) |
| 64 | { |
| 65 | QSpinBox *spinBox = new QSpinBox(parent); |
| 66 | spinBox->setSingleStep(1); |
| 67 | spinBox->setMinimum(std::numeric_limits<int>::min()); |
| 68 | spinBox->setMaximum(std::numeric_limits<int>::max()); |
| 69 | editorWidget = spinBox; |
| 70 | } |
| 71 | else if (data.typeId() == QMetaType::Float) |
| 72 | { |
| 73 | QDoubleSpinBox *spinBox = new QDoubleSpinBox(parent); |
| 74 | spinBox->setDecimals(5); |
| 75 | spinBox->setSingleStep(0.1); |
| 76 | spinBox->setMinimum(std::numeric_limits<float>::min()); |
| 77 | spinBox->setMaximum(std::numeric_limits<float>::max()); |
| 78 | |
| 79 | editorWidget = spinBox; |
| 80 | } |
| 81 | else if (data.typeId() == QMetaType::QStringList) |
| 82 | { |
| 83 | QStringList entries = data.value<QStringList>(); |
| 84 | QComboBox *comboBox = new QComboBox(parent); |
| 85 | comboBox->setEditable(false); |
| 86 | comboBox->addItems(entries); |
| 87 | |
| 88 | editorWidget = comboBox; |
| 89 | } |
| 90 | else |
| 91 | { |
| 92 | editorWidget = QStyledItemDelegate::createEditor(parent, option, index); |
| 93 | } |
| 94 | |
| 95 | if (editorWidget) |
| 96 | { |
| 97 | // install event filter |
| 98 | editorWidget->installEventFilter(const_cast<QmitkMapPropertyDelegate *>(this)); |
| 99 | } |
| 100 | |
| 101 | return editorWidget; |
| 102 | } |
| 103 | else |
| 104 | return new QLabel(displayData.toString(), parent); |
| 105 | } |
| 106 | |
| 107 | void QmitkMapPropertyDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const |
| 108 | { |