summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/prefs-macros.h7
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.cpp17
-rw-r--r--core/subsurface-qt/SettingsObjectWrapper.h4
-rw-r--r--core/units.h5
-rw-r--r--desktop-widgets/preferences/preferences_units.cpp2
-rw-r--r--desktop-widgets/preferences/preferences_units.ui18
-rw-r--r--qt-models/divetripmodel.cpp54
-rw-r--r--qt-models/divetripmodel.h3
8 files changed, 94 insertions, 16 deletions
diff --git a/core/prefs-macros.h b/core/prefs-macros.h
index 9208fb82e..7648580ef 100644
--- a/core/prefs-macros.h
+++ b/core/prefs-macros.h
@@ -18,6 +18,13 @@
else \
prefs.units.field = default_prefs.units.field
+#define GET_UNIT_INT(name, field) \
+ v = s.value(QString(name)); \
+ if (v.isValid()) \
+ prefs.units.field = v.toInt(); \
+ else \
+ prefs.units.field = default_prefs.units.field
+
#define GET_BOOL(name, field) \
v = s.value(QString(name)); \
if (v.isValid()) \
diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp
index 4fcb96580..eb7cf0960 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.cpp
+++ b/core/subsurface-qt/SettingsObjectWrapper.cpp
@@ -1631,6 +1631,11 @@ int UnitsSettings::durationUnits() const
return prefs.units.duration_units;
}
+int UnitsSettings::showUnitsTable() const
+{
+ return prefs.units.show_units_table;
+}
+
QString UnitsSettings::unitSystem() const
{
return prefs.unit_system == METRIC ? QStringLiteral("metric")
@@ -1721,6 +1726,17 @@ void UnitsSettings::setDurationUnits(int value)
emit durationUnitChanged(value);
}
+void UnitsSettings::setShowUnitsTable(int value)
+{
+ if (value == prefs.units.show_units_table)
+ return;
+ QSettings s;
+ s.beginGroup(group);
+ s.setValue("show_units_table", value);
+ prefs.units.show_units_table = value;
+ emit showUnitsTableChanged(value);
+}
+
void UnitsSettings::setCoordinatesTraditional(bool value)
{
if (value == prefs.coordinates_traditional)
@@ -2197,6 +2213,7 @@ void SettingsObjectWrapper::load()
}
GET_UNIT("vertical_speed_time", vertical_speed_time, units::MINUTES, units::SECONDS);
GET_UNIT3("duration_units", duration_units, units::MIXED, units::ALWAYS_HOURS, units::DURATION);
+ GET_UNIT_INT("show_units_table", show_units_table);
GET_BOOL("coordinates", coordinates_traditional);
s.endGroup();
s.beginGroup("TecDetails");
diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h
index bbc762e28..146acfcce 100644
--- a/core/subsurface-qt/SettingsObjectWrapper.h
+++ b/core/subsurface-qt/SettingsObjectWrapper.h
@@ -513,6 +513,7 @@ class UnitsSettings : public QObject {
Q_PROPERTY(bool coordinates_traditional READ coordinatesTraditional WRITE setCoordinatesTraditional NOTIFY coordinatesTraditionalChanged)
Q_PROPERTY(int vertical_speed_time READ verticalSpeedTime WRITE setVerticalSpeedTime NOTIFY verticalSpeedTimeChanged)
Q_PROPERTY(int duration_units READ durationUnits WRITE setDurationUnits NOTIFY durationUnitChanged)
+ Q_PROPERTY(int show_units_table READ showUnitsTable WRITE setShowUnitsTable NOTIFY showUnitsTableChanged)
public:
UnitsSettings(QObject *parent = 0);
@@ -523,6 +524,7 @@ public:
int weight() const;
int verticalSpeedTime() const;
int durationUnits() const;
+ int showUnitsTable() const;
QString unitSystem() const;
bool coordinatesTraditional() const;
@@ -534,6 +536,7 @@ public slots:
void setWeight(int value);
void setVerticalSpeedTime(int value);
void setDurationUnits(int value);
+ void setShowUnitsTable(int value);
void setUnitSystem(const QString& value);
void setCoordinatesTraditional(bool value);
@@ -547,6 +550,7 @@ signals:
void unitSystemChanged(const QString& value);
void coordinatesTraditionalChanged(bool value);
void durationUnitChanged(int value);
+ void showUnitsTableChanged(int value);
private:
const QString group = QStringLiteral("Units");
};
diff --git a/core/units.h b/core/units.h
index 535103349..d44c50ab4 100644
--- a/core/units.h
+++ b/core/units.h
@@ -260,6 +260,7 @@ struct units {
MINUTES_ONLY,
ALWAYS_HOURS
} duration_units;
+ int show_units_table;
};
/*
@@ -272,13 +273,13 @@ struct units {
#define SI_UNITS \
{ \
.length = METERS, .volume = LITER, .pressure = BAR, .temperature = CELSIUS, .weight = KG, \
- .vertical_speed_time = MINUTES, .duration_units = MIXED \
+ .vertical_speed_time = MINUTES, .duration_units = MIXED, .show_units_table = false \
}
#define IMPERIAL_UNITS \
{ \
.length = FEET, .volume = CUFT, .pressure = PSI, .temperature = FAHRENHEIT, .weight = LBS, \
- .vertical_speed_time = MINUTES, .duration_units = MIXED \
+ .vertical_speed_time = MINUTES, .duration_units = MIXED, .show_units_table = false \
}
#ifdef __cplusplus
diff --git a/desktop-widgets/preferences/preferences_units.cpp b/desktop-widgets/preferences/preferences_units.cpp
index 9ff6eb0af..2ff09f192 100644
--- a/desktop-widgets/preferences/preferences_units.cpp
+++ b/desktop-widgets/preferences/preferences_units.cpp
@@ -43,6 +43,7 @@ void PreferencesUnits::refreshSettings()
ui->duration_mixed->setChecked(prefs.units.duration_units == units::MIXED);
ui->duration_no_hours->setChecked(prefs.units.duration_units == units::MINUTES_ONLY);
ui->duration_show_hours->setChecked(prefs.units.duration_units == units::ALWAYS_HOURS);
+ ui->show_units_table->setChecked(prefs.units.show_units_table);
}
void PreferencesUnits::syncSettings()
@@ -60,4 +61,5 @@ void PreferencesUnits::syncSettings()
units->setVerticalSpeedTime(ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
units->setCoordinatesTraditional(ui->gpsTraditional->isChecked());
units->setDurationUnits(ui->duration_mixed->isChecked() ? units::MIXED : (ui->duration_no_hours->isChecked() ? units::MINUTES_ONLY : units::ALWAYS_HOURS));
+ units->setShowUnitsTable(ui->show_units_table->isChecked());
}
diff --git a/desktop-widgets/preferences/preferences_units.ui b/desktop-widgets/preferences/preferences_units.ui
index 49ef80a22..d6c201d41 100644
--- a/desktop-widgets/preferences/preferences_units.ui
+++ b/desktop-widgets/preferences/preferences_units.ui
@@ -269,7 +269,23 @@
</widget>
</item>
<item>
- <widget class="QGroupBox" name="groupBox_11">
+ <widget class="QGroupBox" name="groupBox_divelist">
+ <property name="title">
+ <string>Dive list table</string>
+ </property>
+ <layout class="QHBoxLayout" name="horizontalLayout_2">
+ <item>
+ <widget class="QCheckBox" name="show_units_table">
+ <property name="text">
+ <string>Show units in dive list table</string>
+ </property>
+ </widget>
+ </item>
+ </layout>
+ </widget>
+ </item>
+ <item>
+ <widget class="QGroupBox" name="groupBox_gps">
<property name="title">
<string>GPS coordinates</string>
</property>
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index 5777ae88a..2a0b29449 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -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);
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index 24b215129..ec9b615b0 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -38,8 +38,11 @@ public:
QString displayDepth() const;
QString displayDepthWithUnit() const;
QString displayTemperature() const;
+ QString displayTemperatureWithUnit() const;
QString displayWeight() const;
+ QString displayWeightWithUnit() const;
QString displaySac() const;
+ QString displaySacWithUnit() const;
int countPhotos(dive *dive) const;
int weight() const;
QString icon_names[4];