From 96e35e542cce1e988f542d46789a3ab66d9cb1e7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava Date: Thu, 6 Feb 2014 14:18:00 -0200 Subject: 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 Signed-off-by: Dirk Hohndel --- qt-ui/mainwindow.cpp | 95 ---------------------------------------------- qt-ui/preferences.cpp | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 95 deletions(-) diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index e9041653a..c9528f90f 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -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(); 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() diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index ab9c9fa39..cb8dde83b 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -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(); + 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(); } -- cgit v1.2.3-70-g09d2