diff options
author | Robert C. Helling <helling@atdotde.de> | 2018-05-08 17:26:48 +0200 |
---|---|---|
committer | Lubomir I. Ivanov <neolit123@gmail.com> | 2018-05-14 23:47:00 +0300 |
commit | b8c94cad69e59e0b0584c23b39ca9a519c84db94 (patch) | |
tree | ff28a1a2dcbb845e24dd8ef6ca580c667c36aa62 /desktop-widgets | |
parent | 969dfee9ec088acb942e211cb90329d2b8c0751f (diff) | |
download | subsurface-b8c94cad69e59e0b0584c23b39ca9a519c84db94.tar.gz |
Planner: Add combo box for dive mode selection
I am not really sure what I am doing here but I copied
code from the gas selection.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/diveplanner.cpp | 1 | ||||
-rw-r--r-- | desktop-widgets/modeldelegates.cpp | 18 | ||||
-rw-r--r-- | desktop-widgets/modeldelegates.h | 10 |
3 files changed, 29 insertions, 0 deletions
diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index fd7dc948e..b22d268d8 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -114,6 +114,7 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent, Qt::WindowFlags f) : QWidg ui.tableWidget->setModel(plannerModel); plannerModel->setRecalc(true); ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::GAS, new AirTypesDelegate(this)); + ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DIVEMODE, new DiveTypesDelegate(this)); ui.cylinderTableWidget->setTitle(tr("Available gases")); ui.cylinderTableWidget->setBtnToolTip(tr("Add cylinder")); ui.cylinderTableWidget->setModel(CylindersModel::instance()); diff --git a/desktop-widgets/modeldelegates.cpp b/desktop-widgets/modeldelegates.cpp index 24dc767c4..6a33e60f4 100644 --- a/desktop-widgets/modeldelegates.cpp +++ b/desktop-widgets/modeldelegates.cpp @@ -407,6 +407,24 @@ AirTypesDelegate::AirTypesDelegate(QObject *parent) : ComboBoxDelegate(GasSelect { } +void DiveTypesDelegate::revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint) +{ + Q_UNUSED(widget) + Q_UNUSED(hint) +} + +void DiveTypesDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const +{ + if (!index.isValid()) + return; + QComboBox *combo = qobject_cast<QComboBox *>(editor); + model->setData(index, QVariant(combo->currentIndex())); +} + +DiveTypesDelegate::DiveTypesDelegate(QObject *parent) : ComboBoxDelegate(DiveTypeSelectionModel::instance(), parent, false) +{ +} + SpinBoxDelegate::SpinBoxDelegate(int min, int max, int step, QObject *parent): QStyledItemDelegate(parent), min(min), diff --git a/desktop-widgets/modeldelegates.h b/desktop-widgets/modeldelegates.h index 4c46d9b7c..a479b36f0 100644 --- a/desktop-widgets/modeldelegates.h +++ b/desktop-widgets/modeldelegates.h @@ -92,6 +92,16 @@ slots: void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint); }; +class DiveTypesDelegate : public ComboBoxDelegate { + Q_OBJECT +public: + explicit DiveTypesDelegate(QObject *parent = 0); + virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const; +public +slots: + void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint); +}; + class SpinBoxDelegate : public QStyledItemDelegate { Q_OBJECT public: |