diff options
-rw-r--r-- | core/settings/qPref.cpp | 1 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.cpp | 456 | ||||
-rw-r--r-- | core/subsurface-qt/SettingsObjectWrapper.h | 119 | ||||
-rw-r--r-- | desktop-widgets/diveplanner.cpp | 18 | ||||
-rw-r--r-- | qt-models/diveplannermodel.cpp | 66 | ||||
-rw-r--r-- | subsurface-helper.cpp | 1 | ||||
-rw-r--r-- | tests/testpreferences.cpp | 166 |
7 files changed, 123 insertions, 704 deletions
diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 135cb6818..ede230236 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -18,6 +18,7 @@ void qPref::loadSync(bool doSync) qPrefCloudStorage::instance()->loadSync(doSync); qPrefDisplay::instance()->loadSync(doSync); qPrefDiveComputer::instance()->loadSync(doSync); + qPrefDivePlanner::instance()->loadSync(doSync); // qPrefFaceook does not use disk. qPrefProxy::instance()->loadSync(doSync); qPrefUnits::instance()->loadSync(doSync); diff --git a/core/subsurface-qt/SettingsObjectWrapper.cpp b/core/subsurface-qt/SettingsObjectWrapper.cpp index 7997852e6..c31d3831b 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/core/subsurface-qt/SettingsObjectWrapper.cpp @@ -715,429 +715,6 @@ void GeocodingPreferences::setThirdTaxonomyCategory(taxonomy_category value) emit thirdTaxonomyCategoryChanged(value); } -DivePlannerSettings::DivePlannerSettings(QObject *parent) : - QObject(parent) -{ -} - -bool DivePlannerSettings::lastStop() const -{ - return prefs.last_stop; -} - -bool DivePlannerSettings::verbatimPlan() const -{ - return prefs.verbatim_plan; -} - -bool DivePlannerSettings::displayRuntime() const -{ - return prefs.display_runtime; -} - -bool DivePlannerSettings::displayDuration() const -{ - return prefs.display_duration; -} - -bool DivePlannerSettings::displayTransitions() const -{ - return prefs.display_transitions; -} - -bool DivePlannerSettings::displayVariations() const -{ - return prefs.display_variations; -} - -bool DivePlannerSettings::doo2breaks() const -{ - return prefs.doo2breaks; -} - -bool DivePlannerSettings::dropStoneMode() const -{ - return prefs.drop_stone_mode; -} - -bool DivePlannerSettings::safetyStop() const -{ - return prefs.safetystop; -} - -bool DivePlannerSettings::switchAtRequiredStop() const -{ - return prefs.switch_at_req_stop; -} - -int DivePlannerSettings::ascrate75() const -{ - return prefs.ascrate75; -} - -int DivePlannerSettings::ascrate50() const -{ - return prefs.ascrate50; -} - -int DivePlannerSettings::ascratestops() const -{ - return prefs.ascratestops; -} - -int DivePlannerSettings::ascratelast6m() const -{ - return prefs.ascratelast6m; -} - -int DivePlannerSettings::descrate() const -{ - return prefs.descrate; -} - -int DivePlannerSettings::sacfactor() const -{ - return prefs.sacfactor; -} - -int DivePlannerSettings::problemsolvingtime() const -{ - return prefs.problemsolvingtime; -} - -int DivePlannerSettings::bottompo2() const -{ - return prefs.bottompo2; -} - -int DivePlannerSettings::decopo2() const -{ - return prefs.decopo2; -} - -int DivePlannerSettings::bestmixend() const -{ - return prefs.bestmixend.mm; -} - -int DivePlannerSettings::reserveGas() const -{ - return prefs.reserve_gas; -} - -int DivePlannerSettings::minSwitchDuration() const -{ - return prefs.min_switch_duration; -} - -int DivePlannerSettings::bottomSac() const -{ - return prefs.bottomsac; -} - -int DivePlannerSettings::decoSac() const -{ - return prefs.decosac; -} - -deco_mode DivePlannerSettings::decoMode() const -{ - return prefs.planner_deco_mode; -} - -void DivePlannerSettings::setLastStop(bool value) -{ - if (value == prefs.last_stop) - return; - QSettings s; - s.beginGroup(group); - s.setValue("last_stop", value); - prefs.last_stop = value; - emit lastStopChanged(value); -} - -void DivePlannerSettings::setVerbatimPlan(bool value) -{ - if (value == prefs.verbatim_plan) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("verbatim_plan", value); - prefs.verbatim_plan = value; - emit verbatimPlanChanged(value); -} - -void DivePlannerSettings::setDisplayRuntime(bool value) -{ - if (value == prefs.display_runtime) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("display_runtime", value); - prefs.display_runtime = value; - emit displayRuntimeChanged(value); -} - -void DivePlannerSettings::setDisplayDuration(bool value) -{ - if (value == prefs.display_duration) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("display_duration", value); - prefs.display_duration = value; - emit displayDurationChanged(value); -} - -void DivePlannerSettings::setDisplayTransitions(bool value) -{ - if (value == prefs.display_transitions) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("display_transitions", value); - prefs.display_transitions = value; - emit displayTransitionsChanged(value); -} - -void DivePlannerSettings::setDisplayVariations(bool value) -{ - if (value == prefs.display_variations) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("display_variations", value); - prefs.display_variations = value; - emit displayVariationsChanged(value); -} - -void DivePlannerSettings::setDoo2breaks(bool value) -{ - if (value == prefs.doo2breaks) - return; - QSettings s; - s.beginGroup(group); - s.setValue("doo2breaks", value); - prefs.doo2breaks = value; - emit doo2breaksChanged(value); -} - -void DivePlannerSettings::setDropStoneMode(bool value) -{ - if (value == prefs.drop_stone_mode) - return; - QSettings s; - s.beginGroup(group); - s.setValue("drop_stone_mode", value); - prefs.drop_stone_mode = value; - emit dropStoneModeChanged(value); -} - -void DivePlannerSettings::setSafetyStop(bool value) -{ - if (value == prefs.safetystop) - return; - QSettings s; - s.beginGroup(group); - s.setValue("safetystop", value); - prefs.safetystop = value; - emit safetyStopChanged(value); -} - -void DivePlannerSettings::setSwitchAtRequiredStop(bool value) -{ - if (value == prefs.switch_at_req_stop) - return; - QSettings s; - s.beginGroup(group); - s.setValue("switch_at_req_stop", value); - prefs.switch_at_req_stop = value; - emit switchAtRequiredStopChanged(value); -} - -void DivePlannerSettings::setAscrate75(int value) -{ - if (value == prefs.ascrate75) - return; - QSettings s; - s.beginGroup(group); - s.setValue("ascrate75", value); - prefs.ascrate75 = value; - emit ascrate75Changed(value); -} - -void DivePlannerSettings::setAscrate50(int value) -{ - if (value == prefs.ascrate50) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("ascrate50", value); - prefs.ascrate50 = value; - emit ascrate50Changed(value); -} - -void DivePlannerSettings::setAscratestops(int value) -{ - if (value == prefs.ascratestops) - return; - QSettings s; - s.beginGroup(group); - s.setValue("ascratestops", value); - prefs.ascratestops = value; - emit ascratestopsChanged(value); -} - -void DivePlannerSettings::setAscratelast6m(int value) -{ - if (value == prefs.ascratelast6m) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("ascratelast6m", value); - prefs.ascratelast6m = value; - emit ascratelast6mChanged(value); -} - -void DivePlannerSettings::setDescrate(int value) -{ - if (value == prefs.descrate) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("descrate", value); - prefs.descrate = value; - emit descrateChanged(value); -} - -void DivePlannerSettings::setSacFactor(int value) -{ - if (value == prefs.sacfactor) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("sacfactor", value); - prefs.sacfactor = value; - emit sacFactorChanged(value); -} - -void DivePlannerSettings::setProblemSolvingTime(int value) -{ - if (value == prefs.problemsolvingtime) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("problemsolvingtime", value); - prefs.problemsolvingtime = value; - emit problemSolvingTimeChanged(value); -} - -void DivePlannerSettings::setBottompo2(int value) -{ - if (value == prefs.bottompo2) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("bottompo2", value); - prefs.bottompo2 = value; - emit bottompo2Changed(value); -} - -void DivePlannerSettings::setDecopo2(int value) -{ - if (value == prefs.decopo2) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("decopo2", value); - prefs.decopo2 = value; - emit decopo2Changed(value); -} - -void DivePlannerSettings::setBestmixend(int value) -{ - if (value == prefs.bestmixend.mm) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("bestmixend", value); - prefs.bestmixend.mm = value; - emit bestmixendChanged(value); -} - -void DivePlannerSettings::setReserveGas(int value) -{ - if (value == prefs.reserve_gas) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("reserve_gas", value); - prefs.reserve_gas = value; - emit reserveGasChanged(value); -} - -void DivePlannerSettings::setMinSwitchDuration(int value) -{ - if (value == prefs.min_switch_duration) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("min_switch_duration", value); - prefs.min_switch_duration = value; - emit minSwitchDurationChanged(value); -} - -void DivePlannerSettings::setBottomSac(int value) -{ - if (value == prefs.bottomsac) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("bottomsac", value); - prefs.bottomsac = value; - emit bottomSacChanged(value); -} - -void DivePlannerSettings::setDecoSac(int value) -{ - if (value == prefs.decosac) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("decosac", value); - prefs.decosac = value; - emit decoSacChanged(value); -} - -void DivePlannerSettings::setDecoMode(deco_mode value) -{ - if (value == prefs.planner_deco_mode) - return; - - QSettings s; - s.beginGroup(group); - s.setValue("deco_mode", value); - prefs.planner_deco_mode = value; - emit decoModeChanged(value); -} - GeneralSettingsObjectWrapper::GeneralSettingsObjectWrapper(QObject *parent) : QObject(parent) { @@ -1528,7 +1105,7 @@ QObject(parent), geocoding(new GeocodingPreferences(this)), proxy(new qPrefProxy(this)), cloud_storage(new qPrefCloudStorage(this)), - planner_settings(new DivePlannerSettings(this)), + planner_settings(new qPrefDivePlanner(this)), unit_settings(new qPrefUnits(this)), general_settings(new GeneralSettingsObjectWrapper(this)), display_settings(new qPrefDisplay(this)), @@ -1626,36 +1203,7 @@ void SettingsObjectWrapper::load() GET_INT("distance_threshold", distance_threshold); s.endGroup(); - s.beginGroup("Planner"); - GET_BOOL("last_stop", last_stop); - GET_BOOL("verbatim_plan", verbatim_plan); - GET_BOOL("display_duration", display_duration); - GET_BOOL("display_runtime", display_runtime); - GET_BOOL("display_transitions", display_transitions); - GET_BOOL("display_variations", display_variations); - GET_BOOL("safetystop", safetystop); - GET_BOOL("doo2breaks", doo2breaks); - GET_BOOL("switch_at_req_stop",switch_at_req_stop); - GET_BOOL("drop_stone_mode", drop_stone_mode); - - GET_INT("reserve_gas", reserve_gas); - GET_INT("ascrate75", ascrate75); - GET_INT("ascrate50", ascrate50); - GET_INT("ascratestops", ascratestops); - GET_INT("ascratelast6m", ascratelast6m); - GET_INT("descrate", descrate); - GET_INT("sacfactor", sacfactor); - GET_INT("problemsolvingtime", problemsolvingtime); - GET_INT("bottompo2", bottompo2); - GET_INT("decopo2", decopo2); - GET_INT("bestmixend", bestmixend.mm); - GET_INT("min_switch_duration", min_switch_duration); - GET_INT("bottomsac", bottomsac); - GET_INT("decosac", decosac); - - prefs.planner_deco_mode = deco_mode(s.value("deco_mode", default_prefs.planner_deco_mode).toInt()); - s.endGroup(); - + qPrefDivePlanner::instance()->load(); qPrefDiveComputer::instance()->load(); s.beginGroup("UpdateManager"); diff --git a/core/subsurface-qt/SettingsObjectWrapper.h b/core/subsurface-qt/SettingsObjectWrapper.h index 9099b0ceb..54add731d 100644 --- a/core/subsurface-qt/SettingsObjectWrapper.h +++ b/core/subsurface-qt/SettingsObjectWrapper.h @@ -229,120 +229,6 @@ private: const QString group = QStringLiteral("geocoding"); }; -class DivePlannerSettings : public QObject { - Q_OBJECT - Q_PROPERTY(bool last_stop READ lastStop WRITE setLastStop NOTIFY lastStopChanged) - Q_PROPERTY(bool verbatim_plan READ verbatimPlan WRITE setVerbatimPlan NOTIFY verbatimPlanChanged) - Q_PROPERTY(bool display_runtime READ displayRuntime WRITE setDisplayRuntime NOTIFY displayRuntimeChanged) - Q_PROPERTY(bool display_duration READ displayDuration WRITE setDisplayDuration NOTIFY displayDurationChanged) - Q_PROPERTY(bool display_transitions READ displayTransitions WRITE setDisplayTransitions NOTIFY displayTransitionsChanged) - Q_PROPERTY(bool display_variations READ displayVariations WRITE setDisplayVariations NOTIFY displayVariationsChanged) - Q_PROPERTY(bool doo2breaks READ doo2breaks WRITE setDoo2breaks NOTIFY doo2breaksChanged) - Q_PROPERTY(bool drop_stone_mode READ dropStoneMode WRITE setDropStoneMode NOTIFY dropStoneModeChanged) - Q_PROPERTY(bool safetystop READ safetyStop WRITE setSafetyStop NOTIFY safetyStopChanged) - Q_PROPERTY(bool switch_at_req_stop READ switchAtRequiredStop WRITE setSwitchAtRequiredStop NOTIFY switchAtRequiredStopChanged) - Q_PROPERTY(int ascrate75 READ ascrate75 WRITE setAscrate75 NOTIFY ascrate75Changed) - Q_PROPERTY(int ascrate50 READ ascrate50 WRITE setAscrate50 NOTIFY ascrate50Changed) - Q_PROPERTY(int ascratestops READ ascratestops WRITE setAscratestops NOTIFY ascratestopsChanged) - Q_PROPERTY(int ascratelast6m READ ascratelast6m WRITE setAscratelast6m NOTIFY ascratelast6mChanged) - Q_PROPERTY(int descrate READ descrate WRITE setDescrate NOTIFY descrateChanged) - Q_PROPERTY(int sacfactor READ sacfactor WRITE setSacFactor NOTIFY sacFactorChanged) - Q_PROPERTY(int problemsolvingtime READ problemsolvingtime WRITE setProblemSolvingTime NOTIFY problemSolvingTimeChanged) - Q_PROPERTY(int bottompo2 READ bottompo2 WRITE setBottompo2 NOTIFY bottompo2Changed) - Q_PROPERTY(int decopo2 READ decopo2 WRITE setDecopo2 NOTIFY decopo2Changed) - Q_PROPERTY(int bestmixend READ bestmixend WRITE setBestmixend NOTIFY bestmixendChanged) - Q_PROPERTY(int reserve_gas READ reserveGas WRITE setReserveGas NOTIFY reserveGasChanged) - Q_PROPERTY(int min_switch_duration READ minSwitchDuration WRITE setMinSwitchDuration NOTIFY minSwitchDurationChanged) - Q_PROPERTY(int bottomsac READ bottomSac WRITE setBottomSac NOTIFY bottomSacChanged) - Q_PROPERTY(int decosac READ decoSac WRITE setDecoSac NOTIFY decoSacChanged) - Q_PROPERTY(deco_mode decoMode READ decoMode WRITE setDecoMode NOTIFY decoModeChanged) - -public: - DivePlannerSettings(QObject *parent = 0); - bool lastStop() const; - bool verbatimPlan() const; - bool displayRuntime() const; - bool displayDuration() const; - bool displayTransitions() const; - bool displayVariations() const; - bool doo2breaks() const; - bool dropStoneMode() const; - bool safetyStop() const; - bool switchAtRequiredStop() const; - int ascrate75() const; - int ascrate50() const; - int ascratestops() const; - int ascratelast6m() const; - int descrate() const; - int sacfactor() const; - int problemsolvingtime() const; - int bottompo2() const; - int decopo2() const; - int bestmixend() const; - int reserveGas() const; - int minSwitchDuration() const; - int bottomSac() const; - int decoSac() const; - deco_mode decoMode() const; - -public slots: - void setLastStop(bool value); - void setVerbatimPlan(bool value); - void setDisplayRuntime(bool value); - void setDisplayDuration(bool value); - void setDisplayTransitions(bool value); - void setDisplayVariations(bool value); - void setDoo2breaks(bool value); - void setDropStoneMode(bool value); - void setSafetyStop(bool value); - void setSwitchAtRequiredStop(bool value); - void setAscrate75(int value); - void setAscrate50(int value); - void setAscratestops(int value); - void setAscratelast6m(int value); - void setDescrate(int value); - void setSacFactor(int value); - void setProblemSolvingTime(int value); - void setBottompo2(int value); - void setDecopo2(int value); - void setBestmixend(int value); - void setReserveGas(int value); - void setMinSwitchDuration(int value); - void setBottomSac(int value); - void setDecoSac(int value); - void setDecoMode(deco_mode value); - -signals: - void lastStopChanged(bool value); - void verbatimPlanChanged(bool value); - void displayRuntimeChanged(bool value); - void displayDurationChanged(bool value); - void displayTransitionsChanged(bool value); - void displayVariationsChanged(bool value); - void doo2breaksChanged(bool value); - void dropStoneModeChanged(bool value); - void safetyStopChanged(bool value); - void switchAtRequiredStopChanged(bool value); - void ascrate75Changed(int value); - void ascrate50Changed(int value); - void ascratestopsChanged(int value); - void ascratelast6mChanged(int value); - void descrateChanged(int value); - void sacFactorChanged(int value); - void problemSolvingTimeChanged(int value); - void bottompo2Changed(int value); - void decopo2Changed(int value); - void bestmixendChanged(int value); - void reserveGasChanged(int value); - void minSwitchDurationChanged(int value); - void bottomSacChanged(int value); - void decoSacChanged(int value); - void decoModeChanged(deco_mode value); - -private: - const QString group = QStringLiteral("Planner"); -}; - class GeneralSettingsObjectWrapper : public QObject { Q_OBJECT Q_PROPERTY(QString default_filename READ defaultFilename WRITE setDefaultFilename NOTIFY defaultFilenameChanged) @@ -472,9 +358,8 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(GeocodingPreferences* geocoding MEMBER geocoding CONSTANT) Q_PROPERTY(qPrefProxy* proxy MEMBER proxy CONSTANT) Q_PROPERTY(qPrefCloudStorage* cloud_storage MEMBER cloud_storage CONSTANT) - Q_PROPERTY(DivePlannerSettings* planner MEMBER planner_settings CONSTANT) + Q_PROPERTY(qPrefDivePlanner* planner MEMBER planner_settings CONSTANT) Q_PROPERTY(qPrefUnits* units MEMBER unit_settings CONSTANT) - Q_PROPERTY(GeneralSettingsObjectWrapper* general MEMBER general_settings CONSTANT) Q_PROPERTY(qPrefDisplay* display MEMBER display_settings CONSTANT) Q_PROPERTY(LanguageSettingsObjectWrapper* language MEMBER language_settings CONSTANT) @@ -492,7 +377,7 @@ public: GeocodingPreferences *geocoding; qPrefProxy *proxy; qPrefCloudStorage *cloud_storage; - DivePlannerSettings *planner_settings; + qPrefDivePlanner *planner_settings; qPrefUnits *unit_settings; GeneralSettingsObjectWrapper *general_settings; qPrefDisplay *display_settings; diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 7d4f1a5f5..e2f192f8e 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -599,27 +599,27 @@ void PlannerSettingsWidget::printDecoPlan() void PlannerSettingsWidget::setAscrate75(int rate) { - SettingsObjectWrapper::instance()->planner_settings->setAscrate75(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascrate75(lrint(rate * UNIT_FACTOR)); } void PlannerSettingsWidget::setAscrate50(int rate) { - SettingsObjectWrapper::instance()->planner_settings->setAscrate50(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascrate50(lrint(rate * UNIT_FACTOR)); } void PlannerSettingsWidget::setAscratestops(int rate) { - SettingsObjectWrapper::instance()->planner_settings->setAscratestops(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascratestops(lrint(rate * UNIT_FACTOR)); } void PlannerSettingsWidget::setAscratelast6m(int rate) { - SettingsObjectWrapper::instance()->planner_settings->setAscratelast6m(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascratelast6m(lrint(rate * UNIT_FACTOR)); } void PlannerSettingsWidget::setDescrate(int rate) { - SettingsObjectWrapper::instance()->planner_settings->setDescrate(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_descrate(lrint(rate * UNIT_FACTOR)); } void PlannerSettingsWidget::sacFactorChanged(const double factor) @@ -634,25 +634,25 @@ void PlannerSettingsWidget::problemSolvingTimeChanged(const int minutes) void PlannerSettingsWidget::setBottomPo2(double po2) { - SettingsObjectWrapper::instance()->planner_settings->setBottompo2((int) (po2 * 1000.0)); + qPrefDivePlanner::instance()->set_bottompo2((int) (po2 * 1000.0)); } void PlannerSettingsWidget::setDecoPo2(double po2) { pressure_t olddecopo2; olddecopo2.mbar = prefs.decopo2; - SettingsObjectWrapper::instance()->planner_settings->setDecopo2((int) (po2 * 1000.0)); + qPrefDivePlanner::instance()->set_decopo2((int) (po2 * 1000.0)); CylindersModel::instance()->updateDecoDepths(olddecopo2); } void PlannerSettingsWidget::setBestmixEND(int depth) { - SettingsObjectWrapper::instance()->planner_settings->setBestmixend(units_to_depth(depth).mm); + qPrefDivePlanner::instance()->set_bestmixend(units_to_depth(depth)); } void PlannerSettingsWidget::setBackgasBreaks(bool dobreaks) { - SettingsObjectWrapper::instance()->planner_settings->setDoo2breaks(dobreaks); + qPrefDivePlanner::instance()->set_doo2breaks(dobreaks); plannerModel->emitDataChanged(); } diff --git a/qt-models/diveplannermodel.cpp b/qt-models/diveplannermodel.cpp index 52c87071e..c26cac76a 100644 --- a/qt-models/diveplannermodel.cpp +++ b/qt-models/diveplannermodel.cpp @@ -427,30 +427,26 @@ void DivePlannerPointsModel::emitDataChanged() void DivePlannerPointsModel::setBottomSac(double sac) { diveplan.bottomsac = units_to_sac(sac); - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setBottomSac(diveplan.bottomsac); + qPrefDivePlanner::instance()->set_bottomsac(diveplan.bottomsac); emitDataChanged(); } void DivePlannerPointsModel::setDecoSac(double sac) { diveplan.decosac = units_to_sac(sac); - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDecoSac(diveplan.decosac); + qPrefDivePlanner::instance()->set_decosac(diveplan.decosac); emitDataChanged(); } void DivePlannerPointsModel::setSacFactor(double factor) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setSacFactor((int) round(factor * 100)); + qPrefDivePlanner::instance()->set_sacfactor((int) round(factor * 100)); emitDataChanged(); } void DivePlannerPointsModel::setProblemSolvingTime(int minutes) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setProblemSolvingTime(minutes); + qPrefDivePlanner::instance()->set_problemsolvingtime(minutes); emitDataChanged(); } @@ -508,110 +504,96 @@ int DivePlannerPointsModel::getSurfacePressure() void DivePlannerPointsModel::setLastStop6m(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setLastStop(value); + qPrefDivePlanner::instance()->set_last_stop(value); emitDataChanged(); } void DivePlannerPointsModel::setAscrate75(int rate) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setAscrate75(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascrate75(lrint(rate * UNIT_FACTOR)); emitDataChanged(); } void DivePlannerPointsModel::setAscrate50(int rate) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setAscrate50(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascrate50(lrint(rate * UNIT_FACTOR)); emitDataChanged(); } void DivePlannerPointsModel::setAscratestops(int rate) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setAscratestops(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascratestops(lrint(rate * UNIT_FACTOR)); emitDataChanged(); } void DivePlannerPointsModel::setAscratelast6m(int rate) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setAscratelast6m(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_ascratelast6m(lrint(rate * UNIT_FACTOR)); emitDataChanged(); } void DivePlannerPointsModel::setDescrate(int rate) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDescrate(lrint(rate * UNIT_FACTOR)); + qPrefDivePlanner::instance()->set_descrate(lrint(rate * UNIT_FACTOR)); emitDataChanged(); } void DivePlannerPointsModel::setVerbatim(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setVerbatimPlan(value); + qPrefDivePlanner::instance()->set_verbatim_plan(value); emitDataChanged(); } void DivePlannerPointsModel::setDisplayRuntime(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDisplayRuntime(value); + qPrefDivePlanner::instance()->set_display_runtime(value); emitDataChanged(); } void DivePlannerPointsModel::setDisplayDuration(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDisplayDuration(value); + qPrefDivePlanner::instance()->set_display_duration(value); emitDataChanged(); } void DivePlannerPointsModel::setDisplayTransitions(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDisplayTransitions(value); + qPrefDivePlanner::instance()->set_display_transitions(value); emitDataChanged(); } void DivePlannerPointsModel::setDisplayVariations(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDisplayVariations(value); + qPrefDivePlanner::instance()->set_display_variations(value); emitDataChanged(); } void DivePlannerPointsModel::setDecoMode(int mode) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDecoMode(deco_mode(mode)); + qPrefDivePlanner::instance()->set_planner_deco_mode(deco_mode(mode)); emit recreationChanged(mode == int(prefs.planner_deco_mode)); emitDataChanged(); } void DivePlannerPointsModel::setSafetyStop(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setSafetyStop(value); + qPrefDivePlanner::instance()->set_safetystop(value); emitDataChanged(); } void DivePlannerPointsModel::setReserveGas(int reserve) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; + auto planner = qPrefDivePlanner::instance(); if (prefs.units.pressure == units::BAR) - planner->setReserveGas(reserve * 1000); + planner->set_reserve_gas(reserve * 1000); else - planner->setReserveGas(psi_to_mbar(reserve)); + planner->set_reserve_gas(psi_to_mbar(reserve)); emitDataChanged(); } void DivePlannerPointsModel::setDropStoneMode(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setDropStoneMode(value); + qPrefDivePlanner::instance()->set_drop_stone_mode(value); if (prefs.drop_stone_mode) { /* Remove the first entry if we enable drop_stone_mode */ if (rowCount() >= 2) { @@ -633,15 +615,13 @@ void DivePlannerPointsModel::setDropStoneMode(bool value) void DivePlannerPointsModel::setSwitchAtReqStop(bool value) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setSwitchAtRequiredStop(value); + qPrefDivePlanner::instance()->set_switch_at_req_stop(value); emitDataChanged(); } void DivePlannerPointsModel::setMinSwitchDuration(int duration) { - auto planner = SettingsObjectWrapper::instance()->planner_settings; - planner->setMinSwitchDuration(duration * 60); + qPrefDivePlanner::instance()->set_min_switch_duration(duration * 60); emitDataChanged(); } diff --git a/subsurface-helper.cpp b/subsurface-helper.cpp index e59cab046..7b34aba1a 100644 --- a/subsurface-helper.cpp +++ b/subsurface-helper.cpp @@ -160,6 +160,7 @@ void register_qml_types() REGISTER_TYPE(qPrefCloudStorage, "SsrfCloudStoragePrefs"); REGISTER_TYPE(qPrefDisplay, "SsrfDisplayPrefs"); REGISTER_TYPE(qPrefDiveComputer, "SsrfDiveComputerPrefs"); + REGISTER_TYPE(qPrefDivePlanner, "SsrfDivePlannerPrefs"); REGISTER_TYPE(qPrefFacebook, "SsrfFacebookPrefs"); REGISTER_TYPE(qPrefProxy, "SsrfProxyPrefs"); REGISTER_TYPE(qPrefUnits, "SsrfUnitPrefs"); diff --git a/tests/testpreferences.cpp b/tests/testpreferences.cpp index 50c8472d8..345aaf094 100644 --- a/tests/testpreferences.cpp +++ b/tests/testpreferences.cpp @@ -177,41 +177,44 @@ void TestPreferences::testPreferences() TEST(geo->secondTaxonomyCategory(), TC_COUNTRY); TEST(geo->thirdTaxonomyCategory(), TC_NONE); - auto planner = pref->planner_settings; - planner->setLastStop(true); - planner->setVerbatimPlan(true); - planner->setDisplayRuntime(true); - planner->setDisplayDuration(true); - planner->setDisplayTransitions(true); - planner->setDoo2breaks(true); - planner->setDropStoneMode(true); - planner->setSafetyStop(true); - planner->setSwitchAtRequiredStop(true); - - planner->setAscrate75(1); - planner->setAscrate50(2); - planner->setAscratestops(3); - planner->setAscratelast6m(4); - planner->setDescrate(5); - planner->setBottompo2(6); - planner->setDecopo2(7); - planner->setBestmixend(8); - planner->setReserveGas(9); - planner->setMinSwitchDuration(10); - planner->setBottomSac(11); - planner->setDecoSac(12); - - planner->setDecoMode(BUEHLMANN); - - TEST(planner->lastStop(), true); - TEST(planner->verbatimPlan(), true); - TEST(planner->displayRuntime(), true); - TEST(planner->displayDuration(), true); - TEST(planner->displayTransitions(), true); + auto planner = qPrefDivePlanner::instance(); + depth_t x; + + planner->set_last_stop(true); + planner->set_verbatim_plan(true); + planner->set_display_runtime(true); + planner->set_display_duration(true); + planner->set_display_transitions(true); + planner->set_doo2breaks(true); + planner->set_drop_stone_mode(true); + planner->set_safetystop(true); + planner->set_switch_at_req_stop(true); + + planner->set_ascrate75(1); + planner->set_ascrate50(2); + planner->set_ascratestops(3); + planner->set_ascratelast6m(4); + planner->set_descrate(5); + planner->set_bottompo2(6); + planner->set_decopo2(7); + x.mm = 8; + planner->set_bestmixend(x); + planner->set_reserve_gas(9); + planner->set_min_switch_duration(10); + planner->set_bottomsac(11); + planner->set_decosac(12); + + planner->set_planner_deco_mode(BUEHLMANN); + + TEST(planner->last_stop(), true); + TEST(planner->verbatim_plan(), true); + TEST(planner->display_runtime(), true); + TEST(planner->display_duration(), true); + TEST(planner->display_transitions(), true); TEST(planner->doo2breaks(), true); - TEST(planner->dropStoneMode(), true); - TEST(planner->safetyStop(), true); - TEST(planner->switchAtRequiredStop(), true); + TEST(planner->drop_stone_mode(), true); + TEST(planner->safetystop(), true); + TEST(planner->switch_at_req_stop(), true); TEST(planner->ascrate75(), 1); TEST(planner->ascrate50(), 2); @@ -220,48 +223,49 @@ void TestPreferences::testPreferences() TEST(planner->descrate(), 5); TEST(planner->bottompo2(), 6); TEST(planner->decopo2(), 7); - TEST(planner->bestmixend(), 8); - TEST(planner->reserveGas(), 9); - TEST(planner->minSwitchDuration(), 10); - TEST(planner->bottomSac(), 11); - TEST(planner->decoSac(), 12); - - TEST(planner->decoMode(), BUEHLMANN); - - planner->setLastStop(false); - planner->setVerbatimPlan(false); - planner->setDisplayRuntime(false); - planner->setDisplayDuration(false); - planner->setDisplayTransitions(false); - planner->setDoo2breaks(false); - planner->setDropStoneMode(false); - planner->setSafetyStop(false); - planner->setSwitchAtRequiredStop(false); - - planner->setAscrate75(11); - planner->setAscrate50(12); - planner->setAscratestops(13); - planner->setAscratelast6m(14); - planner->setDescrate(15); - planner->setBottompo2(16); - planner->setDecopo2(17); - planner->setBestmixend(18); - planner->setReserveGas(19); - planner->setMinSwitchDuration(110); - planner->setBottomSac(111); - planner->setDecoSac(112); - - planner->setDecoMode(RECREATIONAL); - - TEST(planner->lastStop(), false); - TEST(planner->verbatimPlan(), false); - TEST(planner->displayRuntime(), false); - TEST(planner->displayDuration(), false); - TEST(planner->displayTransitions(), false); + TEST(planner->bestmixend().mm, 8); + TEST(planner->reserve_gas(), 9); + TEST(planner->min_switch_duration(), 10); + TEST(planner->bottomsac(), 11); + TEST(planner->decosac(), 12); + + TEST(planner->planner_deco_mode(), BUEHLMANN); + + planner->set_last_stop(false); + planner->set_verbatim_plan(false); + planner->set_display_runtime(false); + planner->set_display_duration(false); + planner->set_display_transitions(false); + planner->set_doo2breaks(false); + planner->set_drop_stone_mode(false); + planner->set_safetystop(false); + planner->set_switch_at_req_stop(false); + + planner->set_ascrate75(11); + planner->set_ascrate50(12); + planner->set_ascratestops(13); + planner->set_ascratelast6m(14); + planner->set_descrate(15); + planner->set_bottompo2(16); + planner->set_decopo2(17); + x.mm = 18; + planner->set_bestmixend(x); + planner->set_reserve_gas(19); + planner->set_min_switch_duration(110); + planner->set_bottomsac(111); + planner->set_decosac(112); + + planner->set_planner_deco_mode(RECREATIONAL); + + TEST(planner->last_stop(), false); + TEST(planner->verbatim_plan(), false); + TEST(planner->display_runtime(), false); + TEST(planner->display_duration(), false); + TEST(planner->display_transitions(), false); TEST(planner->doo2breaks(), false); - TEST(planner->dropStoneMode(), false); - TEST(planner->safetyStop(), false); - TEST(planner->switchAtRequiredStop(), false); + TEST(planner->drop_stone_mode(), false); + TEST(planner->safetystop(), false); + TEST(planner->switch_at_req_stop(), false); TEST(planner->ascrate75(), 11); TEST(planner->ascrate50(), 12); @@ -270,13 +274,13 @@ void TestPreferences::testPreferences() TEST(planner->descrate(), 15); TEST(planner->bottompo2(), 16); TEST(planner->decopo2(), 17); - TEST(planner->bestmixend(), 18); - TEST(planner->reserveGas(), 19); - TEST(planner->minSwitchDuration(), 110); - TEST(planner->bottomSac(), 111); - TEST(planner->decoSac(), 112); + TEST(planner->bestmixend().mm, 18); + TEST(planner->reserve_gas(), 19); + TEST(planner->min_switch_duration(), 110); + TEST(planner->bottomsac(), 111); + TEST(planner->decosac(), 112); - TEST(planner->decoMode(), RECREATIONAL); + TEST(planner->planner_deco_mode(), RECREATIONAL); auto general = pref->general_settings; general->setDefaultFilename("filename"); |