summaryrefslogtreecommitdiffstats
path: root/qt-ui/configuredivecomputerdialog.cpp
diff options
context:
space:
mode:
authorGravatar Anton Lundin <glance@acc.umu.se>2014-10-27 22:12:45 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2014-10-27 15:41:51 -0700
commit0e3a9328bc10b59a4e4843819bad0b3a4d75c456 (patch)
tree1860e8f20b24eab7838761aa2c7a25cbbf0782f4 /qt-ui/configuredivecomputerdialog.cpp
parent49401eec0bc83bc852114eac0a6ec828016e9ae8 (diff)
downloadsubsurface-0e3a9328bc10b59a4e4843819bad0b3a4d75c456.tar.gz
Create a delegate for gas type columns
This creates a delegate for the type column to choose the type value for gases that is less confusing then the raw value. Signed-off-by: Anton Lundin <glance@acc.umu.se> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui/configuredivecomputerdialog.cpp')
-rw-r--r--qt-ui/configuredivecomputerdialog.cpp41
1 files changed, 41 insertions, 0 deletions
diff --git a/qt-ui/configuredivecomputerdialog.cpp b/qt-ui/configuredivecomputerdialog.cpp
index a97d1dbde..c2da24485 100644
--- a/qt-ui/configuredivecomputerdialog.cpp
+++ b/qt-ui/configuredivecomputerdialog.cpp
@@ -28,6 +28,42 @@ struct mydescriptor {
unsigned int model;
};
+GasTypeComboBoxItemDelegate::GasTypeComboBoxItemDelegate(QObject *parent, computer_type type) : QStyledItemDelegate(parent), type(type) { }
+GasTypeComboBoxItemDelegate::~GasTypeComboBoxItemDelegate() { }
+
+QWidget* GasTypeComboBoxItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
+{
+ // Create the combobox and populate it
+ QComboBox *cb = new QComboBox(parent);
+ cb->addItem(QString("Disabled"));
+ if (type == OSTC3) {
+ cb->addItem(QString("Fist"));
+ cb->addItem(QString("Travel"));
+ cb->addItem(QString("Deco"));
+ } else if (type == OSTC) {
+ cb->addItem(QString("Active"));
+ cb->addItem(QString("Fist"));
+ }
+ return cb;
+}
+
+void GasTypeComboBoxItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const
+{
+ if(QComboBox *cb = qobject_cast<QComboBox *>(editor))
+ cb->setCurrentIndex(index.data(Qt::EditRole).toInt());
+ else
+ QStyledItemDelegate::setEditorData(editor, index);
+}
+
+
+void GasTypeComboBoxItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
+{
+ if(QComboBox *cb = qobject_cast<QComboBox *>(editor))
+ model->setData(index, cb->currentIndex(), Qt::EditRole);
+ else
+ QStyledItemDelegate::setModelData(editor, model, index);
+}
+
ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
QDialog(parent),
config(0),
@@ -53,6 +89,11 @@ ConfigureDiveComputerDialog::ConfigureDiveComputerDialog(QWidget *parent) :
ui.DiveComputerList->setCurrentRow(0);
on_DiveComputerList_currentRowChanged(0);
+ ui.ostc3GasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
+ ui.ostc3DilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC3));
+ ui.ostcGasTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC));
+ ui.ostcDilTable->setItemDelegateForColumn(3, new GasTypeComboBoxItemDelegate(this, GasTypeComboBoxItemDelegate::OSTC));
+
QSettings settings;
settings.beginGroup("ConfigureDiveComputerDialog");
settings.beginGroup("ostc3GasTable");