31 : QStyledItemDelegate(parent)
42 const QModelIndex &index)
const
44 int column = index.column();
47 QComboBox *box =
new QComboBox(parent);
55 return QStyledItemDelegate::createEditor(parent, option, index);
65 QComboBox *comboBox =
dynamic_cast<QComboBox *
>(object);
67 if (event->type() == QEvent::MouseButtonRelease) {
68 comboBox->showPopup();
72 return QStyledItemDelegate::eventFilter(
object, event);
88 QComboBox *comboBox =
static_cast<QComboBox *
>(editor);
89 Q_ASSERT(comboBox != NULL);
93 int value = index.model()->data(index, Qt::EditRole).toInt();
94 comboBox->setCurrentIndex(value);
96 QStyledItemDelegate::setEditorData(editor, index);
107 const QModelIndex &index)
const
109 if (!index.isValid())
112 QComboBox *comboBox =
static_cast<QComboBox *
>(editor);
113 Q_ASSERT(comboBox != NULL);
114 if (comboBox == NULL)
117 int value = comboBox->itemData(comboBox->currentIndex()).toInt();
118 model->setData(index, value, Qt::EditRole);
120 QStyledItemDelegate::setModelData(editor, model, index);
127 const QModelIndex &index)
const
130 QRect r = option.rect;
131 r.setSize(editor->sizeHint());
132 editor->setGeometry(r);
135 QRect r = option.rect;
136 r.setSize(editor->sizeHint());
137 editor->setGeometry(r);
139 QStyledItemDelegate::updateEditorGeometry(editor, option, index);
150 return QStyledItemDelegate::displayText(value, locale);
161 foreach (
const int k, keys)
static QMap< int, QString > modeNames
void loadComboBox(QComboBox *combo) const
Populate the selections in the mode combo box.
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const
Update the size of the editor widget.
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
Set data in the model when the UI is changed.
QWidget * createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
Create the QComboxBox for the mode or pass to the default implementation.
WaypointDelegate(QObject *parent=nullptr)
bool eventFilter(QObject *object, QEvent *event)
This filter is required to make combo boxes work.
void setEditorData(QWidget *editor, const QModelIndex &index) const
Set data in the UI when the model is changed.
QString displayText(const QVariant &value, const QLocale &locale) const
Convert the variant to a string value.