mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +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::SENSORS, true);
|
||||
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.tableWidget, &TableView::addButtonClicked, plannerModel, &DivePlannerPointsModel::addDefaultStop);
|
||||
connect(cylinders, &CylindersModel::dataChanged, GasSelectionModel::instance(), &GasSelectionModel::repopulate);
|
||||
|
@ -543,7 +545,7 @@ PlannerWidgets::PlannerWidgets()
|
|||
&plannerDetails, &PlannerDetails::setPlanNotes);
|
||||
}
|
||||
|
||||
void PlannerWidgets::planDive()
|
||||
void PlannerWidgets::planDive(dive *currentDive)
|
||||
{
|
||||
DivePlannerPointsModel::instance()->setPlanMode(DivePlannerPointsModel::PLAN);
|
||||
dc_number = 0;
|
||||
|
@ -552,11 +554,11 @@ void PlannerWidgets::planDive()
|
|||
DivePlannerPointsModel::instance()->createSimpleDive(&displayed_dive);
|
||||
|
||||
// plan the dive in the same mode as the currently selected one
|
||||
if (current_dive) {
|
||||
plannerSettingsWidget.setDiveMode(current_dive->dc.divemode);
|
||||
plannerSettingsWidget.setBailoutVisibility(current_dive->dc.divemode);
|
||||
if (current_dive->salinity)
|
||||
plannerWidget.setSalinity(current_dive->salinity);
|
||||
if (currentDive) {
|
||||
plannerSettingsWidget.setDiveMode(currentDive->dc.divemode);
|
||||
plannerSettingsWidget.setBailoutVisibility(currentDive->dc.divemode);
|
||||
if (currentDive->salinity)
|
||||
plannerWidget.setSalinity(currentDive->salinity);
|
||||
else // No salinity means salt water
|
||||
plannerWidget.setSalinity(SEAWATER_SALINITY);
|
||||
}
|
||||
|
@ -565,13 +567,10 @@ void PlannerWidgets::planDive()
|
|||
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()->loadFromDive(&displayed_dive, dc_number);
|
||||
DivePlannerPointsModel::instance()->loadFromDive(&displayed_dive, currentDC);
|
||||
|
||||
plannerWidget.setReplanButton(true);
|
||||
plannerWidget.setupStartTime(timestampToDateTime(displayed_dive.when));
|
||||
|
@ -580,7 +579,7 @@ void PlannerWidgets::replanDive()
|
|||
if (displayed_dive.salinity)
|
||||
plannerWidget.setSalinity(displayed_dive.salinity);
|
||||
reset_cylinders(&displayed_dive, true);
|
||||
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive, dc_number);
|
||||
DivePlannerPointsModel::instance()->cylindersModel()->updateDive(&displayed_dive, currentDC);
|
||||
}
|
||||
|
||||
void PlannerWidgets::printDecoPlan()
|
||||
|
|
|
@ -9,6 +9,7 @@
|
|||
class QListView;
|
||||
class QModelIndex;
|
||||
class DivePlannerPointsModel;
|
||||
struct dive;
|
||||
|
||||
#include "ui_diveplanner.h"
|
||||
|
||||
|
@ -75,8 +76,8 @@ class PlannerWidgets : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
PlannerWidgets();
|
||||
void planDive();
|
||||
void replanDive();
|
||||
void planDive(dive *currentDive);
|
||||
void replanDive(int currentDC);
|
||||
public
|
||||
slots:
|
||||
void printDecoPlan();
|
||||
|
|
|
@ -664,8 +664,9 @@ void MainWindow::on_actionReplanDive_triggered()
|
|||
setApplicationState(ApplicationState::PlanDive);
|
||||
|
||||
disableShortcuts(true);
|
||||
profile->setPlanState(&displayed_dive, 0);
|
||||
plannerWidgets->replanDive();
|
||||
copy_dive(current_dive, &displayed_dive); // Planning works on a copy of the dive (for now).
|
||||
profile->setPlanState(&displayed_dive, dc_number);
|
||||
plannerWidgets->replanDive(dc_number);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionDivePlanner_triggered()
|
||||
|
@ -678,7 +679,7 @@ void MainWindow::on_actionDivePlanner_triggered()
|
|||
|
||||
disableShortcuts(true);
|
||||
profile->setPlanState(&displayed_dive, 0);
|
||||
plannerWidgets->planDive();
|
||||
plannerWidgets->planDive(current_dive);
|
||||
}
|
||||
|
||||
void MainWindow::on_actionAddDive_triggered()
|
||||
|
|
|
@ -250,28 +250,25 @@ void TankInfoDelegate::editorClosed(QWidget *, QAbstractItemDelegate::EndEditHin
|
|||
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
|
||||
{
|
||||
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);
|
||||
if (!currentDc) {
|
||||
if (!currentdc)
|
||||
return comboBox;
|
||||
}
|
||||
bool isCcrDive = currentDc->divemode == CCR;
|
||||
bool isCcrDive = currentdc->divemode == CCR;
|
||||
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]));
|
||||
}
|
||||
}
|
||||
return comboBox;
|
||||
}
|
||||
|
||||
|
@ -288,16 +285,23 @@ void TankUseDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, c
|
|||
model->setData(index, cylinderuse_from_text(qPrintable(comboBox->currentText())));
|
||||
}
|
||||
|
||||
|
||||
SensorDelegate::SensorDelegate(QObject *parent) : QStyledItemDelegate(parent)
|
||||
SensorDelegate::SensorDelegate(QObject *parent) : QStyledItemDelegate(parent), currentdc(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
void SensorDelegate::setCurrentDC(divecomputer *dc)
|
||||
{
|
||||
currentdc = dc;
|
||||
}
|
||||
|
||||
QWidget *SensorDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &, const QModelIndex &index) const
|
||||
{
|
||||
QComboBox *comboBox = new QComboBox(parent);
|
||||
|
||||
if (!currentdc)
|
||||
return comboBox;
|
||||
|
||||
std::vector<int16_t> sensors;
|
||||
const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number);
|
||||
for (int i = 0; i < currentdc->samples; ++i) {
|
||||
auto &sample = currentdc->sample[i];
|
||||
for (int s = 0; s < MAX_SENSORS; ++s) {
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
#include <QStyledItemDelegate>
|
||||
#include <QComboBox>
|
||||
|
||||
class QPainter;
|
||||
struct divecomputer;
|
||||
|
||||
class DiveListDelegate : public QStyledItemDelegate {
|
||||
public:
|
||||
|
@ -73,19 +75,23 @@ class TankUseDelegate : public QStyledItemDelegate {
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit TankUseDelegate(QObject *parent = 0);
|
||||
void setCurrentDC(divecomputer *dc);
|
||||
private:
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, 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;
|
||||
divecomputer *currentdc;
|
||||
};
|
||||
|
||||
class SensorDelegate : public QStyledItemDelegate {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit SensorDelegate(QObject *parent = 0);
|
||||
void setCurrentDC(divecomputer *dc);
|
||||
private:
|
||||
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override;
|
||||
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
|
||||
divecomputer *currentdc;
|
||||
};
|
||||
|
||||
class WSInfoDelegate : public ComboBoxDelegate {
|
||||
|
|
|
@ -138,8 +138,12 @@ void TabDiveEquipment::toggleTriggeredColumn()
|
|||
|
||||
void TabDiveEquipment::updateData(const std::vector<dive *> &, dive *currentDive, int currentDC)
|
||||
{
|
||||
divecomputer *dc = get_dive_dc(currentDive, currentDC);
|
||||
|
||||
cylindersModel->updateDive(currentDive, currentDC);
|
||||
weightModel->updateDive(currentDive);
|
||||
sensorDelegate.setCurrentDC(dc);
|
||||
tankUseDelegate.setCurrentDC(dc);
|
||||
|
||||
if (currentDive && currentDive->suit)
|
||||
ui.suit->setText(QString(currentDive->suit));
|
||||
|
|
Loading…
Reference in a new issue