summaryrefslogtreecommitdiffstats
path: root/qt-ui/mainwindow.cpp
diff options
context:
space:
mode:
authorGravatar Patrick Valsecchi <patrick@thus.ch>2013-11-20 13:40:14 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2013-11-21 08:11:40 -0800
commit4c4a7a6d968fa27de72f1510c55d327a7e919d7c (patch)
tree8efda997313870e3b433a8a49b94a47af830fc54 /qt-ui/mainwindow.cpp
parente0b376622c505ee631b87b54aefa0130bbfa1237 (diff)
downloadsubsurface-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/mainwindow.cpp')
-rw-r--r--qt-ui/mainwindow.cpp54
1 files changed, 15 insertions, 39 deletions
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)