mirror of
https://github.com/subsurface/subsurface.git
synced 2025-01-31 21:03:23 +00:00
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>
This commit is contained in:
parent
e0b376622c
commit
4c4a7a6d96
9 changed files with 24 additions and 92 deletions
|
@ -116,9 +116,6 @@ void init_ui(int *argcp, char ***argvp)
|
|||
}
|
||||
|
||||
QSettings s;
|
||||
s.beginGroup("GeneralSettings");
|
||||
prefs.default_filename = getSetting(s, "default_filename");
|
||||
s.endGroup();
|
||||
s.beginGroup("DiveComputer");
|
||||
default_dive_computer_vendor = getSetting(s, "dive_computer_vendor");
|
||||
default_dive_computer_product = getSetting(s,"dive_computer_product");
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
#include <QDebug>
|
||||
#include <QSet>
|
||||
#include <QTableView>
|
||||
#include <QSettings>
|
||||
#include <QPalette>
|
||||
|
||||
MainTab::MainTab(QWidget *parent) : QTabWidget(parent),
|
||||
|
|
|
@ -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,17 +627,16 @@ void MainWindow::readSettings()
|
|||
GET_BOOL("show_sac", show_sac);
|
||||
s.endGroup();
|
||||
|
||||
s.beginGroup("Display");
|
||||
v = s.value(QString("divelist_font"));
|
||||
if (v.isValid())
|
||||
prefs.divelist_font = strdup(v.toString().toUtf8().data());
|
||||
}
|
||||
s.beginGroup("GeneralSettings");
|
||||
GET_TXT("default_filename", default_filename);
|
||||
s.endGroup();
|
||||
|
||||
#define SAVE_VALUE(name, field) \
|
||||
if (prefs.field != default_prefs.field) \
|
||||
settings.setValue(name, prefs.field); \
|
||||
else \
|
||||
settings.remove(name)
|
||||
s.beginGroup("Display");
|
||||
GET_TXT("divelist_font", divelist_font);
|
||||
GET_INT("font_size", font_size);
|
||||
GET_INT("displayinvalid", display_invalid_dives);
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
void MainWindow::writeSettings()
|
||||
{
|
||||
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1557,7 +1557,6 @@ void ToolTipItem::persistPos()
|
|||
s.beginGroup("ProfileMap");
|
||||
s.setValue("tooltip_position", currentPos);
|
||||
s.endGroup();
|
||||
s.sync();
|
||||
}
|
||||
|
||||
void ToolTipItem::readPos()
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -26,7 +26,7 @@ struct preferences default_prefs = {
|
|||
.gflow = 30,
|
||||
.gfhigh = 75,
|
||||
.font_size = 14.0,
|
||||
.show_invalid = FALSE,
|
||||
.display_invalid_dives = FALSE,
|
||||
.show_sac = FALSE,
|
||||
};
|
||||
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
extern struct preferences prefs;
|
||||
extern struct preferences default_prefs;
|
||||
extern bool imported;
|
||||
|
||||
void setup_system_prefs(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue