mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
Desktop: automatically update dive information tab
Currently, the dive information tab was not updated when the user edited fields. The fields were only updated when switching between dives. Therefore, hook into the "divesChanged" signal and update the fields accordingly. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
98a3eb414b
commit
26edea7f71
2 changed files with 55 additions and 13 deletions
|
@ -10,6 +10,7 @@
|
||||||
TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation())
|
TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation())
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveInformation::divesChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
TabDiveInformation::~TabDiveInformation()
|
TabDiveInformation::~TabDiveInformation()
|
||||||
|
@ -35,20 +36,13 @@ void TabDiveInformation::clear()
|
||||||
ui->salinityText->clear();
|
ui->salinityText->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TabDiveInformation::updateData()
|
// Update fields that depend on the dive profile
|
||||||
|
void TabDiveInformation::updateProfile()
|
||||||
{
|
{
|
||||||
if (!current_dive) {
|
|
||||||
clear();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ui->maxcnsText->setText(QString("%1\%").arg(current_dive->maxcns));
|
ui->maxcnsText->setText(QString("%1\%").arg(current_dive->maxcns));
|
||||||
ui->otuText->setText(QString("%1").arg(current_dive->otu));
|
ui->otuText->setText(QString("%1").arg(current_dive->otu));
|
||||||
ui->maximumDepthText->setText(get_depth_string(current_dive->maxdepth, true));
|
ui->maximumDepthText->setText(get_depth_string(current_dive->maxdepth, true));
|
||||||
ui->averageDepthText->setText(get_depth_string(current_dive->meandepth, true));
|
ui->averageDepthText->setText(get_depth_string(current_dive->meandepth, true));
|
||||||
ui->dateText->setText(get_short_dive_date_string(current_dive->when));
|
|
||||||
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
|
||||||
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
|
||||||
|
|
||||||
volume_t gases[MAX_CYLINDERS] = {};
|
volume_t gases[MAX_CYLINDERS] = {};
|
||||||
get_gas_used(current_dive, gases);
|
get_gas_used(current_dive, gases);
|
||||||
|
@ -80,13 +74,31 @@ void TabDiveInformation::updateData()
|
||||||
ui->diveTimeText->setText(get_dive_duration_string(current_dive->duration.seconds, tr("h"), tr("min"), tr("sec"),
|
ui->diveTimeText->setText(get_dive_duration_string(current_dive->duration.seconds, tr("h"), tr("min"), tr("sec"),
|
||||||
" ", current_dive->dc.divemode == FREEDIVE));
|
" ", current_dive->dc.divemode == FREEDIVE));
|
||||||
|
|
||||||
|
ui->sacText->setText( mean[0] ? SACs : QString());
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update fields that depend on start of dive
|
||||||
|
void TabDiveInformation::updateWhen()
|
||||||
|
{
|
||||||
|
ui->dateText->setText(get_short_dive_date_string(current_dive->when));
|
||||||
timestamp_t surface_interval = get_surface_interval(current_dive->when);
|
timestamp_t surface_interval = get_surface_interval(current_dive->when);
|
||||||
if (surface_interval >= 0)
|
if (surface_interval >= 0)
|
||||||
ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min")));
|
ui->surfaceIntervalText->setText(get_dive_surfint_string(surface_interval, tr("d"), tr("h"), tr("min")));
|
||||||
else
|
else
|
||||||
ui->surfaceIntervalText->clear();
|
ui->surfaceIntervalText->clear();
|
||||||
|
}
|
||||||
|
|
||||||
ui->sacText->setText( mean[0] ? SACs : QString());
|
void TabDiveInformation::updateData()
|
||||||
|
{
|
||||||
|
if (!current_dive) {
|
||||||
|
clear();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
updateProfile();
|
||||||
|
updateWhen();
|
||||||
|
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
||||||
|
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
||||||
|
|
||||||
if (current_dive->surface_pressure.mbar) /* this is ALWAYS displayed in mbar */
|
if (current_dive->surface_pressure.mbar) /* this is ALWAYS displayed in mbar */
|
||||||
ui->airPressureText->setText(QString("%1mbar").arg(current_dive->surface_pressure.mbar));
|
ui->airPressureText->setText(QString("%1mbar").arg(current_dive->surface_pressure.mbar));
|
||||||
|
@ -97,5 +109,32 @@ void TabDiveInformation::updateData()
|
||||||
ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0));
|
ui->salinityText->setText(QString("%1g/ℓ").arg(current_dive->salinity / 10.0));
|
||||||
else
|
else
|
||||||
ui->salinityText->clear();
|
ui->salinityText->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
// This function gets called if a field gets updated by an undo command.
|
||||||
|
// Refresh the corresponding UI field.
|
||||||
|
void TabDiveInformation::divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field)
|
||||||
|
{
|
||||||
|
// If the current dive is not in list of changed dives, do nothing
|
||||||
|
if (!current_dive || !dives.contains(current_dive))
|
||||||
|
return;
|
||||||
|
|
||||||
|
switch(field) {
|
||||||
|
case DiveField::DURATION:
|
||||||
|
case DiveField::DEPTH:
|
||||||
|
case DiveField::MODE:
|
||||||
|
updateProfile();
|
||||||
|
break;
|
||||||
|
case DiveField::AIR_TEMP:
|
||||||
|
ui->airTemperatureText->setText(get_temperature_string(current_dive->airtemp, true));
|
||||||
|
break;
|
||||||
|
case DiveField::WATER_TEMP:
|
||||||
|
ui->waterTemperatureText->setText(get_temperature_string(current_dive->watertemp, true));
|
||||||
|
break;
|
||||||
|
case DiveField::DATETIME:
|
||||||
|
updateWhen();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#define TAB_DIVE_INFORMATION_H
|
#define TAB_DIVE_INFORMATION_H
|
||||||
|
|
||||||
#include "TabBase.h"
|
#include "TabBase.h"
|
||||||
|
#include "core/subsurface-qt/DiveListNotifier.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class TabDiveInformation;
|
class TabDiveInformation;
|
||||||
|
@ -15,10 +16,12 @@ public:
|
||||||
~TabDiveInformation();
|
~TabDiveInformation();
|
||||||
void updateData() override;
|
void updateData() override;
|
||||||
void clear() override;
|
void clear() override;
|
||||||
|
private slots:
|
||||||
|
void divesChanged(dive_trip *trip, const QVector<dive *> &dives, DiveField field);
|
||||||
private:
|
private:
|
||||||
Ui::TabDiveInformation *ui;
|
Ui::TabDiveInformation *ui;
|
||||||
|
void updateProfile();
|
||||||
|
void updateWhen();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue