mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Display units in dive list table based on prefs option
Add a preferences option which enables or disables display of units in the main dive liste table. Signed-off-by: Stefan Fuchs <sfuchs@gmx.de>
This commit is contained in:
parent
2cb5d45231
commit
78cda85444
8 changed files with 94 additions and 16 deletions
|
@ -157,16 +157,16 @@ QVariant DiveItem::data(int column, int role) const
|
|||
retVal = displayDate();
|
||||
break;
|
||||
case DEPTH:
|
||||
retVal = displayDepth();
|
||||
retVal = prefs.units.show_units_table ? displayDepthWithUnit() : displayDepth();
|
||||
break;
|
||||
case DURATION:
|
||||
retVal = displayDuration();
|
||||
break;
|
||||
case TEMPERATURE:
|
||||
retVal = displayTemperature();
|
||||
retVal = prefs.units.show_units_table ? retVal = displayTemperatureWithUnit() : displayTemperature();
|
||||
break;
|
||||
case TOTALWEIGHT:
|
||||
retVal = displayWeight();
|
||||
retVal = prefs.units.show_units_table ? retVal = displayWeightWithUnit() : displayWeight();
|
||||
break;
|
||||
case SUIT:
|
||||
retVal = QString(dive->suit);
|
||||
|
@ -175,13 +175,16 @@ QVariant DiveItem::data(int column, int role) const
|
|||
retVal = QString(dive->cylinder[0].type.description);
|
||||
break;
|
||||
case SAC:
|
||||
retVal = displaySac();
|
||||
retVal = prefs.units.show_units_table ? retVal = displaySacWithUnit() : displaySac();
|
||||
break;
|
||||
case OTU:
|
||||
retVal = dive->otu;
|
||||
break;
|
||||
case MAXCNS:
|
||||
retVal = dive->maxcns;
|
||||
if (prefs.units.show_units_table)
|
||||
retVal = QString("%1%").arg(dive->maxcns);
|
||||
else
|
||||
retVal = dive->maxcns;
|
||||
break;
|
||||
case PHOTOS:
|
||||
break;
|
||||
|
@ -359,9 +362,10 @@ int DiveItem::countPhotos(dive *dive) const
|
|||
QString DiveItem::displayDuration() const
|
||||
{
|
||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
return get_dive_duration_string(dive->duration.seconds, "", "", "", ":", dive->dc.divemode == FREEDIVE);
|
||||
// Next line is test for alternative display with units
|
||||
// return get_dive_duration_string(dive->duration.seconds, tr("h"), tr("min"), "", ":", dive->dc.divemode == FREEDIVE);
|
||||
if (prefs.units.show_units_table)
|
||||
return get_dive_duration_string(dive->duration.seconds, tr("h"), tr("min"), "", ":", dive->dc.divemode == FREEDIVE);
|
||||
else
|
||||
return get_dive_duration_string(dive->duration.seconds, "", "", "", ":", dive->dc.divemode == FREEDIVE);
|
||||
}
|
||||
|
||||
QString DiveItem::displayTemperature() const
|
||||
|
@ -370,11 +374,16 @@ QString DiveItem::displayTemperature() const
|
|||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
if (!dive->watertemp.mkelvin)
|
||||
return str;
|
||||
if (get_units()->temperature == units::CELSIUS)
|
||||
str = QString::number(mkelvin_to_C(dive->watertemp.mkelvin), 'f', 1);
|
||||
else
|
||||
str = QString::number(mkelvin_to_F(dive->watertemp.mkelvin), 'f', 1);
|
||||
return str;
|
||||
return get_temperature_string(dive->watertemp, false);
|
||||
}
|
||||
|
||||
QString DiveItem::displayTemperatureWithUnit() const
|
||||
{
|
||||
QString str;
|
||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
if (!dive->watertemp.mkelvin)
|
||||
return str;
|
||||
return get_temperature_string(dive->watertemp, true);
|
||||
}
|
||||
|
||||
QString DiveItem::displaySac() const
|
||||
|
@ -390,12 +399,31 @@ QString DiveItem::displaySac() const
|
|||
return QString("");
|
||||
}
|
||||
|
||||
QString DiveItem::displaySacWithUnit() const
|
||||
{
|
||||
QString str;
|
||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
if (dive->sac) {
|
||||
const char *unit;
|
||||
int decimal;
|
||||
double value = get_volume_units(dive->sac, &decimal, &unit);
|
||||
return QString::number(value, 'f', decimal) + QString(unit).append(tr("/min"));
|
||||
}
|
||||
return QString("");
|
||||
}
|
||||
|
||||
QString DiveItem::displayWeight() const
|
||||
{
|
||||
QString str = weight_string(weight());
|
||||
return str;
|
||||
}
|
||||
|
||||
QString DiveItem::displayWeightWithUnit() const
|
||||
{
|
||||
QString str = weight_string(weight()) + ((get_units()->weight == units::KG) ? tr("kg") : tr("lbs"));
|
||||
return str;
|
||||
}
|
||||
|
||||
int DiveItem::weight() const
|
||||
{
|
||||
struct dive *dive = get_dive_by_uniq_id(diveId);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue