diff options
author | Patrick Valsecchi <patrick@thus.ch> | 2013-11-20 13:40:14 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2013-11-21 08:11:40 -0800 |
commit | 4c4a7a6d968fa27de72f1510c55d327a7e919d7c (patch) | |
tree | 8efda997313870e3b433a8a49b94a47af830fc54 /qt-ui | |
parent | e0b376622c505ee631b87b54aefa0130bbfa1237 (diff) | |
download | subsurface-4c4a7a6d968fa27de72f1510c55d327a7e919d7c.tar.gz |
Refactoring of the configuration handling.
Before, when clicking the OK button on the preferences GUI, we were
updating in-memory preferences from the GUI, saving them to the
configuration file from the GUI, reloading from the file to the
in-memory preferences. Then, to add to the ducplication, when the
application was exiting, some fields were saved again.
Basically the first step and the last step were useless appart from
the fact the the other steps where missing a few fields here and there.
This patch removes the first step and fixes the missing fields.
Signed-off-by: Patrick Valsecchi <patrick@thus.ch>
ACKed-by: Tomaz Canabrava <tcanabrava@kde.org>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
Diffstat (limited to 'qt-ui')
-rw-r--r-- | qt-ui/maintab.cpp | 1 | ||||
-rw-r--r-- | qt-ui/mainwindow.cpp | 54 | ||||
-rw-r--r-- | qt-ui/preferences.cpp | 49 | ||||
-rw-r--r-- | qt-ui/preferences.h | 1 | ||||
-rw-r--r-- | qt-ui/profilegraphics.cpp | 1 | ||||
-rw-r--r-- | qt-ui/tableview.cpp | 1 |
6 files changed, 22 insertions, 85 deletions
diff --git a/qt-ui/maintab.cpp b/qt-ui/maintab.cpp index a56b2fc5d..e3cf0bccb 100644 --- a/qt-ui/maintab.cpp +++ b/qt-ui/maintab.cpp @@ -21,7 +21,6 @@ #include <QDebug> #include <QSet> #include <QTableView> -#include <QSettings> #include <QPalette> MainTab::MainTab(QWidget *parent) : QTabWidget(parent), diff --git a/qt-ui/mainwindow.cpp b/qt-ui/mainwindow.cpp index 53198902c..23c972741 100644 --- a/qt-ui/mainwindow.cpp +++ b/qt-ui/mainwindow.cpp @@ -557,6 +557,13 @@ bool MainWindow::askSaveChanges() 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() { @@ -620,18 +627,17 @@ void MainWindow::readSettings() GET_BOOL("show_sac", show_sac); s.endGroup(); + s.beginGroup("GeneralSettings"); + GET_TXT("default_filename", default_filename); + s.endGroup(); + s.beginGroup("Display"); - v = s.value(QString("divelist_font")); - if (v.isValid()) - prefs.divelist_font = strdup(v.toString().toUtf8().data()); + GET_TXT("divelist_font", divelist_font); + GET_INT("font_size", font_size); + GET_INT("displayinvalid", display_invalid_dives); + s.endGroup(); } -#define SAVE_VALUE(name, field) \ - if (prefs.field != default_prefs.field) \ - settings.setValue(name, prefs.field); \ - else \ - settings.remove(name) - void MainWindow::writeSettings() { QSettings settings; @@ -643,36 +649,6 @@ void MainWindow::writeSettings() saveSplitterSizes(); } settings.endGroup(); - - settings.beginGroup("Units"); - SAVE_VALUE("length", units.length); - SAVE_VALUE("pressure", units.pressure); - SAVE_VALUE("volume", units.volume); - SAVE_VALUE("temperature", units.temperature); - SAVE_VALUE("weight", units.weight); - SAVE_VALUE("vertical_speed_time", units.vertical_speed_time); - settings.endGroup(); - settings.beginGroup("TecDetails"); - SAVE_VALUE("po2graph", pp_graphs.po2); - SAVE_VALUE("pn2graph", pp_graphs.pn2); - SAVE_VALUE("phegraph", pp_graphs.phe); - SAVE_VALUE("po2threshold", pp_graphs.po2_threshold); - SAVE_VALUE("pn2threshold", pp_graphs.pn2_threshold); - SAVE_VALUE("phethreshold", pp_graphs.phe_threshold); - SAVE_VALUE("mod", mod); - SAVE_VALUE("modppO2", mod_ppO2); - SAVE_VALUE("ead", ead); - SAVE_VALUE("redceiling", profile_red_ceiling); - SAVE_VALUE("calcceiling", profile_calc_ceiling); - SAVE_VALUE("calcceiling3m", calc_ceiling_3m_incr); - SAVE_VALUE("calcalltissues", calc_all_tissues); - SAVE_VALUE("dcceiling", profile_dc_ceiling); - SAVE_VALUE("gflow", gflow); - SAVE_VALUE("gfhigh", gfhigh); - settings.endGroup(); - settings.beginGroup("GeneralSettings"); - SAVE_VALUE("default_filename", default_filename); - settings.endGroup(); } void MainWindow::closeEvent(QCloseEvent *event) diff --git a/qt-ui/preferences.cpp b/qt-ui/preferences.cpp index b9fb26018..f638d9d7d 100644 --- a/qt-ui/preferences.cpp +++ b/qt-ui/preferences.cpp @@ -77,7 +77,7 @@ void PreferencesDialog::setUiFromPrefs() ui.font->setFont(QString(prefs.divelist_font)); ui.fontsize->setValue(prefs.font_size); ui.defaultfilename->setText(prefs.default_filename); - ui.displayinvalid->setChecked(prefs.show_invalid); + ui.displayinvalid->setChecked(prefs.display_invalid_dives); ui.show_sac->setChecked(prefs.show_sac); ui.vertical_speed_minutes->setChecked(prefs.units.vertical_speed_time == units::MINUTES); ui.vertical_speed_seconds->setChecked(prefs.units.vertical_speed_time == units::SECONDS); @@ -86,6 +86,7 @@ void PreferencesDialog::setUiFromPrefs() void PreferencesDialog::restorePrefs() { prefs = oldPrefs; + setUiFromPrefs(); } void PreferencesDialog::rememberPrefs() @@ -93,41 +94,6 @@ void PreferencesDialog::rememberPrefs() oldPrefs = prefs; } -#define SP(V, B) prefs.V = (int)(B->isChecked() ? 1 : 0) - -void PreferencesDialog::setPrefsFromUi() -{ - SP(pp_graphs.phe, ui.phe); - SP(pp_graphs.po2, ui.po2); - SP(pp_graphs.pn2, ui.pn2); - prefs.pp_graphs.phe_threshold = ui.pheThreshold->value(); - prefs.pp_graphs.po2_threshold = ui.po2Threshold->value(); - prefs.pp_graphs.pn2_threshold = ui.pn2Threshold->value(); - SP(ead, ui.ead_end_eadd); - SP(mod, ui.mod); - prefs.mod_ppO2 = ui.maxppo2->value(); - SP(profile_dc_ceiling, ui.dc_reported_ceiling); - SP(profile_red_ceiling, ui.red_ceiling); - SP(profile_calc_ceiling, ui.calculated_ceiling); - SP(calc_ceiling_3m_incr, ui.increment_3m); - SP(calc_ndl_tts, ui.calc_ndl_tts); - SP(calc_all_tissues, ui.all_tissues); - prefs.gflow = ui.gflow->value(); - prefs.gfhigh = ui.gfhigh->value(); - prefs.unit_system = ui.metric->isChecked() ? METRIC : (ui.imperial->isChecked() ? IMPERIAL : PERSONALIZE); - prefs.units.temperature = ui.fahrenheit->isChecked() ? units::FAHRENHEIT : units::CELSIUS; - prefs.units.length = ui.feet->isChecked() ? units::FEET : units::METERS; - prefs.units.pressure = ui.psi->isChecked() ? units::PSI : units::BAR; - prefs.units.volume = ui.cuft->isChecked() ? units::CUFT : units::LITER; - prefs.units.weight = ui.lbs->isChecked() ? units::LBS : units::KG; - prefs.units.vertical_speed_time = ui.vertical_speed_minutes->isChecked() ? units::MINUTES : units::SECONDS; - prefs.divelist_font = strdup(ui.font->font().family().toUtf8().data()); - prefs.font_size = ui.fontsize->value(); - prefs.default_filename = strdup(ui.defaultfilename->text().toUtf8().data()); - prefs.display_invalid_dives = ui.displayinvalid->isChecked(); - SP(show_sac, ui.show_sac); -} - #define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0)) void PreferencesDialog::syncSettings() @@ -170,9 +136,12 @@ void PreferencesDialog::syncSettings() s.endGroup(); // Defaults s.beginGroup("GeneralSettings"); - s.value("table_fonts", ui.font->font().family()); - s.value("font_size", ui.fontsize->value()); s.value("default_filename", ui.defaultfilename->text()); + s.endGroup(); + + s.beginGroup("Display"); + s.value("divelist_font", ui.font->font().family()); + s.value("font_size", ui.fontsize->value()); s.value("displayinvalid", ui.displayinvalid->isChecked()); s.endGroup(); s.sync(); @@ -185,16 +154,12 @@ void PreferencesDialog::buttonClicked(QAbstractButton* button) switch(ui.buttonBox->standardButton(button)){ case QDialogButtonBox::Discard: restorePrefs(); - setUiFromPrefs(); - syncSettings(); close(); break; case QDialogButtonBox::Apply: - setPrefsFromUi(); syncSettings(); break; case QDialogButtonBox::FirstButton: - setPrefsFromUi(); syncSettings(); close(); break; diff --git a/qt-ui/preferences.h b/qt-ui/preferences.h index c9590db07..1cd3d9096 100644 --- a/qt-ui/preferences.h +++ b/qt-ui/preferences.h @@ -26,7 +26,6 @@ public slots: private: explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0); void setUiFromPrefs(); - void setPrefsFromUi(); void setUIFromSettings(); Ui::PreferencesDialog ui; struct preferences oldPrefs; diff --git a/qt-ui/profilegraphics.cpp b/qt-ui/profilegraphics.cpp index 3e7cff237..834d7bdb1 100644 --- a/qt-ui/profilegraphics.cpp +++ b/qt-ui/profilegraphics.cpp @@ -1557,7 +1557,6 @@ void ToolTipItem::persistPos() s.beginGroup("ProfileMap"); s.setValue("tooltip_position", currentPos); s.endGroup(); - s.sync(); } void ToolTipItem::readPos() diff --git a/qt-ui/tableview.cpp b/qt-ui/tableview.cpp index d9731b477..80100218a 100644 --- a/qt-ui/tableview.cpp +++ b/qt-ui/tableview.cpp @@ -36,7 +36,6 @@ TableView::~TableView() s.setValue(QString("colwidth%1").arg(i), ui.tableView->columnWidth(i)); } s.endGroup(); - s.sync(); } void TableView::setBtnToolTip(const QString& tooltip) |