mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Connect preferences to the rest of the code
The biggest problem here was that bool has different sizes in C and C++ code. So using this in a structure shared between the two sides wasn't a smart idea. Instead I went with 'short', but that caused problems with Qt being to smart for its own good and not doing the right thing when dealing with 'boolean' settings and a short value. This may be something in the way I implemented things (as I doubt that something this fundamental would be broken) but the workaround implemented here (explicitly using 0 or 1 depending on the value of the boolean) seems to work. I also decided to get rid of the confusion of where gflow/gfhigh are floating point (0..1) and when they are integers (0..100). We now use integers anywhere outside of deco.c. I also applied some serious spelling corrections to the preferences dialog's ui file. Finally, this enables the code that selects which partial pressure graph to show. Still to do: font size, metric/imperial logic Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
parent
8394828806
commit
4f53ad736d
10 changed files with 120 additions and 92 deletions
12
deco.c
12
deco.c
|
@ -136,7 +136,7 @@ double add_segment(double pressure, const struct gasmix *gasmix, int period_in_s
|
|||
|
||||
#if GF_LOW_AT_MAXDEPTH
|
||||
if (pressure > gf_low_pressure_this_dive)
|
||||
gf_low_pressure_this_dive = pressure;
|
||||
gf_low_pressure_this_dive = pressure;
|
||||
#endif
|
||||
|
||||
if (ccpo2) { /* CC */
|
||||
|
@ -263,10 +263,10 @@ unsigned int deco_allowed_depth(double tissues_tolerance, double surface_pressur
|
|||
return depth;
|
||||
}
|
||||
|
||||
void set_gf(double gflow, double gfhigh)
|
||||
void set_gf(short gflow, short gfhigh)
|
||||
{
|
||||
if (gflow != -1.0)
|
||||
buehlmann_config.gf_low = gflow;
|
||||
if (gfhigh != -1.0)
|
||||
buehlmann_config.gf_high = gfhigh;
|
||||
if (gflow != -1)
|
||||
buehlmann_config.gf_low = (double)gflow / 100.0;
|
||||
if (gfhigh != -1)
|
||||
buehlmann_config.gf_high = (double)gfhigh / 100.0;
|
||||
}
|
||||
|
|
2
dive.h
2
dive.h
|
@ -694,7 +694,7 @@ extern double add_segment(double pressure, const struct gasmix *gasmix, int peri
|
|||
extern void clear_deco(double surface_pressure);
|
||||
extern void dump_tissues(void);
|
||||
extern unsigned int deco_allowed_depth(double tissues_tolerance, double surface_pressure, struct dive *dive, gboolean smooth);
|
||||
extern void set_gf(double gflow, double gfhigh);
|
||||
extern void set_gf(short gflow, short gfhigh);
|
||||
extern void cache_deco_state(double, char **datap);
|
||||
extern double restore_deco_state(char *data);
|
||||
|
||||
|
|
7
main.c
7
main.c
|
@ -25,11 +25,14 @@ struct preferences default_prefs = {
|
|||
.mod = FALSE,
|
||||
.mod_ppO2 = 1.6,
|
||||
.ead = FALSE,
|
||||
.profile_dc_ceiling = TRUE,
|
||||
.profile_red_ceiling = FALSE,
|
||||
.profile_calc_ceiling = FALSE,
|
||||
.calc_ceiling_3m_incr = FALSE,
|
||||
.gflow = 0.30,
|
||||
.gfhigh = 0.75,
|
||||
.gflow = 30,
|
||||
.gfhigh = 75,
|
||||
.font_size = 14.0,
|
||||
.show_invalid = FALSE,
|
||||
#ifdef USE_GTK_UI
|
||||
.map_provider = OSM_GPS_MAP_SOURCE_VIRTUAL_EARTH_HYBRID,
|
||||
#endif
|
||||
|
|
54
pref.h
54
pref.h
|
@ -5,42 +5,46 @@
|
|||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* can't use 'bool' for the boolean values - different size in C and C++ */
|
||||
typedef struct {
|
||||
gboolean cylinder;
|
||||
gboolean temperature;
|
||||
gboolean totalweight;
|
||||
gboolean suit;
|
||||
gboolean nitrox;
|
||||
gboolean sac;
|
||||
gboolean otu;
|
||||
gboolean maxcns;
|
||||
short cylinder;
|
||||
short temperature;
|
||||
short totalweight;
|
||||
short suit;
|
||||
short nitrox;
|
||||
short sac;
|
||||
short otu;
|
||||
short maxcns;
|
||||
} visible_cols_t;
|
||||
|
||||
typedef struct {
|
||||
gboolean po2;
|
||||
gboolean pn2;
|
||||
gboolean phe;
|
||||
short po2;
|
||||
short pn2;
|
||||
short phe;
|
||||
double po2_threshold;
|
||||
double pn2_threshold;
|
||||
double phe_threshold;
|
||||
} partial_pressure_graphs_t;
|
||||
|
||||
struct preferences {
|
||||
struct units units;
|
||||
visible_cols_t visible_cols;
|
||||
partial_pressure_graphs_t pp_graphs;
|
||||
gboolean mod;
|
||||
double mod_ppO2;
|
||||
gboolean ead;
|
||||
gboolean profile_red_ceiling;
|
||||
gboolean profile_calc_ceiling;
|
||||
gboolean calc_ceiling_3m_incr;
|
||||
double gflow;
|
||||
double gfhigh;
|
||||
int map_provider;
|
||||
const char *divelist_font;
|
||||
const char *default_filename;
|
||||
short display_invalid_dives;
|
||||
double font_size;
|
||||
visible_cols_t visible_cols;
|
||||
partial_pressure_graphs_t pp_graphs;
|
||||
short mod;
|
||||
double mod_ppO2;
|
||||
short ead;
|
||||
short profile_dc_ceiling;
|
||||
short profile_red_ceiling;
|
||||
short profile_calc_ceiling;
|
||||
short calc_ceiling_3m_incr;
|
||||
short gflow;
|
||||
short gfhigh;
|
||||
int map_provider;
|
||||
short display_invalid_dives;
|
||||
short show_invalid;
|
||||
struct units units;
|
||||
};
|
||||
|
||||
extern struct preferences prefs, default_prefs;
|
||||
|
@ -49,7 +53,7 @@ extern struct preferences prefs, default_prefs;
|
|||
|
||||
extern void subsurface_open_conf(void);
|
||||
extern void subsurface_set_conf(const char *name, const char *value);
|
||||
extern void subsurface_set_conf_bool(const char *name, gboolean value);
|
||||
extern void subsurface_set_conf_bool(const char *name, bool value);
|
||||
extern void subsurface_set_conf_int(const char *name, int value);
|
||||
extern void subsurface_unset_conf(const char *name);
|
||||
extern const char *subsurface_get_conf(const char *name);
|
||||
|
|
|
@ -76,7 +76,7 @@ const char *getSetting(QSettings &s, QString name)
|
|||
QVariant v;
|
||||
v = s.value(name);
|
||||
if (v.isValid()) {
|
||||
return strdup(v.toString().toUtf8().constData());
|
||||
return strdup(v.toString().toUtf8().data());
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -372,11 +372,11 @@ void MainWindow::readSettings()
|
|||
GET_BOOL(v, "OTU", prefs.visible_cols.otu);
|
||||
GET_BOOL(v, "MAXCNS", prefs.visible_cols.maxcns);
|
||||
GET_BOOL(v, "SAC", prefs.visible_cols.sac);
|
||||
settings.endGroup();
|
||||
settings.beginGroup("TecDetails");
|
||||
GET_BOOL(v, "po2graph", prefs.pp_graphs.po2);
|
||||
GET_BOOL(v, "pn2graph", prefs.pp_graphs.pn2);
|
||||
GET_BOOL(v, "phegraph", prefs.pp_graphs.phe);
|
||||
settings.endGroup();
|
||||
settings.beginGroup("TecDetails");
|
||||
v = settings.value(QString("po2threshold"));
|
||||
if (v.isValid())
|
||||
prefs.pp_graphs.po2_threshold = v.toDouble();
|
||||
|
@ -392,14 +392,15 @@ void MainWindow::readSettings()
|
|||
prefs.mod_ppO2 = v.toDouble();
|
||||
GET_BOOL(v, "ead", prefs.ead);
|
||||
GET_BOOL(v, "redceiling", prefs.profile_red_ceiling);
|
||||
GET_BOOL(v, "show_dc_reported_ceiling", prefs.profile_dc_ceiling);
|
||||
GET_BOOL(v, "calcceiling", prefs.profile_calc_ceiling);
|
||||
GET_BOOL(v, "calcceiling3m", prefs.calc_ceiling_3m_incr);
|
||||
v = settings.value(QString("gflow"));
|
||||
if (v.isValid())
|
||||
prefs.gflow = v.toInt() / 100.0;
|
||||
prefs.gflow = v.toInt();
|
||||
v = settings.value(QString("gfhigh"));
|
||||
if (v.isValid())
|
||||
prefs.gfhigh = v.toInt() / 100.0;
|
||||
prefs.gfhigh = v.toInt();
|
||||
set_gf(prefs.gflow, prefs.gfhigh);
|
||||
settings.endGroup();
|
||||
|
||||
|
@ -420,7 +421,9 @@ void MainWindow::readSettings()
|
|||
|
||||
#define SAVE_VALUE(name, field) \
|
||||
if (prefs.field != default_prefs.field) \
|
||||
settings.setValue(name, prefs.field)
|
||||
settings.setValue(name, prefs.field); \
|
||||
else \
|
||||
settings.remove(name)
|
||||
|
||||
void MainWindow::writeSettings()
|
||||
{
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#include "preferences.h"
|
||||
#include "ui_preferences.h"
|
||||
#include "../dive.h"
|
||||
#include <QSettings>
|
||||
|
||||
PreferencesDialog* PreferencesDialog::instance()
|
||||
|
@ -9,32 +8,36 @@ PreferencesDialog* PreferencesDialog::instance()
|
|||
return dialog;
|
||||
}
|
||||
|
||||
#define B(V, P) s.value(#V, default_prefs.P).toBool()
|
||||
#define D(V, P) s.value(#V, default_prefs.P).toDouble()
|
||||
#define I(V, P) s.value(#V, default_prefs.P).toInt()
|
||||
|
||||
PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDialog(parent, f)
|
||||
, ui(new Ui::PreferencesDialog())
|
||||
{
|
||||
ui->setupUi(this);
|
||||
connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(syncSettings()));
|
||||
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(resetSettings()));
|
||||
|
||||
#define B(X) s.value(#X, false).toBool()
|
||||
#define D(X) s.value(#X, 0.0).toDouble()
|
||||
oldPrefs = prefs;
|
||||
|
||||
QSettings s;
|
||||
|
||||
// Graph
|
||||
s.beginGroup("TecDetails");
|
||||
ui->calculated_ceiling->setChecked(B(show_calculated_ceiling));
|
||||
ui->phe->setChecked(B(show_phe));
|
||||
ui->po2->setChecked(B(show_po2));
|
||||
ui->pn2->setChecked(B(show_pn2));
|
||||
ui->pheThreshould->setValue(D(phe_threshould));
|
||||
ui->po2Threashould->setValue(D(po2_threshould));
|
||||
ui->pn2Threshould->setValue(D(pn2_threshould));
|
||||
ui->ead_end_eadd->setChecked(B(show_ead_end_eadd));
|
||||
ui->dc_reported_ceiling->setChecked(B(show_dc_reported_ceiling));
|
||||
ui->calculated_ceiling->setChecked(B(show_calculated_ceiling));
|
||||
ui->increment_3m->setChecked(B(show_3m_increments));
|
||||
ui->gflow->setValue(D(gflow));
|
||||
ui->gfhigh->setValue(D(gfhigh));
|
||||
ui->calculated_ceiling->setChecked(B(calcceiling, profile_calc_ceiling));
|
||||
ui->phe->setChecked(B(phegraph, pp_graphs.phe));
|
||||
ui->po2->setChecked(B(po2graph, pp_graphs.po2));
|
||||
ui->pn2->setChecked(B(pn2graph, pp_graphs.pn2));
|
||||
ui->pheThreshold->setValue(D(phethreshold, pp_graphs.phe_threshold));
|
||||
ui->po2Threshold->setValue(D(po2threshold, pp_graphs.po2_threshold));
|
||||
ui->pn2Threshold->setValue(D(pn2threshold, pp_graphs.pn2_threshold));
|
||||
ui->ead_end_eadd->setChecked(B(ead, ead));
|
||||
ui->dc_reported_ceiling->setChecked(B(dcceiling, profile_dc_ceiling));
|
||||
ui->calculated_ceiling->setChecked(B(calceiling, profile_calc_ceiling));
|
||||
ui->increment_3m->setChecked(B(calcceiling3m, calc_ceiling_3m_incr));
|
||||
ui->gflow->setValue((int)(I(gflow, gflow)));
|
||||
ui->gfhigh->setValue((int)(I(gfhigh, gfhigh)));
|
||||
s.endGroup();
|
||||
|
||||
// Units
|
||||
|
@ -68,36 +71,44 @@ PreferencesDialog::PreferencesDialog(QWidget* parent, Qt::WindowFlags f) : QDial
|
|||
// Defaults
|
||||
s.beginGroup("GeneralSettings");
|
||||
ui->font->setFont( QFont(s.value("table_fonts").toString()));
|
||||
ui->fontsize->setValue(D(font_size));
|
||||
ui->fontsize->setValue(D(font_size, font_size));
|
||||
|
||||
ui->defaultfilename->setText(s.value("default_file").toString());
|
||||
ui->displayinvalid->setChecked(B(show_invalid));
|
||||
ui->defaultfilename->setText(s.value("default_filename").toString());
|
||||
ui->displayinvalid->setChecked(B(show_invalid, show_invalid));
|
||||
s.endGroup();
|
||||
}
|
||||
|
||||
#undef B
|
||||
#undef D
|
||||
|
||||
void PreferencesDialog::resetSettings()
|
||||
{
|
||||
prefs = oldPrefs;
|
||||
}
|
||||
|
||||
#define SB(V, B) s.setValue(V, (int)(B->isChecked() ? 1 : 0))
|
||||
|
||||
void PreferencesDialog::syncSettings()
|
||||
{
|
||||
QSettings s;
|
||||
|
||||
// Graph
|
||||
s.beginGroup("TecDetails");
|
||||
s.setValue("show_calculated_ceiling", ui->calculated_ceiling->isChecked());
|
||||
s.setValue("show_phe", ui->phe->isChecked());
|
||||
s.setValue("show_po2", ui->po2->isChecked());
|
||||
s.setValue("show_pn2", ui->pn2->isChecked());
|
||||
s.setValue("phe_threshould", ui->pheThreshould->value());
|
||||
s.setValue("po2_threshould", ui->po2Threashould->value());
|
||||
s.setValue("pn2_threshould", ui->pn2Threshould->value());
|
||||
s.setValue("show_ead_end_eadd", ui->ead_end_eadd->isChecked());
|
||||
s.setValue("show_dc_reported_ceiling", ui->dc_reported_ceiling->isChecked());
|
||||
s.setValue("show_calculated_ceiling", ui->calculated_ceiling->isChecked());
|
||||
|
||||
s.setValue("show_3m_increments", ui->increment_3m->isChecked());
|
||||
SB("calcceiling", ui->calculated_ceiling);
|
||||
SB("phegraph", ui->phe);
|
||||
SB("po2graph", ui->po2);
|
||||
SB("pn2graph", ui->pn2);
|
||||
s.setValue("phethreshold", ui->pheThreshold->value());
|
||||
s.setValue("po2threshold", ui->po2Threshold->value());
|
||||
s.setValue("pn2threshold", ui->pn2Threshold->value());
|
||||
SB("ead", ui->ead_end_eadd);
|
||||
SB("dcceiling", ui->dc_reported_ceiling);
|
||||
SB("calceiling3m", ui->increment_3m);
|
||||
s.setValue("gflow", ui->gflow->value());
|
||||
s.setValue("gfhigh", ui->gfhigh->value());
|
||||
s.endGroup();
|
||||
|
||||
// Units
|
||||
s.beginGroup("Units");
|
||||
s.setValue("units_metric", ui->metric->isChecked());
|
||||
|
@ -111,10 +122,13 @@ void PreferencesDialog::syncSettings()
|
|||
s.beginGroup("GeneralSettings");
|
||||
s.value("table_fonts", ui->font->font().family());
|
||||
s.value("font_size", ui->fontsize->value());
|
||||
s.value("default_file", ui->defaultfilename->text());
|
||||
s.value("default_filename", ui->defaultfilename->text());
|
||||
s.value("displayinvalid", ui->displayinvalid->isChecked());
|
||||
s.endGroup();
|
||||
s.sync();
|
||||
|
||||
oldPrefs = prefs;
|
||||
emit settingsChanged();
|
||||
}
|
||||
|
||||
#undef SB
|
||||
|
|
|
@ -2,6 +2,8 @@
|
|||
#define PREFERENCES_DIALOG_H
|
||||
|
||||
#include <QDialog>
|
||||
#include "../dive.h"
|
||||
#include "../pref.h"
|
||||
|
||||
namespace Ui{
|
||||
class PreferencesDialog;
|
||||
|
@ -17,10 +19,12 @@ signals:
|
|||
|
||||
public slots:
|
||||
void syncSettings();
|
||||
|
||||
void resetSettings();
|
||||
|
||||
private:
|
||||
explicit PreferencesDialog(QWidget* parent = 0, Qt::WindowFlags f = 0);
|
||||
Ui::PreferencesDialog* ui;
|
||||
Ui::PreferencesDialog* ui;
|
||||
struct preferences oldPrefs;
|
||||
};
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
|
|
@ -449,12 +449,12 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>threshould</string>
|
||||
<string>threshold</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="po2Threashould">
|
||||
<widget class="QDoubleSpinBox" name="po2Threshold">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
@ -490,12 +490,12 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>threshould</string>
|
||||
<string>threshold</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="pn2Threshould">
|
||||
<widget class="QDoubleSpinBox" name="pn2Threshold">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
@ -531,12 +531,12 @@
|
|||
<bool>false</bool>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>threshould</string>
|
||||
<string>threshold</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QSpinBox" name="pheThreshould">
|
||||
<widget class="QDoubleSpinBox" name="pheThreshold">
|
||||
<property name="enabled">
|
||||
<bool>false</bool>
|
||||
</property>
|
||||
|
@ -650,7 +650,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QDoubleSpinBox" name="gflow"/>
|
||||
<widget class="QSpinBox" name="gflow"/>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_20">
|
||||
|
@ -660,7 +660,7 @@
|
|||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QDoubleSpinBox" name="gfhigh"/>
|
||||
<widget class="QSpinBox" name="gfhigh"/>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
|
@ -754,7 +754,7 @@
|
|||
<connection>
|
||||
<sender>po2</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>po2Threashould</receiver>
|
||||
<receiver>po2Threshold</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -786,7 +786,7 @@
|
|||
<connection>
|
||||
<sender>pn2</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>pn2Threshould</receiver>
|
||||
<receiver>pn2Threshold</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
@ -818,7 +818,7 @@
|
|||
<connection>
|
||||
<sender>phe</sender>
|
||||
<signal>clicked(bool)</signal>
|
||||
<receiver>pheThreshould</receiver>
|
||||
<receiver>pheThreshold</receiver>
|
||||
<slot>setEnabled(bool)</slot>
|
||||
<hints>
|
||||
<hint type="sourcelabel">
|
||||
|
|
|
@ -429,7 +429,7 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
setup_pp_limits(&gc);
|
||||
QColor c;
|
||||
QPointF from, to;
|
||||
//if (prefs.pp_graphs.pn2) {
|
||||
if (prefs.pp_graphs.pn2) {
|
||||
c = profile_color[PN2].first();
|
||||
entry = pi->entry;
|
||||
from = QPointF(SCALEGC(entry->sec, entry->pn2));
|
||||
|
@ -465,9 +465,9 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
from = QPointF(SCALEGC(entry->sec, entry->pn2));
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
//if (prefs.pp_graphs.phe) {
|
||||
if (prefs.pp_graphs.phe) {
|
||||
c = profile_color[PHE].first();
|
||||
entry = pi->entry;
|
||||
|
||||
|
@ -504,8 +504,8 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
from = QPointF(SCALEGC(entry->sec, entry->phe));
|
||||
}
|
||||
}
|
||||
//}
|
||||
//if (prefs.pp_graphs.po2) {
|
||||
}
|
||||
if (prefs.pp_graphs.po2) {
|
||||
c = profile_color[PO2].first();
|
||||
entry = pi->entry;
|
||||
from = QPointF(SCALEGC(entry->sec, entry->po2));
|
||||
|
@ -539,7 +539,7 @@ void ProfileGraphicsView::plot_pp_gas_profile()
|
|||
from = QPointF(SCALEGC(entry->sec, entry->po2));
|
||||
}
|
||||
}
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
||||
void ProfileGraphicsView::plot_deco_text()
|
||||
|
@ -549,7 +549,7 @@ void ProfileGraphicsView::plot_deco_text()
|
|||
float y = gc.topy = 1.0;
|
||||
static text_render_options_t tro = {PRESSURE_TEXT_SIZE, PRESSURE_TEXT, CENTER, -0.2};
|
||||
gc.bottomy = 0.0;
|
||||
plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow * 100).arg(prefs.gfhigh * 100));
|
||||
plot_text(&tro, QPointF(x, y), QString("GF %1/%2").arg(prefs.gflow).arg(prefs.gfhigh));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue