diff options
author | Dirk Hohndel <dirk@hohndel.org> | 2013-05-22 12:14:06 -0700 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-05-22 12:14:06 -0700 |
commit | 63b6f7d5a25967f003a734d2058a73b4b13e8387 (patch) | |
tree | 0f5d68199afacaa04bd2bac7029fc08e42db18c5 /qt-ui | |
parent | 9c3b512701c59955350f317eb6d19e6fdc93f546 (diff) | |
parent | 134e20bdc27f63c73ef8257dc357ae05642fece8 (diff) | |
download | subsurface-63b6f7d5a25967f003a734d2058a73b4b13e8387.tar.gz |
Merge branch 'comboBoxDelegate' of https://github.com/tcanabrava/subsurface
Diffstat (limited to 'qt-ui')
-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 | 34 | ||||
-rw-r--r-- | qt-ui/modeldelegates.cpp | 1 | ||||
-rw-r--r-- | qt-ui/models.cpp | 22 | ||||
-rw-r--r-- | qt-ui/models.h | 4 |
10 files changed, 8 insertions, 623 deletions
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 c172deeea..4be27426c 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -6,8 +6,6 @@ */ #include "maintab.h" #include "ui_maintab.h" -#include "addcylinderdialog.h" -#include "addweightsystemdialog.h" #include "mainwindow.h" #include "../helpers.h" #include "../statistics.h" @@ -290,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() @@ -317,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 0164deedc..c05e59ea8 100644 --- a/qt-ui/modeldelegates.cpp +++ b/qt-ui/modeldelegates.cpp @@ -54,7 +54,6 @@ QWidget* TankInfoDelegate::createEditor(QWidget* parent, const QStyleOptionViewI QComboBox *comboDelegate = new QComboBox(parent); TankInfoModel *model = new TankInfoModel; QString data = index.model()->data(index, Qt::DisplayRole).toString(); - qDebug() << "Tentando pegar " << data; comboDelegate->setModel(model); int i; for(i = 0; i < model->rowCount(); i++){ diff --git a/qt-ui/models.cpp b/qt-ui/models.cpp index ee1ae78ac..3bbc79f72 100644 --- a/qt-ui/models.cpp +++ b/qt-ui/models.cpp @@ -67,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); @@ -160,7 +160,7 @@ int CylindersModel::rowCount(const QModelIndex& parent) const return rows; } -void CylindersModel::add(cylinder_t* cyl) +void CylindersModel::add() { if (rows >= MAX_CYLINDERS) { return; @@ -168,14 +168,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(); @@ -266,7 +258,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); @@ -331,18 +323,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(); diff --git a/qt-ui/models.h b/qt-ui/models.h index ded612bb9..b207ff0fd 100644 --- a/qt-ui/models.h +++ b/qt-ui/models.h @@ -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); |