mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Move save of preferences to the preferences dialog.
I had a few very strange bugs regarding to preferences (like clicking on apply twice so things worked), because the code that moved from "QSettings" to 'Internal Settings Struct' was being triggered on the mainwindow, *after* the settingsChanged signal was emmited. This should fix the problem. Signed-off-by: Tomaz Canabrava <tcanabrava@kde.org> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
5c1abde2a5
commit
96e35e542c
2 changed files with 102 additions and 95 deletions
|
@ -563,49 +563,6 @@ bool MainWindow::askSaveChanges()
|
|||
return false;
|
||||
}
|
||||
|
||||
#define GET_UNIT(name, field, f, t) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \
|
||||
else \
|
||||
prefs.units.field = default_prefs.units.field
|
||||
|
||||
#define GET_BOOL(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt() ? true : false; \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_DOUBLE(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toDouble(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_INT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
|
||||
void MainWindow::initialUiSetup()
|
||||
{
|
||||
QSettings settings;
|
||||
|
@ -629,63 +586,11 @@ void MainWindow::initialUiSetup()
|
|||
|
||||
void MainWindow::readSettings()
|
||||
{
|
||||
QVariant v;
|
||||
QSettings s;
|
||||
|
||||
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);
|
||||
s.endGroup();
|
||||
s.beginGroup("TecDetails");
|
||||
GET_BOOL("po2graph", pp_graphs.po2);
|
||||
GET_BOOL("pn2graph", pp_graphs.pn2);
|
||||
GET_BOOL("phegraph", pp_graphs.phe);
|
||||
GET_DOUBLE("po2threshold", pp_graphs.po2_threshold);
|
||||
GET_DOUBLE("pn2threshold", pp_graphs.pn2_threshold);
|
||||
GET_DOUBLE("phethreshold", pp_graphs.phe_threshold);
|
||||
GET_BOOL("mod", mod);
|
||||
GET_DOUBLE("modppO2", mod_ppO2);
|
||||
GET_BOOL("ead", ead);
|
||||
GET_BOOL("redceiling", profile_red_ceiling);
|
||||
GET_BOOL("dcceiling", profile_dc_ceiling);
|
||||
GET_BOOL("calcceiling", profile_calc_ceiling);
|
||||
GET_BOOL("calcceiling3m", calc_ceiling_3m_incr);
|
||||
GET_BOOL("calcndltts", calc_ndl_tts);
|
||||
GET_BOOL("calcalltissues", calc_all_tissues);
|
||||
GET_INT("gflow", gflow);
|
||||
GET_INT("gfhigh", gfhigh);
|
||||
GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
|
||||
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
||||
GET_BOOL("show_sac", show_sac);
|
||||
GET_BOOL("display_unused_tanks", display_unused_tanks);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("GeneralSettings");
|
||||
GET_TXT("default_filename", default_filename);
|
||||
GET_TXT("default_cylinder", default_cylinder);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Display");
|
||||
QFont defaultFont = s.value("divelist_font", qApp->font()).value<QFont>();
|
||||
defaultFont.setPointSizeF(s.value("font_size", qApp->font().pointSizeF()).toFloat());
|
||||
qApp->setFont(defaultFont);
|
||||
GET_TXT("divelist_font", divelist_font);
|
||||
GET_INT("font_size", font_size);
|
||||
GET_INT("displayinvalid", display_invalid_dives);
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
void MainWindow::writeSettings()
|
||||
|
|
|
@ -137,6 +137,49 @@ void PreferencesDialog::rememberPrefs()
|
|||
|
||||
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
||||
|
||||
|
||||
#define GET_UNIT(name, field, f, t) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.units.field = (v.toInt() == (t)) ? (t) : (f); \
|
||||
else \
|
||||
prefs.units.field = default_prefs.units.field
|
||||
|
||||
#define GET_BOOL(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt() ? true : false; \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_DOUBLE(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toDouble(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_INT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = v.toInt(); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
#define GET_TXT(name, field) \
|
||||
v = s.value(QString(name)); \
|
||||
if (v.isValid()) \
|
||||
prefs.field = strdup(v.toString().toUtf8().constData()); \
|
||||
else \
|
||||
prefs.field = default_prefs.field
|
||||
|
||||
void PreferencesDialog::syncSettings()
|
||||
{
|
||||
QSettings s;
|
||||
|
@ -201,7 +244,66 @@ void PreferencesDialog::syncSettings()
|
|||
}
|
||||
s.setValue("UseSystemLanguage", ui.languageSystemDefault->isChecked());
|
||||
s.setValue("UiLanguage", ui.languageView->currentIndex().data(Qt::UserRole));
|
||||
s.endGroup();
|
||||
// This code was on the mainwindow, it should belong nowhere, but since we dind't
|
||||
// correctly fixed this code yet ( too much stuff on the code calling preferences )
|
||||
// force this here.
|
||||
|
||||
QVariant v;
|
||||
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);
|
||||
s.endGroup();
|
||||
s.beginGroup("TecDetails");
|
||||
GET_BOOL("po2graph", pp_graphs.po2);
|
||||
GET_BOOL("pn2graph", pp_graphs.pn2);
|
||||
GET_BOOL("phegraph", pp_graphs.phe);
|
||||
GET_DOUBLE("po2threshold", pp_graphs.po2_threshold);
|
||||
GET_DOUBLE("pn2threshold", pp_graphs.pn2_threshold);
|
||||
GET_DOUBLE("phethreshold", pp_graphs.phe_threshold);
|
||||
GET_BOOL("mod", mod);
|
||||
GET_DOUBLE("modppO2", mod_ppO2);
|
||||
GET_BOOL("ead", ead);
|
||||
GET_BOOL("redceiling", profile_red_ceiling);
|
||||
GET_BOOL("dcceiling", profile_dc_ceiling);
|
||||
GET_BOOL("calcceiling", profile_calc_ceiling);
|
||||
GET_BOOL("calcceiling3m", calc_ceiling_3m_incr);
|
||||
GET_BOOL("calcndltts", calc_ndl_tts);
|
||||
GET_BOOL("calcalltissues", calc_all_tissues);
|
||||
GET_INT("gflow", gflow);
|
||||
GET_INT("gfhigh", gfhigh);
|
||||
GET_BOOL("gf_low_at_maxdepth", gf_low_at_maxdepth);
|
||||
set_gf(prefs.gflow, prefs.gfhigh, prefs.gf_low_at_maxdepth);
|
||||
GET_BOOL("show_sac", show_sac);
|
||||
GET_BOOL("display_unused_tanks", display_unused_tanks);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("GeneralSettings");
|
||||
GET_TXT("default_filename", default_filename);
|
||||
GET_TXT("default_cylinder", default_cylinder);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Display");
|
||||
QFont defaultFont = s.value("divelist_font", qApp->font()).value<QFont>();
|
||||
defaultFont.setPointSizeF(s.value("font_size", qApp->font().pointSizeF()).toFloat());
|
||||
qApp->setFont(defaultFont);
|
||||
GET_TXT("divelist_font", divelist_font);
|
||||
GET_INT("font_size", font_size);
|
||||
GET_INT("displayinvalid", display_invalid_dives);
|
||||
s.endGroup();
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue