mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
tab-widgets: pass current dive computer to delegates
Don't access the global current_dc, but pass it to the sensor and tank-use delegates, when the current dive or dive computer changes. The same pattern is already realized for the tank and weight models. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
32de8a1387
commit
19baae449d
6 changed files with 48 additions and 33 deletions
|
@ -51,7 +51,9 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0)
|
||||||
view->setColumnHidden(CylindersModel::SIZE_INT, true);
|
view->setColumnHidden(CylindersModel::SIZE_INT, true);
|
||||||
view->setColumnHidden(CylindersModel::SENSORS, true);
|
view->setColumnHidden(CylindersModel::SENSORS, true);
|
||||||
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
view->setItemDelegateForColumn(CylindersModel::TYPE, new TankInfoDelegate(this));
|
||||||
view->setItemDelegateForColumn(CylindersModel::USE, new TankUseDelegate(this));
|
auto tankUseDelegate = new TankUseDelegate(this);
|
||||||
|
tankUseDelegate->setCurrentDC(get_dive_dc(&displayed_dive, 0));
|
||||||
|
view->setItemDelegateForColumn(CylindersModel::USE, tankUseDelegate);
|
||||||
connect(ui.cylinderTableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addCylinder_clicked);
|
connect(ui.cylinderTableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addCylinder_clicked);
|
||||||
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
|
connect(ui.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
|
||||||
connect(cylinders, &CylindersModel::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
|
connect(cylinders, &CylindersModel::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
|
||||||
|
@ -543,7 +545,7 @@ PlannerWidgets::PlannerWidgets()
|
||||||
&plannerDetails, &PlannerDetails::setPlanNotes);
|
&plannerDetails, &PlannerDetails::setPlanNotes);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlannerWidgets::planDive()
|
void PlannerWidgets::planDive(dive *currentDive)
|
||||||
{
|
{
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
||||||
dc_number = 0;
|
dc_number = 0;
|
||||||
|
@ -552,11 +554,11 @@ void PlannerWidgets::planDive()
|
||||||
DivePlannerPointsModel::instance()->createSimpleDive(&displayed_dive);
|
DivePlannerPointsModel::instance()->createSimpleDive(&displayed_dive);
|
||||||
|
|
||||||
// plan the dive in the same mode as the currently selected one
|
// plan the dive in the same mode as the currently selected one
|
||||||
if (current_dive) {
|
if (currentDive) {
|
||||||
plannerSettingsWidget.setDiveMode(current_dive->dc.divemode);
|
plannerSettingsWidget.setDiveMode(currentDive->dc.divemode);
|
||||||
plannerSettingsWidget.setBailoutVisibility(current_dive->dc.divemode);
|
plannerSettingsWidget.setBailoutVisibility(currentDive->dc.divemode);
|
||||||
if (current_dive->salinity)
|
if (currentDive->salinity)
|
||||||
plannerWidget.setSalinity(current_dive->salinity);
|
plannerWidget.setSalinity(currentDive->salinity);
|
||||||
else // No salinity means salt water
|
else // No salinity means salt water
|
||||||
plannerWidget.setSalinity(SEAWATER_SALINITY);
|
plannerWidget.setSalinity(SEAWATER_SALINITY);
|
||||||
}
|
}
|
||||||
|
@ -565,13 +567,10 @@ void PlannerWidgets::planDive()
|
||||||
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when)); // This will reload the profile!
|
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when)); // This will reload the profile!
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlannerWidgets::replanDive()
|
void PlannerWidgets::replanDive(int currentDC)
|
||||||
{
|
{
|
||||||
if (!current_dive)
|
|
||||||
return;
|
|
||||||
copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now).
|
|
||||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
||||||
DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive, dc_number);
|
DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive, currentDC);
|
||||||
|
|
||||||
plannerWidget.setReplanButton(true);
|
plannerWidget.setReplanButton(true);
|
||||||
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when));
|
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when));
|
||||||
|
@ -580,7 +579,7 @@ void PlannerWidgets::replanDive()
|
||||||
if (displayed_dive.salinity)
|
if (displayed_dive.salinity)
|
||||||
plannerWidget.setSalinity(displayed_dive.salinity);
|
plannerWidget.setSalinity(displayed_dive.salinity);
|
||||||
reset_cylinders(&displayed_dive, true);
|
reset_cylinders(&displayed_dive, true);
|
||||||
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive, dc_number);
|
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive, currentDC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void PlannerWidgets::printDecoPlan()
|
void PlannerWidgets::printDecoPlan()
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
class QListView;
|
class QListView;
|
||||||
class QModelIndex;
|
class QModelIndex;
|
||||||
class DivePlannerPointsModel;
|
class DivePlannerPointsModel;
|
||||||
|
struct dive;
|
||||||
|
|
||||||
#include "ui_diveplanner.h"
|
#include "ui_diveplanner.h"
|
||||||
|
|
||||||
|
@ -75,8 +76,8 @@ class PlannerWidgets : public QObject {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
PlannerWidgets();
|
PlannerWidgets();
|
||||||
void planDive();
|
void planDive(dive *currentDive);
|
||||||
void replanDive();
|
void replanDive(int currentDC);
|
||||||
public
|
public
|
||||||
slots:
|
slots:
|
||||||
void printDecoPlan();
|
void printDecoPlan();
|
||||||
|
|
|
@ -664,8 +664,9 @@ void MainWindow::on_actionReplanDive_triggered()
|
||||||
setApplicationState(ApplicationState::PlanDive);
|
setApplicationState(ApplicationState::PlanDive);
|
||||||
|
|
||||||
disableShortcuts(true);
|
disableShortcuts(true);
|
||||||
profile->setPlanState(&displayed_dive, 0);
|
copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now).
|
||||||
plannerWidgets->replanDive();
|
profile->setPlanState(&displayed_dive, dc_number);
|
||||||
|
plannerWidgets->replanDive(dc_number);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionDivePlanner_triggered()
|
void MainWindow::on_actionDivePlanner_triggered()
|
||||||
|
@ -678,7 +679,7 @@ void MainWindow::on_actionDivePlanner_triggered()
|
||||||
|
|
||||||
disableShortcuts(true);
|
disableShortcuts(true);
|
||||||
profile->setPlanState(&displayed_dive, 0);
|
profile->setPlanState(&displayed_dive, 0);
|
||||||
plannerWidgets->planDive();
|
plannerWidgets->planDive(current_dive);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionAddDive_triggered()
|
void MainWindow::on_actionAddDive_triggered()
|
||||||
|
|
|
@ -250,27 +250,24 @@ void TankInfoDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHin
|
||||||
mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, CylindersModel::COMMIT_ROLE);
|
mymodel->setData(IDX(CylindersModel::TYPE), currCombo.activeText, CylindersModel::COMMIT_ROLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
TankUseDelegate::TankUseDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
TankUseDelegate::TankUseDelegate(QObject *parent) : QStyledItemDelegate(parent), currentdc(nullptr)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TankUseDelegate::setCurrentDC(divecomputer *dc)
|
||||||
|
{
|
||||||
|
currentdc = dc;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *TankUseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
|
QWidget *TankUseDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &) const
|
||||||
{
|
{
|
||||||
struct divecomputer *currentDc;
|
|
||||||
if (DivePlannerPointsModel::instance()->currentMode() != DivePlannerPointsModel::NOTHING) {
|
|
||||||
currentDc = &displayed_dive.dc;
|
|
||||||
} else {
|
|
||||||
currentDc = get_dive_dc(current_dive, dc_number);
|
|
||||||
}
|
|
||||||
QComboBox *comboBox = new QComboBox(parent);
|
QComboBox *comboBox = new QComboBox(parent);
|
||||||
if (!currentDc) {
|
if (!currentdc)
|
||||||
return comboBox;
|
return comboBox;
|
||||||
}
|
bool isCcrDive = currentdc->divemode == CCR;
|
||||||
bool isCcrDive = currentDc->divemode == CCR;
|
|
||||||
for (int i = 0; i < NUM_GAS_USE; i++) {
|
for (int i = 0; i < NUM_GAS_USE; i++) {
|
||||||
if (isCcrDive || (i != DILUENT && i != OXYGEN)) {
|
if (isCcrDive || (i != DILUENT && i != OXYGEN))
|
||||||
comboBox->addItem(gettextFromC::tr(cylinderuse_text[i]));
|
comboBox->addItem(gettextFromC::tr(cylinderuse_text[i]));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return comboBox;
|
return comboBox;
|
||||||
}
|
}
|
||||||
|
@ -288,16 +285,23 @@ void TankUseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c
|
||||||
model->setData(index, cylinderuse_from_text(qPrintable(comboBox->currentText())));
|
model->setData(index, cylinderuse_from_text(qPrintable(comboBox->currentText())));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
SensorDelegate::SensorDelegate(QObject *parent) : QStyledItemDelegate(parent), currentdc(nullptr)
|
||||||
SensorDelegate::SensorDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SensorDelegate::setCurrentDC(divecomputer *dc)
|
||||||
|
{
|
||||||
|
currentdc = dc;
|
||||||
|
}
|
||||||
|
|
||||||
QWidget *SensorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
QWidget *SensorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QComboBox *comboBox = new QComboBox(parent);
|
QComboBox *comboBox = new QComboBox(parent);
|
||||||
|
|
||||||
|
if (!currentdc)
|
||||||
|
return comboBox;
|
||||||
|
|
||||||
std::vector<int16_t> sensors;
|
std::vector<int16_t> sensors;
|
||||||
const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number);
|
|
||||||
for (int i = 0; i < currentdc->samples; ++i) {
|
for (int i = 0; i < currentdc->samples; ++i) {
|
||||||
auto &sample = currentdc->sample[i];
|
auto &sample = currentdc->sample[i];
|
||||||
for (int s = 0; s < MAX_SENSORS; ++s) {
|
for (int s = 0; s < MAX_SENSORS; ++s) {
|
||||||
|
|
|
@ -6,7 +6,9 @@
|
||||||
|
|
||||||
#include <QStyledItemDelegate>
|
#include <QStyledItemDelegate>
|
||||||
#include <QComboBox>
|
#include <QComboBox>
|
||||||
|
|
||||||
class QPainter;
|
class QPainter;
|
||||||
|
struct divecomputer;
|
||||||
|
|
||||||
class DiveListDelegate : public QStyledItemDelegate {
|
class DiveListDelegate : public QStyledItemDelegate {
|
||||||
public:
|
public:
|
||||||
|
@ -73,19 +75,23 @@ class TankUseDelegate : public QStyledItemDelegate {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit TankUseDelegate(QObject *parent = 0);
|
explicit TankUseDelegate(QObject *parent = 0);
|
||||||
|
void setCurrentDC(divecomputer *dc);
|
||||||
private:
|
private:
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
void setEditorData(QWidget *editor, const QModelIndex &index) const override;
|
||||||
|
divecomputer *currentdc;
|
||||||
};
|
};
|
||||||
|
|
||||||
class SensorDelegate : public QStyledItemDelegate {
|
class SensorDelegate : public QStyledItemDelegate {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
explicit SensorDelegate(QObject *parent = 0);
|
explicit SensorDelegate(QObject *parent = 0);
|
||||||
|
void setCurrentDC(divecomputer *dc);
|
||||||
private:
|
private:
|
||||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||||
|
divecomputer *currentdc;
|
||||||
};
|
};
|
||||||
|
|
||||||
class WSInfoDelegate : public ComboBoxDelegate {
|
class WSInfoDelegate : public ComboBoxDelegate {
|
||||||
|
|
|
@ -138,8 +138,12 @@ void TabDiveEquipment::toggleTriggeredColumn()
|
||||||
|
|
||||||
void TabDiveEquipment::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
void TabDiveEquipment::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||||
{
|
{
|
||||||
|
divecomputer *dc = get_dive_dc(currentDive, currentDC);
|
||||||
|
|
||||||
cylindersModel->updateDive(currentDive, currentDC);
|
cylindersModel->updateDive(currentDive, currentDC);
|
||||||
weightModel->updateDive(currentDive);
|
weightModel->updateDive(currentDive);
|
||||||
|
sensorDelegate.setCurrentDC(dc);
|
||||||
|
tankUseDelegate.setCurrentDC(dc);
|
||||||
|
|
||||||
if (currentDive && currentDive->suit)
|
if (currentDive && currentDive->suit)
|
||||||
ui.suit->setText(QString(currentDive->suit));
|
ui.suit->setText(QString(currentDive->suit));
|
||||||
|
|
Loading…
Add table
Reference in a new issue