mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-28 05:00:20 +00:00
core: activate qPrefUnits
remove Units from SettingsObjectWrapper and reference qPrefUnits update files using SettingsObjectWrapper/Units to use qPrefUnits this activated qPrefUnits and removed the similar class from SettingsObjectWrapper. Signed-off-by: Jan Iversen <jani@apache.org>
This commit is contained in:
parent
54335e1ec6
commit
affdc9d394
6 changed files with 51 additions and 304 deletions
|
@ -20,6 +20,7 @@ void qPref::loadSync(bool doSync)
|
|||
qPrefDiveComputer::instance()->loadSync(doSync);
|
||||
// qPrefFaceook does not use disk.
|
||||
qPrefProxy::instance()->loadSync(doSync);
|
||||
qPrefUnits::instance()->loadSync(doSync);
|
||||
}
|
||||
|
||||
const QString qPref::canonical_version() const
|
||||
|
|
|
@ -1138,191 +1138,6 @@ void DivePlannerSettings::setDecoMode(deco_mode value)
|
|||
emit decoModeChanged(value);
|
||||
}
|
||||
|
||||
UnitsSettings::UnitsSettings(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int UnitsSettings::length() const
|
||||
{
|
||||
return prefs.units.length;
|
||||
}
|
||||
|
||||
int UnitsSettings::pressure() const
|
||||
{
|
||||
return prefs.units.pressure;
|
||||
}
|
||||
|
||||
int UnitsSettings::volume() const
|
||||
{
|
||||
return prefs.units.volume;
|
||||
}
|
||||
|
||||
int UnitsSettings::temperature() const
|
||||
{
|
||||
return prefs.units.temperature;
|
||||
}
|
||||
|
||||
int UnitsSettings::weight() const
|
||||
{
|
||||
return prefs.units.weight;
|
||||
}
|
||||
|
||||
int UnitsSettings::verticalSpeedTime() const
|
||||
{
|
||||
return prefs.units.vertical_speed_time;
|
||||
}
|
||||
|
||||
int UnitsSettings::durationUnits() const
|
||||
{
|
||||
return prefs.units.duration_units;
|
||||
}
|
||||
|
||||
bool UnitsSettings::showUnitsTable() const
|
||||
{
|
||||
return prefs.units.show_units_table;
|
||||
}
|
||||
|
||||
QString UnitsSettings::unitSystem() const
|
||||
{
|
||||
return prefs.unit_system == METRIC ? QStringLiteral("metric")
|
||||
: prefs.unit_system == IMPERIAL ? QStringLiteral("imperial")
|
||||
: QStringLiteral("personalized");
|
||||
}
|
||||
|
||||
bool UnitsSettings::coordinatesTraditional() const
|
||||
{
|
||||
return prefs.coordinates_traditional;
|
||||
}
|
||||
|
||||
void UnitsSettings::setLength(int value)
|
||||
{
|
||||
if (value == prefs.units.length)
|
||||
return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("length", value);
|
||||
prefs.units.length = (units::LENGTH) value;
|
||||
emit lengthChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setPressure(int value)
|
||||
{
|
||||
if (value == prefs.units.pressure)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("pressure", value);
|
||||
prefs.units.pressure = (units::PRESSURE) value;
|
||||
emit pressureChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setVolume(int value)
|
||||
{
|
||||
if (value == prefs.units.volume)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("volume", value);
|
||||
prefs.units.volume = (units::VOLUME) value;
|
||||
emit volumeChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setTemperature(int value)
|
||||
{
|
||||
if (value == prefs.units.temperature)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("temperature", value);
|
||||
prefs.units.temperature = (units::TEMPERATURE) value;
|
||||
emit temperatureChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setWeight(int value)
|
||||
{
|
||||
if (value == prefs.units.weight)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("weight", value);
|
||||
prefs.units.weight = (units::WEIGHT) value;
|
||||
emit weightChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setVerticalSpeedTime(int value)
|
||||
{
|
||||
if (value == prefs.units.vertical_speed_time)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("vertical_speed_time", value);
|
||||
prefs.units.vertical_speed_time = (units::TIME) value;
|
||||
emit verticalSpeedTimeChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setDurationUnits(int value)
|
||||
{
|
||||
if (value == prefs.units.duration_units)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("duration_units", value);
|
||||
prefs.units.duration_units = (units::DURATION) value;
|
||||
emit durationUnitChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setShowUnitsTable(bool 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)
|
||||
return;
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("coordinates", value);
|
||||
prefs.coordinates_traditional = value;
|
||||
emit coordinatesTraditionalChanged(value);
|
||||
}
|
||||
|
||||
void UnitsSettings::setUnitSystem(const QString& value)
|
||||
{
|
||||
short int v = value == QStringLiteral("metric") ? METRIC
|
||||
: value == QStringLiteral("imperial")? IMPERIAL
|
||||
: PERSONALIZE;
|
||||
|
||||
if (v == prefs.unit_system)
|
||||
return;
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup(group);
|
||||
s.setValue("unit_system", value);
|
||||
|
||||
if (value == QStringLiteral("metric")) {
|
||||
prefs.unit_system = METRIC;
|
||||
prefs.units = SI_units;
|
||||
} else if (value == QStringLiteral("imperial")) {
|
||||
prefs.unit_system = IMPERIAL;
|
||||
prefs.units = IMPERIAL_units;
|
||||
} else {
|
||||
prefs.unit_system = PERSONALIZE;
|
||||
}
|
||||
|
||||
emit unitSystemChanged(value);
|
||||
// TODO: emit the other values here?
|
||||
}
|
||||
|
||||
GeneralSettingsObjectWrapper::GeneralSettingsObjectWrapper(QObject *parent) :
|
||||
QObject(parent)
|
||||
{
|
||||
|
@ -1714,7 +1529,7 @@ QObject(parent),
|
|||
proxy(new qPrefProxy(this)),
|
||||
cloud_storage(new qPrefCloudStorage(this)),
|
||||
planner_settings(new DivePlannerSettings(this)),
|
||||
unit_settings(new UnitsSettings(this)),
|
||||
unit_settings(new qPrefUnits(this)),
|
||||
general_settings(new GeneralSettingsObjectWrapper(this)),
|
||||
display_settings(new qPrefDisplay(this)),
|
||||
language_settings(new LanguageSettingsObjectWrapper(this)),
|
||||
|
@ -1731,26 +1546,9 @@ void SettingsObjectWrapper::load()
|
|||
QVariant v;
|
||||
|
||||
uiLanguage(NULL);
|
||||
s.beginGroup("Units");
|
||||
if (s.value("unit_system").toString() == "metric") {
|
||||
prefs.unit_system = METRIC;
|
||||
prefs.units = SI_units;
|
||||
} else if (s.value("unit_system").toString() == "imperial") {
|
||||
prefs.unit_system = IMPERIAL;
|
||||
prefs.units = IMPERIAL_units;
|
||||
} else {
|
||||
prefs.unit_system = PERSONALIZE;
|
||||
GET_UNIT("length", length, units::FEET, units::METERS);
|
||||
GET_UNIT("pressure", pressure, units::PSI, units::BAR);
|
||||
GET_UNIT("volume", volume, units::CUFT, units::LITER);
|
||||
GET_UNIT("temperature", temperature, units::FAHRENHEIT, units::CELSIUS);
|
||||
GET_UNIT("weight", weight, units::LBS, units::KG);
|
||||
}
|
||||
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_BOOL("show_units_table", show_units_table);
|
||||
GET_BOOL("coordinates", coordinates_traditional);
|
||||
s.endGroup();
|
||||
|
||||
qPrefUnits::instance()->load();
|
||||
|
||||
s.beginGroup("TecDetails");
|
||||
GET_BOOL("po2graph", pp_graphs.po2);
|
||||
GET_BOOL("pn2graph", pp_graphs.pn2);
|
||||
|
|
|
@ -343,59 +343,6 @@ private:
|
|||
const QString group = QStringLiteral("Planner");
|
||||
};
|
||||
|
||||
class UnitsSettings : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(int length READ length WRITE setLength NOTIFY lengthChanged)
|
||||
Q_PROPERTY(int pressure READ pressure WRITE setPressure NOTIFY pressureChanged)
|
||||
Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged)
|
||||
Q_PROPERTY(int temperature READ temperature WRITE setTemperature NOTIFY temperatureChanged)
|
||||
Q_PROPERTY(int weight READ weight WRITE setWeight NOTIFY weightChanged)
|
||||
Q_PROPERTY(QString unit_system READ unitSystem WRITE setUnitSystem NOTIFY unitSystemChanged)
|
||||
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(bool show_units_table READ showUnitsTable WRITE setShowUnitsTable NOTIFY showUnitsTableChanged)
|
||||
|
||||
public:
|
||||
UnitsSettings(QObject *parent = 0);
|
||||
int length() const;
|
||||
int pressure() const;
|
||||
int volume() const;
|
||||
int temperature() const;
|
||||
int weight() const;
|
||||
int verticalSpeedTime() const;
|
||||
int durationUnits() const;
|
||||
bool showUnitsTable() const;
|
||||
QString unitSystem() const;
|
||||
bool coordinatesTraditional() const;
|
||||
|
||||
public slots:
|
||||
void setLength(int value);
|
||||
void setPressure(int value);
|
||||
void setVolume(int value);
|
||||
void setTemperature(int value);
|
||||
void setWeight(int value);
|
||||
void setVerticalSpeedTime(int value);
|
||||
void setDurationUnits(int value);
|
||||
void setShowUnitsTable(bool value);
|
||||
void setUnitSystem(const QString& value);
|
||||
void setCoordinatesTraditional(bool value);
|
||||
|
||||
signals:
|
||||
void lengthChanged(int value);
|
||||
void pressureChanged(int value);
|
||||
void volumeChanged(int value);
|
||||
void temperatureChanged(int value);
|
||||
void weightChanged(int value);
|
||||
void verticalSpeedTimeChanged(int value);
|
||||
void unitSystemChanged(const QString& value);
|
||||
void coordinatesTraditionalChanged(bool value);
|
||||
void durationUnitChanged(int value);
|
||||
void showUnitsTableChanged(bool value);
|
||||
private:
|
||||
const QString group = QStringLiteral("Units");
|
||||
};
|
||||
|
||||
class GeneralSettingsObjectWrapper : public QObject {
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged)
|
||||
|
@ -526,7 +473,7 @@ class SettingsObjectWrapper : public QObject {
|
|||
Q_PROPERTY(qPrefProxy* proxy MEMBER proxy CONSTANT)
|
||||
Q_PROPERTY(qPrefCloudStorage* cloud_storage MEMBER cloud_storage CONSTANT)
|
||||
Q_PROPERTY(DivePlannerSettings* planner MEMBER planner_settings CONSTANT)
|
||||
Q_PROPERTY(UnitsSettings* units MEMBER unit_settings CONSTANT)
|
||||
Q_PROPERTY(qPrefUnits* units MEMBER unit_settings CONSTANT)
|
||||
|
||||
Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT)
|
||||
Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT)
|
||||
|
@ -546,7 +493,7 @@ public:
|
|||
qPrefProxy *proxy;
|
||||
qPrefCloudStorage *cloud_storage;
|
||||
DivePlannerSettings *planner_settings;
|
||||
UnitsSettings *unit_settings;
|
||||
qPrefUnits *unit_settings;
|
||||
GeneralSettingsObjectWrapper *general_settings;
|
||||
qPrefDisplay *display_settings;
|
||||
LanguageSettingsObjectWrapper *language_settings;
|
||||
|
|
|
@ -51,14 +51,14 @@ void PreferencesUnits::syncSettings()
|
|||
QString unitSystem[] = {"metric", "imperial", "personal"};
|
||||
short unitValue = ui->metric->isChecked() ? METRIC : (ui->imperial->isChecked() ? IMPERIAL : PERSONALIZE);
|
||||
|
||||
units->setUnitSystem(unitSystem[unitValue]);
|
||||
units->setTemperature(ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
|
||||
units->setLength(ui->feet->isChecked() ? units::FEET : units::METERS);
|
||||
units->setPressure(ui->psi->isChecked() ? units::PSI : units::BAR);
|
||||
units->setVolume(ui->cuft->isChecked() ? units::CUFT : units::LITER);
|
||||
units->setWeight(ui->lbs->isChecked() ? units::LBS : units::KG);
|
||||
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());
|
||||
units->set_unit_system(unitSystem[unitValue]);
|
||||
units->set_temperature(ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
|
||||
units->set_length(ui->feet->isChecked() ? units::FEET : units::METERS);
|
||||
units->set_pressure(ui->psi->isChecked() ? units::PSI : units::BAR);
|
||||
units->set_volume(ui->cuft->isChecked() ? units::CUFT : units::LITER);
|
||||
units->set_weight(ui->lbs->isChecked() ? units::LBS : units::KG);
|
||||
units->set_vertical_speed_time(ui->vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS);
|
||||
units->set_coordinates_traditional(ui->gpsTraditional->isChecked());
|
||||
units->set_duration_units(ui->duration_mixed->isChecked() ? units::MIXED : (ui->duration_no_hours->isChecked() ? units::MINUTES_ONLY : units::ALWAYS_HOURS));
|
||||
units->set_show_units_table(ui->show_units_table->isChecked());
|
||||
}
|
||||
|
|
|
@ -162,6 +162,7 @@ void register_qml_types()
|
|||
REGISTER_TYPE(qPrefDiveComputer, "SsrfDiveComputerPrefs");
|
||||
REGISTER_TYPE(qPrefFacebook, "SsrfFacebookPrefs");
|
||||
REGISTER_TYPE(qPrefProxy, "SsrfProxyPrefs");
|
||||
REGISTER_TYPE(qPrefUnits, "SsrfUnitPrefs");
|
||||
|
||||
#ifndef SUBSURFACE_TEST_DATA
|
||||
#ifdef SUBSURFACE_MOBILE
|
||||
|
|
|
@ -278,42 +278,42 @@ void TestPreferences::testPreferences()
|
|||
|
||||
TEST(planner->decoMode(), RECREATIONAL);
|
||||
|
||||
auto units = pref->unit_settings;
|
||||
units->setLength(0);
|
||||
units->setPressure(0);
|
||||
units->setVolume(0);
|
||||
units->setTemperature(0);
|
||||
units->setWeight(0);
|
||||
units->setVerticalSpeedTime(0);
|
||||
units->setUnitSystem(QStringLiteral("metric"));
|
||||
units->setCoordinatesTraditional(false);
|
||||
auto units = qPrefUnits::instance();
|
||||
units->set_length(units::METERS);
|
||||
units->set_pressure(units::BAR);
|
||||
units->set_volume(units::LITER);
|
||||
units->set_temperature(units::CELSIUS);
|
||||
units->set_weight(units::KG);
|
||||
units->set_vertical_speed_time(units::SECONDS);
|
||||
units->set_unit_system(QStringLiteral("metric"));
|
||||
units->set_coordinates_traditional(false);
|
||||
|
||||
TEST(units->length(), 0);
|
||||
TEST(units->pressure(), 0);
|
||||
TEST(units->volume(), 0);
|
||||
TEST(units->temperature(), 0);
|
||||
TEST(units->weight(), 0);
|
||||
TEST(units->verticalSpeedTime(), 0);
|
||||
TEST(units->unitSystem(), QStringLiteral("metric"));
|
||||
TEST(units->coordinatesTraditional(), false);
|
||||
TEST(units->length(), units::METERS);
|
||||
TEST(units->pressure(), units::BAR);
|
||||
TEST(units->volume(), units::LITER);
|
||||
TEST(units->temperature(), units::CELSIUS);
|
||||
TEST(units->weight(), units::KG);
|
||||
TEST(units->vertical_speed_time(), units::SECONDS);
|
||||
TEST(units->unit_system(), QStringLiteral("metric"));
|
||||
TEST(units->coordinates_traditional(), false);
|
||||
|
||||
units->setLength(1);
|
||||
units->setPressure(1);
|
||||
units->setVolume(1);
|
||||
units->setTemperature(1);
|
||||
units->setWeight(1);
|
||||
units->setVerticalSpeedTime(1);
|
||||
units->setUnitSystem(QStringLiteral("fake-metric-system"));
|
||||
units->setCoordinatesTraditional(true);
|
||||
units->set_length(units::FEET);
|
||||
units->set_pressure(units::PSI);
|
||||
units->set_volume(units::CUFT);
|
||||
units->set_temperature(units::FAHRENHEIT);
|
||||
units->set_weight(units::LBS);
|
||||
units->set_vertical_speed_time(units::MINUTES);
|
||||
units->set_unit_system(QStringLiteral("fake-metric-system"));
|
||||
units->set_coordinates_traditional(true);
|
||||
|
||||
TEST(units->length(), 1);
|
||||
TEST(units->pressure(), 1);
|
||||
TEST(units->volume(), 1);
|
||||
TEST(units->temperature(), 1);
|
||||
TEST(units->weight(), 1);
|
||||
TEST(units->verticalSpeedTime(), 1);
|
||||
TEST(units->unitSystem(), QStringLiteral("personalized"));
|
||||
TEST(units->coordinatesTraditional(), true);
|
||||
TEST(units->length(), units::FEET);
|
||||
TEST(units->pressure(), units::PSI);
|
||||
TEST(units->volume(), units::CUFT);
|
||||
TEST(units->temperature(), units::FAHRENHEIT);
|
||||
TEST(units->weight(), units::LBS);
|
||||
TEST(units->vertical_speed_time(), units::MINUTES);
|
||||
TEST(units->unit_system(), QStringLiteral("personalized"));
|
||||
TEST(units->coordinates_traditional(), true);
|
||||
|
||||
auto general = pref->general_settings;
|
||||
general->setDefaultFilename("filename");
|
||||
|
|
Loading…
Reference in a new issue