Correctly implement Metric / Imperial / Personalize preference

The code so far had completely ignored Metric / Imperial. Turning this
into a three way radio box seemed to make much more sense.

Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Dirk Hohndel 2013-06-02 19:52:18 +09:00
parent 9a65798daf
commit a98a7a1351
3 changed files with 51 additions and 9 deletions

View file

@ -376,11 +376,17 @@ void MainWindow::readSettings()
settings.endGroup(); settings.endGroup();
settings.beginGroup("Units"); settings.beginGroup("Units");
GET_UNIT(v, "length", length, units::FEET, units::METERS); if (settings.value("unit_system").toString() == "metric") {
GET_UNIT(v, "pressure", pressure, units::PSI, units::BAR); prefs.units = SI_units;
GET_UNIT(v, "volume", volume, units::CUFT, units::LITER); } else if (settings.value("unit_system").toString() == "imperial") {
GET_UNIT(v, "temperature", temperature, units::FAHRENHEIT, units::CELSIUS); prefs.units = IMPERIAL_units;
GET_UNIT(v, "weight", weight, units::LBS, units::KG); } else {
GET_UNIT(v, "length", length, units::FEET, units::METERS);
GET_UNIT(v, "pressure", pressure, units::PSI, units::BAR);
GET_UNIT(v, "volume", volume, units::CUFT, units::LITER);
GET_UNIT(v, "temperature", temperature, units::FAHRENHEIT, units::CELSIUS);
GET_UNIT(v, "weight", weight, units::LBS, units::KG);
}
settings.endGroup(); settings.endGroup();
settings.beginGroup("DisplayListColumns"); settings.beginGroup("DisplayListColumns");
GET_BOOL(v, "CYLINDER", prefs.visible_cols.cylinder); GET_BOOL(v, "CYLINDER", prefs.visible_cols.cylinder);

View file

@ -1,6 +1,7 @@
#include "preferences.h" #include "preferences.h"
#include "ui_preferences.h" #include "ui_preferences.h"
#include <QSettings> #include <QSettings>
#include <QDebug>
PreferencesDialog* PreferencesDialog::instance() PreferencesDialog* PreferencesDialog::instance()
{ {
@ -43,6 +44,7 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDial
ui->increment_3m->setChecked(B(calcceiling3m, calc_ceiling_3m_incr)); ui->increment_3m->setChecked(B(calcceiling3m, calc_ceiling_3m_incr));
ui->all_tissues->setEnabled(ui->calculated_ceiling->isChecked()); ui->all_tissues->setEnabled(ui->calculated_ceiling->isChecked());
ui->all_tissues->setChecked(B(calcalltissues, calc_all_tissues)); ui->all_tissues->setChecked(B(calcalltissues, calc_all_tissues));
ui->groupBox->setEnabled(ui->personalize->isChecked());
ui->gflow->setValue((int)(I(gflow, gflow))); ui->gflow->setValue((int)(I(gflow, gflow)));
ui->gfhigh->setValue((int)(I(gfhigh, gfhigh))); ui->gfhigh->setValue((int)(I(gfhigh, gfhigh)));
@ -121,7 +123,8 @@ void PreferencesDialog::syncSettings()
// Units // Units
s.beginGroup("Units"); s.beginGroup("Units");
s.setValue("units_metric", ui->metric->isChecked()); QString unitSystem = ui->metric->isChecked() ? "metric" : (ui->imperial->isChecked() ? "imperial" : "personal");
s.setValue("unit_system", unitSystem);
s.setValue("temperature", ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS); s.setValue("temperature", ui->fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS);
s.setValue("length", ui->feet->isChecked() ? units::FEET : units::METERS); s.setValue("length", ui->feet->isChecked() ? units::FEET : units::METERS);
s.setValue("pressure", ui->psi->isChecked() ? units::PSI : units::BAR); s.setValue("pressure", ui->psi->isChecked() ? units::PSI : units::BAR);

View file

@ -116,7 +116,7 @@
</sizepolicy> </sizepolicy>
</property> </property>
<property name="currentIndex"> <property name="currentIndex">
<number>2</number> <number>1</number>
</property> </property>
<widget class="QWidget" name="page_2"> <widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3"> <layout class="QVBoxLayout" name="verticalLayout_3">
@ -224,6 +224,9 @@
<property name="text"> <property name="text">
<string>Metric</string> <string>Metric</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_6</string>
</attribute>
</widget> </widget>
</item> </item>
<item> <item>
@ -231,6 +234,19 @@
<property name="text"> <property name="text">
<string>Imperial</string> <string>Imperial</string>
</property> </property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_6</string>
</attribute>
</widget>
</item>
<item>
<widget class="QRadioButton" name="personalize">
<property name="text">
<string>Personalize</string>
</property>
<attribute name="buttonGroup">
<string notr="true">buttonGroup_6</string>
</attribute>
</widget> </widget>
</item> </item>
</layout> </layout>
@ -238,10 +254,10 @@
<item> <item>
<widget class="QGroupBox" name="groupBox"> <widget class="QGroupBox" name="groupBox">
<property name="title"> <property name="title">
<string>Personalize</string> <string/>
</property> </property>
<property name="checkable"> <property name="checkable">
<bool>true</bool> <bool>false</bool>
</property> </property>
<property name="checked"> <property name="checked">
<bool>false</bool> <bool>false</bool>
@ -948,6 +964,22 @@
</hint> </hint>
</hints> </hints>
</connection> </connection>
<connection>
<sender>personalize</sender>
<signal>toggled(bool)</signal>
<receiver>groupBox</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>613</x>
<y>41</y>
</hint>
<hint type="destinationlabel">
<x>634</x>
<y>72</y>
</hint>
</hints>
</connection>
</connections> </connections>
<buttongroups> <buttongroups>
<buttongroup name="buttonGroup_2"/> <buttongroup name="buttonGroup_2"/>
@ -955,5 +987,6 @@
<buttongroup name="buttonGroup_4"/> <buttongroup name="buttonGroup_4"/>
<buttongroup name="buttonGroup_5"/> <buttongroup name="buttonGroup_5"/>
<buttongroup name="buttonGroup"/> <buttongroup name="buttonGroup"/>
<buttongroup name="buttonGroup_6"/>
</buttongroups> </buttongroups>
</ui> </ui>