aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--qt-ui/maintab.cpp5
-rw-r--r--qt-ui/modeldelegates.cpp26
-rw-r--r--qt-ui/modeldelegates.h11
-rw-r--r--qt-ui/models.cpp12
-rw-r--r--qt-ui/models.h1
5 files changed, 53 insertions, 2 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp
index 3cf0a063d..cbd368798 100644
--- a/qt-ui/maintab.cpp
+++ b/qt-ui/maintab.cpp
@@ -103,6 +103,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
connect(ui.weights->view(), SIGNAL(clicked(QModelIndex)), this, SLOT(editWeightWidget(QModelIndex)));
ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
+ ui.cylinders->view()->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this));
ui.weights->view()->setItemDelegateForColumn(WeightModel::TYPE, new WSInfoDelegate(this));
ui.cylinders->view()->setColumnHidden(CylindersModel::DEPTH, true);
completers.buddy = new QCompleter(&buddyModel, ui.buddy);
@@ -612,6 +613,10 @@ void MainTab::updateDiveInfo(bool clear)
}
editMode = NONE;
ui.cylinders->view()->hideColumn(CylindersModel::DEPTH);
+ if (get_dive_dc(&displayed_dive, dc_number)->dctype == CCR)
+ ui.cylinders->view()->showColumn(CylindersModel::USE);
+ else
+ ui.cylinders->view()->hideColumn(CylindersModel::USE);
}
void MainTab::addCylinder_clicked()
diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp
index 7079173c4..85be9ba62 100644
--- a/qt-ui/modeldelegates.cpp
+++ b/qt-ui/modeldelegates.cpp
@@ -277,6 +277,32 @@ QWidget *TankInfoDelegate::createEditor(QWidget *parent, const QStyleOptionViewI
return delegate;
}
+TankUseDelegate::TankUseDelegate(QObject *parent)
+{
+
+}
+
+QWidget *TankUseDelegate::createEditor(QWidget * parent, const QStyleOptionViewItem & option, const QModelIndex & index) const
+{
+ QComboBox *comboBox = new QComboBox(parent);
+ for (int i = 0; i < NUM_GAS_USE; i++)
+ comboBox->addItem(QString(cylinderuse_text[i]));
+ return comboBox;
+}
+
+void TankUseDelegate::setEditorData(QWidget * editor, const QModelIndex & index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
+ QString indexString = index.data().toString();
+ comboBox->setCurrentIndex(cylinderuse_from_text(indexString.toUtf8().data()));
+}
+
+void TankUseDelegate::setModelData(QWidget * editor, QAbstractItemModel * model, const QModelIndex & index) const
+{
+ QComboBox *comboBox = qobject_cast<QComboBox*>(editor);
+ model->setData(index, comboBox->currentIndex());
+}
+
struct RevertWeightData {
QString type;
int weight;
diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h
index 94ffe0868..173151a4a 100644
--- a/qt-ui/modeldelegates.h
+++ b/qt-ui/modeldelegates.h
@@ -2,7 +2,7 @@
#define MODELDELEGATES_H
#include <QStyledItemDelegate>
-class QComboBox;
+#include <QComboBox>
class QPainter;
class DiveListDelegate : public QStyledItemDelegate {
@@ -59,6 +59,15 @@ slots:
void revertModelData(QWidget *widget, QAbstractItemDelegate::EndEditHint hint);
};
+class TankUseDelegate : public QStyledItemDelegate {
+ Q_OBJECT
+public:
+ explicit TankUseDelegate(QObject *parent = 0);
+ virtual void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
+ virtual QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
+ virtual void setEditorData(QWidget * editor, const QModelIndex & index) const;
+};
+
class WSInfoDelegate : public ComboBoxDelegate {
Q_OBJECT
public:
diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp
index 7cf305d83..9464d6c37 100644
--- a/qt-ui/models.cpp
+++ b/qt-ui/models.cpp
@@ -76,7 +76,7 @@ CylindersModel::CylindersModel(QObject *parent) : changed(false),
{
// enum {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, DEPTH};
setHeaderDataStrings(QStringList() << "" << tr("Type") << tr("Size") << tr("Work press.") << tr("Start press.") << tr("End press.") << trUtf8("O" UTF8_SUBSCRIPT_2 "%") << tr("He%")
- << tr("Switch at"));
+ << tr("Switch at") << tr("Use"));
initTrashIcon();
}
@@ -172,6 +172,9 @@ QVariant CylindersModel::data(const QModelIndex &index, int role) const
case DEPTH:
ret = get_depth_string(cyl->depth, true);
break;
+ case USE:
+ ret = QString(cylinderuse_text[cyl->cylinder_use]);
+ break;
}
break;
case Qt::DecorationRole:
@@ -297,6 +300,13 @@ bool CylindersModel::setData(const QModelIndex &index, const QVariant &value, in
cyl->depth = string_to_depth(vString.toUtf8().data());
changed = true;
}
+ break;
+ case USE:
+ if (CHANGED()) {
+ cyl->cylinder_use = (enum cylinderuse)vString.toInt();
+ changed = true;
+ }
+ break;
}
if (addDiveMode)
DivePlannerPointsModel::instance()->tanksUpdated();
diff --git a/qt-ui/models.h b/qt-ui/models.h
index d61a96f9b..0123ce171 100644
--- a/qt-ui/models.h
+++ b/qt-ui/models.h
@@ -107,6 +107,7 @@ public:
O2,
HE,
DEPTH,
+ USE,
COLUMNS
};