diff options
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | dive.c | 5 | ||||
-rw-r--r-- | dive.h | 17 | ||||
-rw-r--r-- | equipment.c | 19 | ||||
-rw-r--r-- | qt-ui/addcylinderdialog.cpp | 56 | ||||
-rw-r--r-- | qt-ui/addcylinderdialog.h | 33 | ||||
-rw-r--r-- | qt-ui/addcylinderdialog.ui | 303 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.cpp | 39 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.h | 30 | ||||
-rw-r--r-- | qt-ui/addweightsystemdialog.ui | 109 | ||||
-rw-r--r-- | qt-ui/maintab.cpp | 36 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 22 | ||||
-rw-r--r-- | qt-ui/modeldelegates.h | 8 | ||||
-rw-r--r-- | qt-ui/models.cpp | 147 | ||||
-rw-r--r-- | qt-ui/models.h | 6 | ||||
-rw-r--r-- | trash.png | bin | 0 -> 4870 bytes |
16 files changed, 163 insertions, 671 deletions
@@ -33,8 +33,6 @@ EXTRA_FLAGS = $(QTCXXFLAGS) $(GTKCFLAGS) $(GLIB2CFLAGS) $(XML2CFLAGS) \ $(LIBSOUPCFLAGS) $(GCONF2CFLAGS) HEADERS = \ - qt-ui/addcylinderdialog.h \ - qt-ui/addweightsystemdialog.h \ qt-ui/divelistview.h \ qt-ui/maintab.h \ qt-ui/mainwindow.h \ @@ -66,8 +64,6 @@ SOURCES = \ time.c \ libdivecomputer.c \ qt-gui.cpp \ - qt-ui/addcylinderdialog.cpp \ - qt-ui/addweightsystemdialog.cpp \ qt-ui/divelistview.cpp \ qt-ui/maintab.cpp \ qt-ui/mainwindow.cpp \ @@ -312,6 +312,11 @@ int gas_volume(cylinder_t *cyl, pressure_t p) return cyl->type.size.mliter * surface_volume_multiplier(p); } +int wet_volume(double cuft, pressure_t p) +{ + return cuft_to_l(cuft) * 1000 / surface_volume_multiplier(p); +} + /* * If the cylinder tank pressures are within half a bar * (about 8 PSI) of the sample pressures, we consider it @@ -155,12 +155,6 @@ typedef struct { const char *description; /* "integrated", "belt", "ankle" */ } weightsystem_t; -extern bool cylinder_nodata(cylinder_t *cyl); -extern bool cylinder_none(void *_data); -extern bool weightsystem_none(void *_data); -extern bool no_weightsystems(weightsystem_t *ws); -extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2); - extern int get_pressure_units(unsigned int mb, const char **units); extern double get_depth_units(unsigned int mm, int *frac, const char **units); extern double get_volume_units(unsigned int ml, int *frac, const char **units); @@ -227,7 +221,7 @@ static inline double psi_to_bar(double psi) return psi / 14.5037738; } -static inline unsigned long psi_to_mbar(double psi) +static inline long psi_to_mbar(double psi) { return psi_to_bar(psi)*1000 + 0.5; } @@ -244,6 +238,7 @@ static inline double bar_to_atm(double bar) /* Volume in mliter of a cylinder at pressure 'p' */ extern int gas_volume(cylinder_t *cyl, pressure_t p); +extern int wet_volume(double cuft, pressure_t p); static inline int mbar_to_PSI(int mbar) { @@ -743,6 +738,14 @@ struct tank_info { int cuft, ml, psi, bar; }; +extern bool cylinder_nodata(cylinder_t *cyl); +extern bool cylinder_none(void *_data); +extern bool weightsystem_none(void *_data); +extern bool no_weightsystems(weightsystem_t *ws); +extern bool weightsystems_equal(weightsystem_t *ws1, weightsystem_t *ws2); +extern void remove_cylinder(struct dive *dive, int idx); +extern void remove_weightsystem(struct dive *dive, int idx); + #ifdef __cplusplus } #endif diff --git a/equipment.c b/equipment.c index 5f858f41d..2c17b985e 100644 --- a/equipment.c +++ b/equipment.c @@ -1267,7 +1267,26 @@ static void add_cb(GtkWidget *w, int w_idx) cylinder_list[w_idx].max_index++; gtk_widget_set_sensitive(cylinder_list[w_idx].add, cylinder_list[w_idx].max_index < MAX_CYLINDERS); } +#endif /* USE_GTK_UI */ +void remove_cylinder(struct dive *dive, int idx) +{ + cylinder_t *cyl = dive->cylinder + idx; + int nr = MAX_CYLINDERS - idx - 1; + memmove(cyl, cyl + 1, nr * sizeof(*cyl)); + memset(cyl + nr, 0, sizeof(*cyl)); +} + +void remove_weightsystem(struct dive *dive, int idx) +{ + weightsystem_t *ws = dive->weightsystem + idx; + int nr = MAX_WEIGHTSYSTEMS - idx - 1; + memmove(ws, ws + 1, nr * sizeof(*ws)); + memset(ws + nr, 0, sizeof(*ws)); +} + + +#if USE_GTK_UI static void del_cb(GtkButton *button, int w_idx) { int index, nr; diff --git a/qt-ui/addcylinderdialog.cpp b/qt-ui/addcylinderdialog.cpp deleted file mode 100644 index 5b91617ed..000000000 --- a/qt-ui/addcylinderdialog.cpp +++ /dev/null @@ -1,56 +0,0 @@ -/* - * addcylinderdialog.cpp - * - * classes for the add cylinder dialog of Subsurface - * - */ -#include "addcylinderdialog.h" -#include "ui_addcylinderdialog.h" -#include <QComboBox> -#include <QDoubleSpinBox> -#include "../conversions.h" -#include "models.h" - -AddCylinderDialog::AddCylinderDialog(QWidget *parent) : ui(new Ui::AddCylinderDialog()) -, tankInfoModel(new TankInfoModel()) -{ - ui->setupUi(this); - ui->cylinderType->setModel(tankInfoModel); -} - -void AddCylinderDialog::setCylinder(cylinder_t *cylinder) -{ - double volume, pressure; - int index; - - currentCylinder = cylinder; - convert_volume_pressure(cylinder->type.size.mliter, cylinder->type.workingpressure.mbar, &volume, &pressure); - - index = ui->cylinderType->findText(QString(cylinder->type.description)); - ui->cylinderType->setCurrentIndex(index); - ui->size->setValue(volume); - ui->pressure->setValue(pressure); - - ui->o2percent->setValue(cylinder->gasmix.o2.permille / 10.0); - ui->hepercent->setValue(cylinder->gasmix.he.permille / 10.0); - - convert_pressure(cylinder->start.mbar, &pressure); - ui->start->setValue(pressure); - - convert_pressure(cylinder->end.mbar, &pressure); - ui->end->setValue(pressure); -} - -void AddCylinderDialog::updateCylinder() -{ - QByteArray description = ui->cylinderType->currentText().toLocal8Bit(); - - currentCylinder->type.description = description.data(); - currentCylinder->type.size.mliter = ui->size->value(); - currentCylinder->type.workingpressure.mbar = ui->pressure->value(); - currentCylinder->gasmix.o2.permille = ui->o2percent->value(); - currentCylinder->gasmix.he.permille = ui->hepercent->value(); - currentCylinder->start.mbar = ui->start->value(); - currentCylinder->end.mbar = ui->end->value(); -} - diff --git a/qt-ui/addcylinderdialog.h b/qt-ui/addcylinderdialog.h deleted file mode 100644 index fc68faa72..000000000 --- a/qt-ui/addcylinderdialog.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * addcylinderdialog.h - * - * header file for the add cylinder dialog of Subsurface - * - */ -#ifndef ADDCYLINDERDIALOG_H -#define ADDCYLINDERDIALOG_H - -#include <QDialog> -#include "../dive.h" - -namespace Ui{ - class AddCylinderDialog; -} - -class TankInfoModel; - -class AddCylinderDialog : public QDialog{ - Q_OBJECT -public: - explicit AddCylinderDialog(QWidget* parent = 0); - void setCylinder(cylinder_t *cylinder); - void updateCylinder(); - -private: - Ui::AddCylinderDialog *ui; - cylinder_t *currentCylinder; - TankInfoModel *tankInfoModel; -}; - - -#endif diff --git a/qt-ui/addcylinderdialog.ui b/qt-ui/addcylinderdialog.ui deleted file mode 100644 index 8bb0428b7..000000000 --- a/qt-ui/addcylinderdialog.ui +++ /dev/null @@ -1,303 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>AddCylinderDialog</class> - <widget class="QDialog" name="AddCylinderDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>408</width> - <height>298</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" rowspan="2"> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Cylinder</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <property name="fieldGrowthPolicy"> - <enum>QFormLayout::ExpandingFieldsGrow</enum> - </property> - <item row="0" column="0"> - <widget class="QLabel" name="label"> - <property name="text"> - <string>Type</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <widget class="QComboBox" name="cylinderType"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Size</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="size"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Pressure</string> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QSpinBox" name="pressure"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="0" column="1"> - <widget class="QGroupBox" name="groupBox_2"> - <property name="title"> - <string>Pressure</string> - </property> - <layout class="QFormLayout" name="formLayout_2"> - <item row="1" column="0"> - <widget class="QLabel" name="label_4"> - <property name="text"> - <string>Start</string> - </property> - </widget> - </item> - <item row="3" column="0"> - <widget class="QLabel" name="label_6"> - <property name="text"> - <string>End</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QSpinBox" name="start"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="3" column="1"> - <widget class="QSpinBox" name="end"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="checkBox"> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="1" column="1"> - <widget class="QGroupBox" name="groupBox_3"> - <property name="title"> - <string>Gas Mix</string> - </property> - <layout class="QFormLayout" name="formLayout_3"> - <item row="1" column="0"> - <widget class="QLabel" name="label_5"> - <property name="text"> - <string>O2%</string> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QDoubleSpinBox" name="o2percent"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_7"> - <property name="text"> - <string>He%</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QDoubleSpinBox" name="hepercent"> - <property name="enabled"> - <bool>false</bool> - </property> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - </widget> - </item> - <item row="0" column="0"> - <widget class="QCheckBox" name="checkBox_2"> - <property name="text"> - <string/> - </property> - </widget> - </item> - </layout> - </widget> - </item> - <item row="2" column="0" colspan="2"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>AddCylinderDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>269</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>260</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>AddCylinderDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>290</x> - <y>269</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>260</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox</sender> - <signal>clicked(bool)</signal> - <receiver>start</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>216</x> - <y>46</y> - </hint> - <hint type="destinationlabel"> - <x>280</x> - <y>66</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox</sender> - <signal>clicked(bool)</signal> - <receiver>end</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>226</x> - <y>48</y> - </hint> - <hint type="destinationlabel"> - <x>268</x> - <y>100</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_2</sender> - <signal>clicked(bool)</signal> - <receiver>o2percent</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>214</x> - <y>165</y> - </hint> - <hint type="destinationlabel"> - <x>260</x> - <y>190</y> - </hint> - </hints> - </connection> - <connection> - <sender>checkBox_2</sender> - <signal>clicked(bool)</signal> - <receiver>hepercent</receiver> - <slot>setEnabled(bool)</slot> - <hints> - <hint type="sourcelabel"> - <x>228</x> - <y>165</y> - </hint> - <hint type="destinationlabel"> - <x>262</x> - <y>216</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/qt-ui/addweightsystemdialog.cpp b/qt-ui/addweightsystemdialog.cpp deleted file mode 100644 index 48a399de9..000000000 --- a/qt-ui/addweightsystemdialog.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * addweightsystemdialog.cpp - * - * classes for the add weightsystem dialog of Subsurface - * - */ -#include "addweightsystemdialog.h" -#include "ui_addweightsystemdialog.h" -#include <QComboBox> -#include <QDoubleSpinBox> -#include "../conversions.h" -#include "models.h" - -AddWeightsystemDialog::AddWeightsystemDialog(QWidget *parent) : ui(new Ui::AddWeightsystemDialog()) -{ - ui->setupUi(this); - currentWeightsystem = NULL; -} - -void AddWeightsystemDialog::setWeightsystem(weightsystem_t *ws) -{ - currentWeightsystem = ws; - - ui->description->insert(QString(ws->description)); - if (get_units()->weight == units::KG) - ui->weight->setValue(ws->weight.grams / 1000); - else - ui->weight->setValue(grams_to_lbs(ws->weight.grams)); -} - -void AddWeightsystemDialog::updateWeightsystem() -{ - currentWeightsystem->description = strdup(ui->description->text().toUtf8().data()); - if (get_units()->weight == units::KG) - currentWeightsystem->weight.grams = ui->weight->value() * 1000; - else - currentWeightsystem->weight.grams = lbs_to_grams(ui->weight->value()); -} - diff --git a/qt-ui/addweightsystemdialog.h b/qt-ui/addweightsystemdialog.h deleted file mode 100644 index e99dc08d8..000000000 --- a/qt-ui/addweightsystemdialog.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * addweightsystemdialog.h - * - * header file for the add weightsystem dialog of Subsurface - * - */ -#ifndef ADDWEIGHTSYSTEMDIALOG_H -#define ADDWEIGHTSYSTEMDIALOG_H - -#include <QDialog> -#include "../dive.h" - -namespace Ui{ - class AddWeightsystemDialog; -} - -class AddWeightsystemDialog : public QDialog{ - Q_OBJECT -public: - explicit AddWeightsystemDialog(QWidget* parent = 0); - void setWeightsystem(weightsystem_t *ws); - void updateWeightsystem(); - -private: - Ui::AddWeightsystemDialog *ui; - weightsystem_t *currentWeightsystem; -}; - - -#endif diff --git a/qt-ui/addweightsystemdialog.ui b/qt-ui/addweightsystemdialog.ui deleted file mode 100644 index 11e60d562..000000000 --- a/qt-ui/addweightsystemdialog.ui +++ /dev/null @@ -1,109 +0,0 @@ -<?xml version="1.0" encoding="UTF-8"?> -<ui version="4.0"> - <class>AddWeightsystemDialog</class> - <widget class="QDialog" name="AddWeightsystemDialog"> - <property name="geometry"> - <rect> - <x>0</x> - <y>0</y> - <width>408</width> - <height>186</height> - </rect> - </property> - <property name="windowTitle"> - <string>Dialog</string> - </property> - <layout class="QGridLayout" name="gridLayout"> - <item row="0" column="0" rowspan="2"> - <widget class="QGroupBox" name="groupBox"> - <property name="title"> - <string>Weightsystem</string> - </property> - <layout class="QFormLayout" name="formLayout"> - <property name="fieldGrowthPolicy"> - <enum>QFormLayout::ExpandingFieldsGrow</enum> - </property> - <item row="1" column="0"> - <widget class="QLabel" name="label_2"> - <property name="text"> - <string>Description</string> - </property> - </widget> - </item> - <item row="2" column="0"> - <widget class="QLabel" name="label_3"> - <property name="text"> - <string>Weight</string> - </property> - </widget> - </item> - <item row="2" column="1"> - <widget class="QSpinBox" name="weight"> - <property name="sizePolicy"> - <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed"> - <horstretch>0</horstretch> - <verstretch>0</verstretch> - </sizepolicy> - </property> - <property name="inputMethodHints"> - <set>Qt::ImhFormattedNumbersOnly</set> - </property> - <property name="accelerated"> - <bool>true</bool> - </property> - </widget> - </item> - <item row="1" column="1"> - <widget class="QLineEdit" name="description"/> - </item> - </layout> - </widget> - </item> - <item row="2" column="0" colspan="2"> - <widget class="QDialogButtonBox" name="buttonBox"> - <property name="orientation"> - <enum>Qt::Horizontal</enum> - </property> - <property name="standardButtons"> - <set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set> - </property> - </widget> - </item> - </layout> - </widget> - <resources/> - <connections> - <connection> - <sender>buttonBox</sender> - <signal>accepted()</signal> - <receiver>AddWeightsystemDialog</receiver> - <slot>accept()</slot> - <hints> - <hint type="sourcelabel"> - <x>248</x> - <y>269</y> - </hint> - <hint type="destinationlabel"> - <x>157</x> - <y>260</y> - </hint> - </hints> - </connection> - <connection> - <sender>buttonBox</sender> - <signal>rejected()</signal> - <receiver>AddWeightsystemDialog</receiver> - <slot>reject()</slot> - <hints> - <hint type="sourcelabel"> - <x>290</x> - <y>269</y> - </hint> - <hint type="destinationlabel"> - <x>286</x> - <y>260</y> - </hint> - </hints> - </connection> - </connections> -</ui> diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a52058816..4be27426c 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -6,12 +6,11 @@ */ #include "maintab.h" #include "ui_maintab.h" -#include "addcylinderdialog.h" -#include "addweightsystemdialog.h" #include "mainwindow.h" #include "../helpers.h" #include "../statistics.h" #include "divelistview.h" +#include "modeldelegates.h" #include <QLabel> #include <QDebug> @@ -81,6 +80,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), ui->cylinders->setColumnWidth( CylindersModel::REMOVE, 24); ui->cylinders->horizontalHeader()->setResizeMode (CylindersModel::REMOVE , QHeaderView::Fixed); + ui->cylinders->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate()); ui->weights->setColumnWidth( WeightModel::REMOVE, 24); ui->cylinders->horizontalHeader()->setResizeMode (WeightModel::REMOVE , QHeaderView::Fixed); } @@ -288,21 +288,7 @@ void MainTab::updateDiveInfo(int dive) void MainTab::addCylinder_clicked() { - if (cylindersModel->rowCount() >= MAX_CYLINDERS) - return; - - AddCylinderDialog dialog(this); - cylinder_t newCylinder; - newCylinder.type.description = ""; - - dialog.setCylinder(&newCylinder); - int result = dialog.exec(); - if (result == QDialog::Rejected) { - return; - } - - dialog.updateCylinder(); - cylindersModel->add(&newCylinder); + cylindersModel->add(); } void MainTab::on_editCylinder_clicked() @@ -315,21 +301,7 @@ void MainTab::on_delCylinder_clicked() void MainTab::addWeight_clicked() { - if (weightModel->rowCount() >= MAX_WEIGHTSYSTEMS) - return; - - AddWeightsystemDialog dialog(this); - weightsystem_t newWeightsystem; - newWeightsystem.description = ""; - newWeightsystem.weight.grams = 0; - - dialog.setWeightsystem(&newWeightsystem); - int result = dialog.exec(); - if (result == QDialog::Rejected) - return; - - dialog.updateWeightsystem(); - weightModel->add(&newWeightsystem); + weightModel->add(); } void MainTab::on_editWeight_clicked() diff --git a/qt-ui/modeldelegates.cpp b/qt-ui/modeldelegates.cpp index be47198e2..c05e59ea8 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -9,6 +9,7 @@ #include <QSortFilterProxyModel> #include <QStyle> #include <QStyleOption> +#include <QComboBox> StarWidgetsDelegate::StarWidgetsDelegate(QWidget* parent): QStyledItemDelegate(parent), @@ -47,3 +48,24 @@ QSize StarWidgetsDelegate::sizeHint(const QStyleOptionViewItem& option, const QM { return QSize(IMG_SIZE * TOTALSTARS + SPACING * (TOTALSTARS-1), IMG_SIZE); } + +QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const +{ + QComboBox *comboDelegate = new QComboBox(parent); + TankInfoModel *model = new TankInfoModel; + QString data = index.model()->data(index, Qt::DisplayRole).toString(); + comboDelegate->setModel(model); + int i; + for(i = 0; i < model->rowCount(); i++){ + if (model->data(model->index(i,0), Qt::DisplayRole).toString() == data){ + break; + } + } + if (i != model->rowCount()) + comboDelegate->setCurrentIndex(i); + return comboDelegate; +} + +TankInfoDelegate::TankInfoDelegate(QObject* parent): QStyledItemDelegate(parent) +{ +} diff --git a/qt-ui/modeldelegates.h b/qt-ui/modeldelegates.h index 5f90a3061..0a56d14d6 100644 --- a/qt-ui/modeldelegates.h +++ b/qt-ui/modeldelegates.h @@ -12,4 +12,12 @@ public: private: QWidget *parentWidget; }; + +class TankInfoDelegate : public QStyledItemDelegate{ + Q_OBJECT +public: + explicit TankInfoDelegate(QObject* parent = 0); + virtual QWidget* createEditor(QWidget* parent, const QStyleOptionViewItem& option, const QModelIndex& index) const; +}; + #endif diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index 360058dfd..eb5a9a5b4 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -6,6 +6,7 @@ */ #include "models.h" #include "../helpers.h" +#include "../dive.h" #include <QCoreApplication> #include <QDebug> #include <QColor> @@ -33,8 +34,8 @@ QVariant CylindersModel::headerData(int section, Qt::Orientation orientation, in case SIZE: ret = tr("Size"); break; - case MAXPRESS: - ret = tr("MaxPress"); + case WORKINGPRESS: + ret = tr("WorkPress"); break; case START: ret = tr("Start"); @@ -66,7 +67,7 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const cylinder_t *cyl = ¤t->cylinder[index.row()]; - if (role == Qt::DisplayRole) { + if (role == Qt::DisplayRole || role==Qt::EditRole) { switch(index.column()) { case TYPE: ret = QString(cyl->type.description); @@ -76,14 +77,14 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const // sizes take working pressure into account... if (cyl->type.size.mliter) { if (prefs.units.volume == prefs.units.CUFT) { - int cuft = ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure)); + int cuft = 0.5 + ml_to_cuft(gas_volume(cyl, cyl->type.workingpressure)); ret = QString("%1cuft").arg(cuft); } else { ret = QString("%1l").arg(cyl->type.size.mliter / 1000.0, 0, 'f', 1); } } break; - case MAXPRESS: + case WORKINGPRESS: if (cyl->type.workingpressure.mbar) ret = get_pressure_string(cyl->type.workingpressure, TRUE); break; @@ -113,45 +114,90 @@ QVariant CylindersModel::data(const QModelIndex& index, int role) const return ret; } +#define CHANGED(_t,_u1,_u2) value._t() != data(index, role).toString().replace(_u1,"").replace(_u2,"")._t() + bool CylindersModel::setData(const QModelIndex& index, const QVariant& value, int role) { cylinder_t *cyl = ¤t->cylinder[index.row()]; - switch(index.column()){ - case TYPE:{ - QByteArray desc = value.toByteArray(); - cyl->type.description = strdup(desc.data()); - break; + switch(index.column()) { + case TYPE: + if (!value.isNull()) { + char *text = value.toByteArray().data(); + if (!cyl->type.description || strcmp(cyl->type.description, text)) { + cyl->type.description = strdup(text); + mark_divelist_changed(TRUE); + } } - case SIZE: - // we can't use get_volume_string because the idiotic imperial tank - // sizes take working pressure into account... - if (cyl->type.size.mliter) { + break; + case SIZE: + if (CHANGED(toDouble, "cuft", "l")) { + // if units are CUFT then this value is meaningless until we have working pressure + if (value.toDouble() != 0.0) { if (prefs.units.volume == prefs.units.CUFT) { - double liters = cuft_to_l(value.toDouble()); - cyl->type.size.mliter = liters * 1000.0; + if (cyl->type.workingpressure.mbar == 0) + // this is a hack as we can't store a wet size + // without working pressure in cuft mode + // so we assume it's an aluminum tank at 3000psi + cyl->type.workingpressure.mbar = psi_to_mbar(3000); + if (cyl->type.size.mliter != wet_volume(value.toDouble(), cyl->type.workingpressure)) { + mark_divelist_changed(TRUE); + cyl->type.size.mliter = wet_volume(value.toDouble(), cyl->type.workingpressure); + } } else { - cyl->type.size.mliter = value.toDouble() * 1000.0; + if (cyl->type.size.mliter != value.toDouble() * 1000.0) { + mark_divelist_changed(TRUE); + cyl->type.size.mliter = value.toDouble() * 1000.0; + } } } - break; - case MAXPRESS: - cyl->type.workingpressure.mbar = value.toInt(); - break; - case START: - cyl->start.mbar = value.toInt(); - break; - case END: - cyl->end.mbar = value.toInt(); - break; - case O2: + } + break; + case WORKINGPRESS: + if (CHANGED(toDouble, "psi", "bar")) { + if (value.toDouble() != 0.0) { + if (prefs.units.pressure == prefs.units.PSI) + cyl->type.workingpressure.mbar = psi_to_mbar(value.toDouble()); + else + cyl->type.workingpressure.mbar = value.toDouble() * 1000; + mark_divelist_changed(TRUE); + } + } + break; + case START: + if (CHANGED(toDouble, "psi", "bar")) { + if (value.toDouble() != 0.0) { + if (prefs.units.pressure == prefs.units.PSI) + cyl->start.mbar = psi_to_mbar(value.toDouble()); + else + cyl->start.mbar = value.toDouble() * 1000; + mark_divelist_changed(TRUE); + } + } + break; + case END: + if (CHANGED(toDouble, "psi", "bar")) { + if (value.toDouble() != 0.0) { + if (prefs.units.pressure == prefs.units.PSI) + cyl->end.mbar = psi_to_mbar(value.toDouble()); + else + cyl->end.mbar = value.toDouble() * 1000; + } + } + break; + case O2: + if (CHANGED(toInt, "%", "%")) { cyl->gasmix.o2.permille = value.toInt() * 10 - 5; - break; - case HE: + mark_divelist_changed(TRUE); + } + break; + case HE: + if (CHANGED(toInt, "%", "%")) { cyl->gasmix.he.permille = value.toInt() * 10 - 5; - break; + mark_divelist_changed(TRUE); + } + break; } - - return QAbstractItemModel::setData(index, value, role); + return QAbstractItemModel::setData(index, value, role); } int CylindersModel::rowCount(const QModelIndex& parent) const @@ -159,7 +205,7 @@ int CylindersModel::rowCount(const QModelIndex& parent) const return rows; } -void CylindersModel::add(cylinder_t* cyl) +void CylindersModel::add() { if (rows >= MAX_CYLINDERS) { return; @@ -167,14 +213,6 @@ void CylindersModel::add(cylinder_t* cyl) int row = rows; - cylinder_t& cylinder = current->cylinder[row]; - - cylinder.end.mbar = cyl->end.mbar; - cylinder.start.mbar = cyl->start.mbar; - cylinder.type.description = strdup(cyl->type.description); - cylinder.type.size = cyl->type.size; - cylinder.type.workingpressure = cyl->type.workingpressure; - beginInsertRows(QModelIndex(), row, row); rows++; endInsertRows(); @@ -226,7 +264,9 @@ void CylindersModel::remove(const QModelIndex& index) return; } beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly. - // Remove code should be here. + rows--; + remove_cylinder(current, index.row()); + mark_divelist_changed(TRUE); endRemoveRows(); } @@ -236,7 +276,9 @@ void WeightModel::remove(const QModelIndex& index) return; } beginRemoveRows(QModelIndex(), index.row(), index.row()); // yah, know, ugly. - // Remove code should be here. + rows--; + remove_weightsystem(current, index.row()); + mark_divelist_changed(TRUE); endRemoveRows(); } @@ -261,7 +303,7 @@ QVariant WeightModel::data(const QModelIndex& index, int role) const weightsystem_t *ws = ¤t_dive->weightsystem[index.row()]; - if (role == Qt::DisplayRole) { + if (role == Qt::DisplayRole || role == Qt::EditRole) { switch(index.column()) { case TYPE: ret = QString(ws->description); @@ -326,18 +368,12 @@ QVariant WeightModel::headerData(int section, Qt::Orientation orientation, int r return ret; } -void WeightModel::add(weightsystem_t* weight) +void WeightModel::add() { if (rows >= MAX_WEIGHTSYSTEMS) return; int row = rows; - - weightsystem_t *ws = ¤t->weightsystem[row]; - - ws->description = weight->description; - ws->weight.grams = weight->weight.grams; - beginInsertRows(QModelIndex(), row, row); rows++; endInsertRows(); @@ -395,9 +431,10 @@ QVariant TankInfoModel::data(const QModelIndex& index, int role) const int bar = ((info->psi) ? psi_to_bar(info->psi) : info->bar) * 1000 + 0.5; - if (info->cuft) { - double airvolume = cuft_to_l(info->cuft) * 1000.0; - ml = airvolume / bar_to_atm(bar) + 0.5; + if (info->cuft && info->psi) { + pressure_t p; + p.mbar = psi_to_mbar(info->psi); + ml = wet_volume(info->cuft, p); } if (role == Qt::DisplayRole) { switch(index.column()) { diff --git a/qt-ui/models.h b/qt-ui/models.h index ded612bb9..6793a7fa8 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -38,7 +38,7 @@ private: class CylindersModel : public QAbstractTableModel { Q_OBJECT public: - enum Column {REMOVE, TYPE, SIZE, MAXPRESS, START, END, O2, HE, COLUMNS}; + enum Column {REMOVE, TYPE, SIZE, WORKINGPRESS, START, END, O2, HE, COLUMNS}; explicit CylindersModel(QObject* parent = 0); /*reimp*/ QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; @@ -48,7 +48,7 @@ public: /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; /*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - void add(cylinder_t *cyl); + void add(); void clear(); void update(); void setDive(struct dive *d); @@ -73,7 +73,7 @@ public: /*reimp*/ Qt::ItemFlags flags(const QModelIndex& index) const; /*reimp*/ bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); - void add(weightsystem_t *weight); + void add(); void clear(); void update(); void setDive(struct dive *d); diff --git a/trash.png b/trash.png Binary files differnew file mode 100644 index 000000000..e3e835dee --- /dev/null +++ b/trash.png |