diff options
25 files changed, 369 insertions, 105 deletions
diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index c8c457432..ce4e6027b 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -211,6 +211,8 @@ set(SUBSURFACE_CORE_LIB_SRCS settings/qPrefUnit.h settings/qPrefUpdateManager.cpp settings/qPrefUpdateManager.h + settings/qPrefEquipment.cpp + settings/qPrefEquipment.h #Subsurface Qt have the Subsurface structs QObjectified for easy access via QML. subsurface-qt/CylinderObjectHelper.cpp diff --git a/core/pref.h b/core/pref.h index b02d9df99..1e8417af8 100644 --- a/core/pref.h +++ b/core/pref.h @@ -98,20 +98,23 @@ struct preferences { dive_computer_prefs_t dive_computer3; dive_computer_prefs_t dive_computer4; - // ********** Display ********** + // ********** Display ************* bool display_invalid_dives; const char *divelist_font; double font_size; double mobile_scale; bool show_developer; + // ********** Equipment tab ******* + const char *default_cylinder; + bool display_unused_tanks; + // ********** General ********** bool auto_recalculate_thumbnails; bool extract_video_thumbnails; int extract_video_thumbnails_position; // position in stream: 0=first 100=last second const char *ffmpeg_executable; // path of ffmpeg binary int defaultsetpoint; // default setpoint in mbar - const char *default_cylinder; const char *default_filename; enum def_file_behavior default_file_behavior; int o2consumption; // ml per min @@ -182,7 +185,6 @@ struct preferences { bool decoinfo; // Show deco info in infobox bool dcceiling; enum deco_mode display_deco_mode; - bool display_unused_tanks; bool ead; int gfhigh; int gflow; diff --git a/core/settings/qPref.cpp b/core/settings/qPref.cpp index 4c4a7961c..c70ad4dbe 100644 --- a/core/settings/qPref.cpp +++ b/core/settings/qPref.cpp @@ -14,6 +14,7 @@ #include "qPrefTechnicalDetails.h" #include "qPrefUnit.h" #include "qPrefUpdateManager.h" +#include "qPrefEquipment.h" #include <QtQml> #include <QQmlContext> @@ -38,6 +39,7 @@ void qPref::loadSync(bool doSync) qPrefTechnicalDetails::loadSync(doSync); qPrefUnits::loadSync(doSync); qPrefUpdateManager::loadSync(doSync); + qPrefEquipment::loadSync(doSync); } Q_DECLARE_METATYPE(deco_mode); @@ -61,6 +63,7 @@ void qPref::registerQML(QQmlEngine *engine) ct->setContextProperty("PrefTechnicalDetails", qPrefTechnicalDetails::instance()); ct->setContextProperty("PrefUnits", qPrefUnits::instance()); ct->setContextProperty("PrefUpdateManager", qPrefUpdateManager::instance()); + ct->setContextProperty("PrefEquipment", qPrefUpdateManager::instance()); } // Register special types diff --git a/core/settings/qPrefEquipment.cpp b/core/settings/qPrefEquipment.cpp new file mode 100644 index 000000000..f7bdb01e1 --- /dev/null +++ b/core/settings/qPrefEquipment.cpp @@ -0,0 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "qPrefEquipment.h" +#include "qPrefPrivate.h" + +static const QString group = QStringLiteral("Equipment"); + +qPrefEquipment *qPrefEquipment::instance() +{ + static qPrefEquipment *self = new qPrefEquipment; + return self; +} + +void qPrefEquipment::loadSync(bool doSync) +{ + disk_default_cylinder(doSync); + disk_display_unused_tanks(doSync); + +} + +HANDLE_PREFERENCE_TXT(Equipment, "default_cylinder", default_cylinder); +HANDLE_PREFERENCE_BOOL(Equipment, "display_unused_tanks", display_unused_tanks); + diff --git a/core/settings/qPrefEquipment.h b/core/settings/qPrefEquipment.h new file mode 100644 index 000000000..33fe9f8d6 --- /dev/null +++ b/core/settings/qPrefEquipment.h @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef QPREFEQUIPMENT_H +#define QPREFEQUIPMENT_H +#include "core/pref.h" + +#include <QObject> + +class qPrefEquipment : public QObject { + Q_OBJECT + Q_PROPERTY(QString default_cylinder READ default_cylinder WRITE set_default_cylinder NOTIFY default_cylinderChanged) + Q_PROPERTY(bool display_unused_tanks READ display_unused_tanks WRITE set_display_unused_tanks NOTIFY display_unused_tanksChanged) + +public: + static qPrefEquipment *instance(); + + // Load/Sync local settings (disk) and struct preference + static void loadSync(bool doSync); + static void load() { loadSync(false); } + static void sync() { loadSync(true); } + +public: + static QString default_cylinder() { return prefs.default_cylinder; } + static bool display_unused_tanks() { return prefs.display_unused_tanks; } + +public slots: + static void set_default_cylinder(const QString& value); + static void set_display_unused_tanks(bool value); + +signals: + void default_cylinderChanged(const QString& value); + void display_unused_tanksChanged(bool value); + +private: + qPrefEquipment() {} + static void disk_default_cylinder(bool doSync); + static void disk_display_unused_tanks(bool doSync); +}; + +#endif + diff --git a/core/settings/qPrefGeneral.cpp b/core/settings/qPrefGeneral.cpp index 766f5edbc..b3e9fb761 100644 --- a/core/settings/qPrefGeneral.cpp +++ b/core/settings/qPrefGeneral.cpp @@ -22,7 +22,6 @@ void qPrefGeneral::loadSync(bool doSync) { disk_auto_recalculate_thumbnails(doSync); disk_auto_recalculate_thumbnails(doSync); - disk_default_cylinder(doSync); disk_default_filename(doSync); disk_default_file_behavior(doSync); disk_defaultsetpoint(doSync); @@ -44,8 +43,6 @@ void qPrefGeneral::loadSync(bool doSync) HANDLE_PREFERENCE_BOOL(General, "auto_recalculate_thumbnails", auto_recalculate_thumbnails); -HANDLE_PREFERENCE_TXT(General, "default_cylinder", default_cylinder); - HANDLE_PREFERENCE_TXT(General, "default_filename", default_filename); diff --git a/core/settings/qPrefGeneral.h b/core/settings/qPrefGeneral.h index df45a56b8..c55063bd2 100644 --- a/core/settings/qPrefGeneral.h +++ b/core/settings/qPrefGeneral.h @@ -8,7 +8,6 @@ class qPrefGeneral : public QObject { Q_OBJECT Q_PROPERTY(bool auto_recalculate_thumbnails READ auto_recalculate_thumbnails WRITE set_auto_recalculate_thumbnails NOTIFY auto_recalculate_thumbnailsChanged) - Q_PROPERTY(QString default_cylinder READ default_cylinder WRITE set_default_cylinder NOTIFY default_cylinderChanged) Q_PROPERTY(QString default_filename READ default_filename WRITE set_default_filename NOTIFY default_filenameChanged) Q_PROPERTY(enum def_file_behavior default_file_behavior READ default_file_behavior WRITE set_default_file_behavior NOTIFY default_file_behaviorChanged) Q_PROPERTY(int defaultsetpoint READ defaultsetpoint WRITE set_defaultsetpoint NOTIFY defaultsetpointChanged) @@ -35,7 +34,6 @@ public: public: static bool auto_recalculate_thumbnails() { return prefs.auto_recalculate_thumbnails; } - static QString default_cylinder() { return prefs.default_cylinder; } static QString default_filename() { return prefs.default_filename; } static enum def_file_behavior default_file_behavior() { return prefs.default_file_behavior; } static int defaultsetpoint() { return prefs.defaultsetpoint; } @@ -53,7 +51,6 @@ public: public slots: static void set_auto_recalculate_thumbnails(bool value); - static void set_default_cylinder(const QString& value); static void set_default_filename(const QString& value); static void set_default_file_behavior(enum def_file_behavior value); static void set_defaultsetpoint(int value); @@ -71,7 +68,6 @@ public slots: signals: void auto_recalculate_thumbnailsChanged(bool value); - void default_cylinderChanged(const QString& value); void default_filenameChanged(const QString& value); void default_file_behaviorChanged(enum def_file_behavior value); void defaultsetpointChanged(int value); @@ -92,7 +88,6 @@ private: qPrefGeneral() {} static void disk_auto_recalculate_thumbnails(bool doSync); - static void disk_default_cylinder(bool doSync); static void disk_default_filename(bool doSync); static void disk_default_file_behavior(bool doSync); static void disk_defaultsetpoint(bool doSync); diff --git a/core/settings/qPrefTechnicalDetails.cpp b/core/settings/qPrefTechnicalDetails.cpp index cfa6cae0e..1d0e30c0c 100644 --- a/core/settings/qPrefTechnicalDetails.cpp +++ b/core/settings/qPrefTechnicalDetails.cpp @@ -20,7 +20,6 @@ void qPrefTechnicalDetails::loadSync(bool doSync) disk_calcndltts(doSync); disk_dcceiling(doSync); disk_display_deco_mode(doSync); - disk_display_unused_tanks(doSync); disk_ead(doSync); disk_gfhigh(doSync); disk_gflow(doSync); @@ -57,8 +56,6 @@ HANDLE_PREFERENCE_BOOL(TechnicalDetails, "dcceiling", dcceiling); HANDLE_PREFERENCE_ENUM(TechnicalDetails, deco_mode, "display_deco_mode", display_deco_mode); -HANDLE_PREFERENCE_BOOL(TechnicalDetails, "display_unused_tanks", display_unused_tanks); - HANDLE_PREFERENCE_BOOL(TechnicalDetails, "ead", ead); void qPrefTechnicalDetails::set_gfhigh(int value) diff --git a/core/settings/qPrefTechnicalDetails.h b/core/settings/qPrefTechnicalDetails.h index 68974e8bb..dfd477320 100644 --- a/core/settings/qPrefTechnicalDetails.h +++ b/core/settings/qPrefTechnicalDetails.h @@ -15,7 +15,6 @@ class qPrefTechnicalDetails : public QObject { Q_PROPERTY(bool decoinfo READ decoinfo WRITE set_decoinfo NOTIFY decoinfoChanged) Q_PROPERTY(bool dcceiling READ dcceiling WRITE set_dcceiling NOTIFY dcceilingChanged) Q_PROPERTY(deco_mode display_deco_mode READ display_deco_mode WRITE set_display_deco_mode NOTIFY display_deco_modeChanged) - Q_PROPERTY(bool display_unused_tanks READ display_unused_tanks WRITE set_display_unused_tanks NOTIFY display_unused_tanksChanged) Q_PROPERTY(bool ead READ ead WRITE set_ead NOTIFY eadChanged) Q_PROPERTY(int gfhigh READ gfhigh WRITE set_gfhigh NOTIFY gfhighChanged) Q_PROPERTY(int gflow READ gflow WRITE set_gflow NOTIFY gflowChanged) @@ -53,7 +52,6 @@ public: static bool decoinfo() { return prefs.decoinfo; } static bool dcceiling() { return prefs.dcceiling; } static deco_mode display_deco_mode() { return prefs.display_deco_mode; } - static bool display_unused_tanks() { return prefs.display_unused_tanks; } static bool ead() { return prefs.ead; } static int gfhigh() { return prefs.gfhigh; } static int gflow() { return prefs.gflow; } @@ -83,7 +81,6 @@ public slots: static void set_decoinfo(bool value); static void set_dcceiling(bool value); static void set_display_deco_mode(deco_mode value); - static void set_display_unused_tanks(bool value); static void set_ead(bool value); static void set_gfhigh(int value); static void set_gflow(int value); @@ -113,7 +110,6 @@ signals: void decoinfoChanged(bool value); void dcceilingChanged(bool value); void display_deco_modeChanged(deco_mode value); - void display_unused_tanksChanged(bool value); void eadChanged(bool value); void gfhighChanged(int value); void gflowChanged(int value); @@ -145,7 +141,6 @@ private: static void disk_decoinfo(bool doSync); static void disk_dcceiling(bool doSync); static void disk_display_deco_mode(bool doSync); - static void disk_display_unused_tanks(bool doSync); static void disk_ead(bool doSync); static void disk_gfhigh(bool doSync); static void disk_gflow(bool doSync); diff --git a/desktop-widgets/preferences/CMakeLists.txt b/desktop-widgets/preferences/CMakeLists.txt index 6f7f657cb..af6071934 100644 --- a/desktop-widgets/preferences/CMakeLists.txt +++ b/desktop-widgets/preferences/CMakeLists.txt @@ -12,6 +12,7 @@ set(SUBSURFACE_PREFERENCES_UI preferences_units.ui preferences_georeference.ui preferences_language.ui + preferences_equipment.ui ) qt5_wrap_ui(SUBSURFACE_PREFERENCES_UI_HDRS ${SUBSURFACE_PREFERENCES_UI}) @@ -23,6 +24,8 @@ set(SUBSURFACE_PREFERENCES_LIB_SRCS abstractpreferenceswidget.h preferences_defaults.cpp preferences_defaults.h + preferences_equipment.cpp + preferences_equipment.h preferences_georeference.cpp preferences_georeference.h preferences_graph.cpp diff --git a/desktop-widgets/preferences/preferences_defaults.cpp b/desktop-widgets/preferences/preferences_defaults.cpp index f439b0702..e0df807b0 100644 --- a/desktop-widgets/preferences/preferences_defaults.cpp +++ b/desktop-widgets/preferences/preferences_defaults.cpp @@ -109,12 +109,6 @@ void PreferencesDefaults::refreshSettings() ui->cloudDefaultFile->setChecked(qPrefGeneral::default_file_behavior() == CLOUD_DEFAULT_FILE); ui->localDefaultFile->setChecked(qPrefGeneral::default_file_behavior() == LOCAL_DEFAULT_FILE); - ui->default_cylinder->clear(); - for (int i = 0; i < MAX_TANK_INFO && tank_info[i].name != NULL; i++) { - ui->default_cylinder->addItem(tank_info[i].name); - if (qPrefGeneral::default_cylinder() == tank_info[i].name) - ui->default_cylinder->setCurrentIndex(i); - } ui->displayinvalid->setChecked(qPrefDisplay::display_invalid_dives()); ui->velocitySlider->setValue(qPrefDisplay::animation_speed()); ui->btnUseDefaultFile->setChecked(qPrefGeneral::use_default_file()); @@ -145,7 +139,6 @@ void PreferencesDefaults::syncSettings() { auto general = qPrefGeneral::instance(); general->set_default_filename(ui->defaultfilename->text()); - general->set_default_cylinder(ui->default_cylinder->currentText()); general->set_use_default_file(ui->btnUseDefaultFile->isChecked()); if (ui->noDefaultFile->isChecked()) general->set_default_file_behavior(NO_DEFAULT_FILE); diff --git a/desktop-widgets/preferences/preferences_defaults.ui b/desktop-widgets/preferences/preferences_defaults.ui index b1538f33d..60b478206 100644 --- a/desktop-widgets/preferences/preferences_defaults.ui +++ b/desktop-widgets/preferences/preferences_defaults.ui @@ -142,38 +142,6 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_6"> - <property name="title"> - <string>Default cylinder</string> - </property> - <layout class="QFormLayout" name="formLayout_6"> - <property name="horizontalSpacing"> - <number>5</number> - </property> - <property name="verticalSpacing"> - <number>5</number> - </property> - <property name="margin"> - <number>5</number> - </property> - <item row="0" column="0"> - <widget class="QLabel" name="label_11"> - <property name="text"> - <string>Use default cylinder</string> - </property> - </widget> - </item> - <item row="0" column="1"> - <layout class="QHBoxLayout" name="horizontalLayout_3"> - <item> - <widget class="QComboBox" name="default_cylinder"/> - </item> - </layout> - </item> - </layout> - </widget> - </item> - <item> <widget class="QGroupBox" name="groupBox_7"> <property name="title"> <string>Animations</string> diff --git a/desktop-widgets/preferences/preferences_equipment.cpp b/desktop-widgets/preferences/preferences_equipment.cpp new file mode 100644 index 000000000..a446a279b --- /dev/null +++ b/desktop-widgets/preferences/preferences_equipment.cpp @@ -0,0 +1,41 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "preferences_equipment.h" +#include "ui_preferences_equipment.h" +#include "core/settings/qPrefEquipment.h" +#include "core/qthelper.h" +#include "core/dive.h" + +#include <QApplication> +#include <QMessageBox> +#include <QSortFilterProxyModel> + +#include "qt-models/models.h" + +PreferencesEquipment::PreferencesEquipment() : AbstractPreferencesWidget(tr("Equipment"), QIcon(":preferences-equipment-icon"), 4) +{ + ui = new Ui::PreferencesEquipment(); + ui->setupUi(this); +} + +PreferencesEquipment::~PreferencesEquipment() +{ + delete ui; +} + +void PreferencesEquipment::refreshSettings() +{ + ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); + ui->default_cylinder->clear(); + for (int i = 0; i < MAX_TANK_INFO && tank_info[i].name != NULL; i++) { + ui->default_cylinder->addItem(tank_info[i].name); + if (qPrefEquipment::default_cylinder() == tank_info[i].name) + ui->default_cylinder->setCurrentIndex(i); + } +} + +void PreferencesEquipment::syncSettings() +{ + auto equipment = qPrefEquipment::instance(); + qPrefEquipment::set_display_unused_tanks(ui->display_unused_tanks->isChecked()); + equipment->set_default_cylinder(ui->default_cylinder->currentText()); +} diff --git a/desktop-widgets/preferences/preferences_equipment.h b/desktop-widgets/preferences/preferences_equipment.h new file mode 100644 index 000000000..09402aa00 --- /dev/null +++ b/desktop-widgets/preferences/preferences_equipment.h @@ -0,0 +1,25 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef PREFERENCES_EQUIPMENT_H +#define PREFERENCES_EQUIPMENT_H + +#include <QMap> +#include "abstractpreferenceswidget.h" + +namespace Ui { + class PreferencesEquipment; +} + +class PreferencesEquipment : public AbstractPreferencesWidget { + Q_OBJECT +public: + PreferencesEquipment(); + ~PreferencesEquipment(); + void refreshSettings() override; + void syncSettings() override; +private: + Ui::PreferencesEquipment *ui; +public slots: + +}; + +#endif diff --git a/desktop-widgets/preferences/preferences_equipment.ui b/desktop-widgets/preferences/preferences_equipment.ui new file mode 100644 index 000000000..4526f9618 --- /dev/null +++ b/desktop-widgets/preferences/preferences_equipment.ui @@ -0,0 +1,93 @@ +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> + <class>PreferencesEquipment</class> + <widget class="QWidget" name="PreferencesEquipment"> + <property name="geometry"> + <rect> + <x>0</x> + <y>0</y> + <width>621</width> + <height>523</height> + </rect> + </property> + <property name="windowTitle"> + <string>Form</string> + </property> + <layout class="QVBoxLayout" name="verticalLayout"> + + <item> + <widget class="QLabel" name="label_cylinders"> + <property name="enabled"> + <bool>true</bool> + </property> + <property name="text"> + <string>CYLINDERS</string> + </property> + </widget> + </item> + + <item> + <widget class="QGroupBox" name="groupBox_6"> + <property name="title"> + <string>Default cylinder in the Cylinders table of the Equipment tab</string> + </property> + <layout class="QFormLayout" name="formLayout_6"> + <property name="horizontalSpacing"> + <number>5</number> + </property> + <property name="verticalSpacing"> + <number>5</number> + </property> + <property name="margin"> + <number>5</number> + </property> + + <item row="0" column="0"> + <widget class="QLabel" name="label_11"> + <property name="text"> + <string>Select a default cylinder</string> + </property> + </widget> + </item> + + <item row="0" column="1"> + <layout class="QHBoxLayout" name="horizontalLayout_3"> + <item> + <widget class="QComboBox" name="default_cylinder"/> + </item> + </layout> + </item> + + </layout> + </widget> + </item> + + <item> + <widget class="QCheckBox" name="display_unused_tanks"> + <property name="text"> + <string>Show unused cylinders in the Cylinders table of the Equipment tab</string> + </property> + </widget> + </item> + + <item> + <spacer name="verticalSpacer"> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> + </item> + + + </layout> + </widget> + + <resources/> + <connections/> +</ui> diff --git a/desktop-widgets/preferences/preferences_graph.cpp b/desktop-widgets/preferences/preferences_graph.cpp index 74c248dc4..54a63fd71 100644 --- a/desktop-widgets/preferences/preferences_graph.cpp +++ b/desktop-widgets/preferences/preferences_graph.cpp @@ -49,7 +49,6 @@ void PreferencesGraph::refreshSettings() ui->psro2rate->setValue(prefs.o2consumption / 1000.0); ui->pscrfactor->setValue(lrint(1000.0 / prefs.pscr_ratio)); - ui->display_unused_tanks->setChecked(prefs.display_unused_tanks); ui->show_average_depth->setChecked(prefs.show_average_depth); ui->auto_recalculate_thumbnails->setChecked(prefs.auto_recalculate_thumbnails); ui->show_icd->setChecked(prefs.show_icd); @@ -78,7 +77,6 @@ void PreferencesGraph::syncSettings() qPrefTechnicalDetails::set_show_ccr_setpoint(ui->show_ccr_setpoint->isChecked()); qPrefTechnicalDetails::set_show_ccr_sensors(ui->show_ccr_sensors->isChecked()); qPrefTechnicalDetails::set_show_scr_ocpo2(ui->show_scr_ocpo2->isChecked()); - qPrefTechnicalDetails::set_display_unused_tanks(ui->display_unused_tanks->isChecked()); qPrefTechnicalDetails::set_show_average_depth(ui->show_average_depth->isChecked()); qPrefTechnicalDetails::set_show_icd(ui->show_icd->isChecked()); qPrefTechnicalDetails::set_display_deco_mode(ui->vpmb->isChecked() ? VPMB : BUEHLMANN); diff --git a/desktop-widgets/preferences/preferences_graph.ui b/desktop-widgets/preferences/preferences_graph.ui index b70a5ff29..ab7e12f87 100644 --- a/desktop-widgets/preferences/preferences_graph.ui +++ b/desktop-widgets/preferences/preferences_graph.ui @@ -355,20 +355,13 @@ </property> <layout class="QGridLayout" name="gridLayout_2"> <item row="0" column="0" colspan="2"> - <widget class="QCheckBox" name="display_unused_tanks"> - <property name="text"> - <string>Show unused cylinders in Equipment tab</string> - </property> - </widget> - </item> - <item row="1" column="0" colspan="2"> <widget class="QCheckBox" name="show_average_depth"> <property name="text"> <string>Show mean depth in Profile</string> </property> </widget> </item> - <item row="2" column="0" colspan="2"> + <item row="1" column="0" colspan="2"> <widget class="QCheckBox" name="auto_recalculate_thumbnails"> <property name="text"> <string>Recalculate thumbnails if older than media file</string> diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index 9e1e6a7bf..508321ac5 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -9,6 +9,7 @@ #include "preferences_graph.h" #include "preferences_network.h" #include "preferences_cloud.h" +#include "preferences_equipment.h" #include "core/qthelper.h" @@ -67,6 +68,7 @@ PreferencesDialog::PreferencesDialog() addPreferencePage(new PreferencesGraph()); addPreferencePage(new PreferencesNetwork()); addPreferencePage(new PreferencesCloud()); + addPreferencePage(new PreferencesEquipment()); refreshPages(); connect(pagesList, &QListWidget::currentRowChanged, diff --git a/icons/pref_equipment.png b/icons/pref_equipment.png Binary files differnew file mode 100644 index 000000000..67bf29b3c --- /dev/null +++ b/icons/pref_equipment.png diff --git a/subsurface.qrc b/subsurface.qrc index da108a8df..c360b5944 100644 --- a/subsurface.qrc +++ b/subsurface.qrc @@ -13,6 +13,7 @@ <file alias="advanced-icon">icons/advanced.png</file> <file alias="preferences-system-network-icon">icons/network.png</file> <file alias="preferences-cloud-icon">icons/pref_cloud.png</file> + <file alias="preferences-equipment-icon">icons/pref_equipment.png</file> <file alias="scale-graph-icon">icons/graph.png</file> <file alias="value-minimum-icon">icons/minimum.png</file> <file alias="value-maximum-icon">icons/maximum.png</file> diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 887e1b34d..07452f7a1 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -110,6 +110,7 @@ TEST(TestQPrefDisplay testqPrefDisplay.cpp) TEST(TestQPrefDiveComputer testqPrefDiveComputer.cpp) TEST(TestQPrefDivePlanner testqPrefDivePlanner.cpp) TEST(TestQPrefGeneral testqPrefGeneral.cpp) +TEST(TestQPrefEquipment testqPrefEquipment.cpp) TEST(TestQPrefGeocoding testqPrefGeocoding.cpp) TEST(TestQPrefLanguage testqPrefLanguage.cpp) TEST(TestQPrefLocationService testqPrefLocationService.cpp) @@ -141,6 +142,7 @@ add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND} TestQPrefDiveComputer TestQPrefDivePlanner TestQPrefGeneral + TestQPrefEquipment TestQPrefGeocoding TestQPrefLanguage TestQPrefLocationService diff --git a/tests/testqPrefEquipment.cpp b/tests/testqPrefEquipment.cpp new file mode 100644 index 000000000..29d1baccb --- /dev/null +++ b/tests/testqPrefEquipment.cpp @@ -0,0 +1,109 @@ +// SPDX-License-Identifier: GPL-2.0 +#include "testqPrefEquipment.h" + +#include "core/pref.h" +#include "core/qthelper.h" +#include "core/settings/qPrefEquipment.h" +#include "core/settings/qPref.h" + +#include <QTest> +#include <QSignalSpy> + +void TestQPrefEquipment::initTestCase() +{ + QCoreApplication::setOrganizationName("Subsurface"); + QCoreApplication::setOrganizationDomain("subsurface.hohndel.org"); + QCoreApplication::setApplicationName("SubsurfaceTestQPrefEquipment"); + qPref::registerQML(NULL); +} + +void TestQPrefEquipment::test_struct_get() +{ + // Test struct pref -> get func. + + auto tst = qPrefEquipment::instance(); + prefs.default_cylinder = copy_qstring("new base11"); + QCOMPARE(tst->default_cylinder(), QString(prefs.default_cylinder)); + prefs.display_unused_tanks = true; + QCOMPARE(tst->display_unused_tanks(), prefs.display_unused_tanks); +} + +void TestQPrefEquipment::test_set_struct() +{ + // Test set func -> struct pref + + auto tst = qPrefEquipment::instance(); + tst->set_default_cylinder("new base21"); + QCOMPARE(QString(prefs.default_cylinder), QString("new base21")); + tst->set_display_unused_tanks(false); + QCOMPARE(prefs.display_unused_tanks, false); +} + +void TestQPrefEquipment::test_set_load_struct() +{ + // test set func -> load -> struct pref + + auto tst = qPrefEquipment::instance(); + + tst->set_default_cylinder("new base31"); + prefs.default_cylinder = copy_qstring("error"); + tst->set_display_unused_tanks(false); + prefs.display_unused_tanks = true; + tst->load(); + QCOMPARE(QString(prefs.default_cylinder), QString("new base31")); + QCOMPARE(prefs.display_unused_tanks, false); +} + +void TestQPrefEquipment::test_struct_disk() +{ + // test struct prefs -> disk + + auto tst = qPrefEquipment::instance(); + prefs.default_cylinder = copy_qstring("base41"); + prefs.display_unused_tanks = true; + + tst->sync(); + prefs.default_cylinder = copy_qstring("error"); + prefs.display_unused_tanks = false; + + tst->load(); + QCOMPARE(QString(prefs.default_cylinder), QString("base41")); + QCOMPARE(prefs.display_unused_tanks, true); + +} + +#define TEST(METHOD, VALUE) \ + QCOMPARE(METHOD, VALUE); \ + equipment->sync(); \ + equipment->load(); \ + QCOMPARE(METHOD, VALUE); + +void TestQPrefEquipment::test_oldPreferences() +{ + auto equipment = qPrefEquipment::instance(); + equipment->set_default_cylinder("cylinder_2"); + TEST(equipment->default_cylinder(), QStringLiteral("cylinder_2")); + equipment->set_default_cylinder("cylinder_1"); + TEST(equipment->default_cylinder(), QStringLiteral("cylinder_1")); + equipment->set_display_unused_tanks(true); + TEST(equipment->display_unused_tanks(), true); + equipment->set_display_unused_tanks(false); + TEST(equipment->display_unused_tanks(), false); +} + +void TestQPrefEquipment::test_signals() +{ + QSignalSpy spy1(qPrefEquipment::instance(), &qPrefEquipment::default_cylinderChanged); + QSignalSpy spy2(qPrefEquipment::instance(), &qPrefEquipment::display_unused_tanksChanged); + + qPrefEquipment::set_default_cylinder("new base21"); + QCOMPARE(spy1.count(), 1); + QVERIFY(spy1.takeFirst().at(0).toBool() == false); + + prefs.display_unused_tanks = true; + qPrefEquipment::set_display_unused_tanks(false); + QCOMPARE(spy2.count(), 1); + QVERIFY(spy2.takeFirst().at(0).toBool() == false); +} + +QTEST_MAIN(TestQPrefEquipment) diff --git a/tests/testqPrefEquipment.h b/tests/testqPrefEquipment.h new file mode 100644 index 000000000..b9a4bcee2 --- /dev/null +++ b/tests/testqPrefEquipment.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef TESTQPREFEQUIPMENT_H +#define TESTQPREFEQUIPMENT_H + +#include <QObject> + +class TestQPrefEquipment : public QObject { + Q_OBJECT + +private slots: + void initTestCase(); + void test_struct_get(); + void test_set_struct(); + void test_set_load_struct(); + void test_struct_disk(); + void test_oldPreferences(); + void test_signals(); +}; + +#endif // TESTQPREFEQUIPMENT_H diff --git a/tests/testqPrefGeneral.cpp b/tests/testqPrefGeneral.cpp index 29ff6a811..1463b914b 100644 --- a/tests/testqPrefGeneral.cpp +++ b/tests/testqPrefGeneral.cpp @@ -24,7 +24,6 @@ void TestQPrefGeneral::test_struct_get() auto tst = qPrefGeneral::instance(); prefs.auto_recalculate_thumbnails = true; - prefs.default_cylinder = copy_qstring("new base11"); prefs.default_filename = copy_qstring("new base12"); prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE; prefs.defaultsetpoint = 14; @@ -36,7 +35,6 @@ void TestQPrefGeneral::test_struct_get() prefs.use_default_file = true; QCOMPARE(tst->auto_recalculate_thumbnails(), prefs.auto_recalculate_thumbnails); - QCOMPARE(tst->default_cylinder(), QString(prefs.default_cylinder)); QCOMPARE(tst->default_filename(), QString(prefs.default_filename)); QCOMPARE(tst->default_file_behavior(), prefs.default_file_behavior); QCOMPARE(tst->defaultsetpoint(), prefs.defaultsetpoint); @@ -55,7 +53,6 @@ void TestQPrefGeneral::test_set_struct() auto tst = qPrefGeneral::instance(); tst->set_auto_recalculate_thumbnails(false); - tst->set_default_cylinder("new base21"); tst->set_default_filename("new base22"); tst->set_default_file_behavior(LOCAL_DEFAULT_FILE); tst->set_defaultsetpoint(24); @@ -69,7 +66,6 @@ void TestQPrefGeneral::test_set_struct() tst->set_diveshareExport_private(false); QCOMPARE(prefs.auto_recalculate_thumbnails, false); - QCOMPARE(QString(prefs.default_cylinder), QString("new base21")); QCOMPARE(QString(prefs.default_filename), QString("new base22")); QCOMPARE(prefs.default_file_behavior, LOCAL_DEFAULT_FILE); QCOMPARE(prefs.defaultsetpoint, 24); @@ -90,7 +86,6 @@ void TestQPrefGeneral::test_set_load_struct() auto tst = qPrefGeneral::instance(); tst->set_auto_recalculate_thumbnails(true); - tst->set_default_cylinder("new base31"); tst->set_default_filename("new base32"); tst->set_default_file_behavior(NO_DEFAULT_FILE); tst->set_defaultsetpoint(34); @@ -104,7 +99,6 @@ void TestQPrefGeneral::test_set_load_struct() tst->set_diveshareExport_private(true); prefs.auto_recalculate_thumbnails = false; - prefs.default_cylinder = copy_qstring("error"); prefs.default_filename = copy_qstring("error"); prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE; prefs.defaultsetpoint = 14; @@ -117,7 +111,6 @@ void TestQPrefGeneral::test_set_load_struct() tst->load(); QCOMPARE(prefs.auto_recalculate_thumbnails, true); - QCOMPARE(QString(prefs.default_cylinder), QString("new base31")); QCOMPARE(QString(prefs.default_filename), QString("new base32")); QCOMPARE(prefs.default_file_behavior, NO_DEFAULT_FILE); QCOMPARE(prefs.defaultsetpoint, 34); @@ -138,7 +131,6 @@ void TestQPrefGeneral::test_struct_disk() auto tst = qPrefGeneral::instance(); prefs.auto_recalculate_thumbnails = true; - prefs.default_cylinder = copy_qstring("base41"); prefs.default_filename = copy_qstring("base42"); prefs.default_file_behavior = CLOUD_DEFAULT_FILE; prefs.defaultsetpoint = 44; @@ -151,7 +143,6 @@ void TestQPrefGeneral::test_struct_disk() tst->sync(); prefs.auto_recalculate_thumbnails = false; - prefs.default_cylinder = copy_qstring("error"); prefs.default_filename = copy_qstring("error"); prefs.default_file_behavior = UNDEFINED_DEFAULT_FILE; prefs.defaultsetpoint = 14; @@ -164,7 +155,6 @@ void TestQPrefGeneral::test_struct_disk() tst->load(); QCOMPARE(prefs.auto_recalculate_thumbnails, true); - QCOMPARE(QString(prefs.default_cylinder), QString("base41")); QCOMPARE(QString(prefs.default_filename), QString("base42")); QCOMPARE(prefs.default_file_behavior, CLOUD_DEFAULT_FILE); QCOMPARE(prefs.defaultsetpoint, 44); @@ -201,7 +191,6 @@ void TestQPrefGeneral::test_oldPreferences() auto general = qPrefGeneral::instance(); general->set_default_filename("filename"); - general->set_default_cylinder("cylinder_2"); general->set_default_file_behavior(LOCAL_DEFAULT_FILE); general->set_defaultsetpoint(0); general->set_o2consumption(0); @@ -209,7 +198,6 @@ void TestQPrefGeneral::test_oldPreferences() general->set_use_default_file(true); TEST(general->default_filename(), QStringLiteral("filename")); - TEST(general->default_cylinder(), QStringLiteral("cylinder_2")); TEST(general->default_file_behavior(), LOCAL_DEFAULT_FILE); // since we have a default file, here it returns TEST(general->defaultsetpoint(), 0); TEST(general->o2consumption(), 0); @@ -217,7 +205,6 @@ void TestQPrefGeneral::test_oldPreferences() TEST(general->use_default_file(), true); general->set_default_filename("no_file_name"); - general->set_default_cylinder("cylinder_1"); //TODOl: Change this to a enum. general->set_default_file_behavior(CLOUD_DEFAULT_FILE); @@ -227,7 +214,6 @@ void TestQPrefGeneral::test_oldPreferences() general->set_use_default_file(false); TEST(general->default_filename(), QStringLiteral("no_file_name")); - TEST(general->default_cylinder(), QStringLiteral("cylinder_1")); TEST(general->default_file_behavior(), CLOUD_DEFAULT_FILE); TEST(general->defaultsetpoint(), 1); TEST(general->o2consumption(), 1); @@ -238,7 +224,6 @@ void TestQPrefGeneral::test_oldPreferences() void TestQPrefGeneral::test_signals() { QSignalSpy spy1(qPrefGeneral::instance(), &qPrefGeneral::auto_recalculate_thumbnailsChanged); - QSignalSpy spy2(qPrefGeneral::instance(), &qPrefGeneral::default_cylinderChanged); QSignalSpy spy3(qPrefGeneral::instance(), &qPrefGeneral::default_filenameChanged); QSignalSpy spy4(qPrefGeneral::instance(), &qPrefGeneral::default_file_behaviorChanged); QSignalSpy spy5(qPrefGeneral::instance(), &qPrefGeneral::defaultsetpointChanged); @@ -254,7 +239,6 @@ void TestQPrefGeneral::test_signals() prefs.auto_recalculate_thumbnails = true; qPrefGeneral::set_auto_recalculate_thumbnails(false); - qPrefGeneral::set_default_cylinder("new base21"); qPrefGeneral::set_default_filename("new base22"); qPrefGeneral::set_default_file_behavior(LOCAL_DEFAULT_FILE); qPrefGeneral::set_defaultsetpoint(24); @@ -271,7 +255,6 @@ void TestQPrefGeneral::test_signals() QVERIFY(spy1.takeFirst().at(0).toBool() == false); - qPrefGeneral::set_default_cylinder("new base21"); qPrefGeneral::set_default_filename("new base22"); qPrefGeneral::set_default_file_behavior(LOCAL_DEFAULT_FILE); qPrefGeneral::set_defaultsetpoint(24); @@ -285,5 +268,4 @@ void TestQPrefGeneral::test_signals() qPrefGeneral::set_diveshareExport_private(false); } - QTEST_MAIN(TestQPrefGeneral) diff --git a/tests/testqPrefTechnicalDetails.cpp b/tests/testqPrefTechnicalDetails.cpp index 9b6d88a45..b6272dbff 100644 --- a/tests/testqPrefTechnicalDetails.cpp +++ b/tests/testqPrefTechnicalDetails.cpp @@ -29,7 +29,6 @@ void TestQPrefTechnicalDetails::test_struct_get() prefs.calcndltts = true; prefs.dcceiling = true; prefs.display_deco_mode = BUEHLMANN; - prefs.display_unused_tanks = true; prefs.ead = true; prefs.gfhigh = 27; prefs.gflow = 25; @@ -56,7 +55,6 @@ void TestQPrefTechnicalDetails::test_struct_get() QCOMPARE(tst->calcndltts(), prefs.calcndltts); QCOMPARE(tst->dcceiling(), prefs.dcceiling); QCOMPARE(tst->display_deco_mode(), prefs.display_deco_mode); - QCOMPARE(tst->display_unused_tanks(), prefs.display_unused_tanks); QCOMPARE(tst->ead(), prefs.ead); QCOMPARE(tst->gfhigh(), prefs.gfhigh); QCOMPARE(tst->gflow(), prefs.gflow); @@ -91,7 +89,6 @@ void TestQPrefTechnicalDetails::test_set_struct() tst->set_calcndltts(false); tst->set_dcceiling(false); tst->set_display_deco_mode(RECREATIONAL); - tst->set_display_unused_tanks(false); tst->set_ead(false); tst->set_gfhigh(29); tst->set_gflow(24); @@ -118,7 +115,6 @@ void TestQPrefTechnicalDetails::test_set_struct() QCOMPARE(prefs.calcndltts, false); QCOMPARE(prefs.dcceiling, false); QCOMPARE(prefs.display_deco_mode, RECREATIONAL); - QCOMPARE(prefs.display_unused_tanks, false); QCOMPARE(prefs.ead, false); QCOMPARE(prefs.gfhigh, 29); QCOMPARE(prefs.gflow, 24); @@ -153,7 +149,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct() tst->set_calcndltts(false); tst->set_dcceiling(true); tst->set_display_deco_mode(RECREATIONAL); - tst->set_display_unused_tanks(false); tst->set_ead(false); tst->set_gfhigh(29); tst->set_gflow(24); @@ -181,7 +176,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct() prefs.calcndltts = true; prefs.dcceiling = false; prefs.display_deco_mode = BUEHLMANN; - prefs.display_unused_tanks = true; prefs.ead = true; prefs.gfhigh = 27; prefs.gflow = 25; @@ -209,7 +203,6 @@ void TestQPrefTechnicalDetails::test_set_load_struct() QCOMPARE(prefs.calcndltts, false); QCOMPARE(prefs.dcceiling, true); QCOMPARE(prefs.display_deco_mode, RECREATIONAL); - QCOMPARE(prefs.display_unused_tanks, false); QCOMPARE(prefs.ead, false); QCOMPARE((int)prefs.gfhigh, 29); QCOMPARE((int)prefs.gflow, 24); @@ -244,7 +237,6 @@ void TestQPrefTechnicalDetails::test_struct_disk() prefs.calcndltts = true; prefs.dcceiling = true; prefs.display_deco_mode = BUEHLMANN; - prefs.display_unused_tanks = true; prefs.ead = true; prefs.gfhigh = 11; prefs.gflow = 12; @@ -273,7 +265,6 @@ void TestQPrefTechnicalDetails::test_struct_disk() prefs.calcndltts = false; prefs.dcceiling = false; prefs.display_deco_mode = RECREATIONAL; - prefs.display_unused_tanks = false; prefs.ead = false; prefs.gfhigh = 27; prefs.gflow = 25; @@ -301,7 +292,6 @@ void TestQPrefTechnicalDetails::test_struct_disk() QCOMPARE(prefs.calcndltts, true); QCOMPARE(prefs.dcceiling, true); QCOMPARE(prefs.display_deco_mode, BUEHLMANN); - QCOMPARE(prefs.display_unused_tanks, true); QCOMPARE(prefs.ead, true); QCOMPARE(prefs.gfhigh, 11); QCOMPARE(prefs.gflow, 12); @@ -399,8 +389,6 @@ void TestQPrefTechnicalDetails::test_oldPreferences() TEST(tecDetails->zoomed_plot(), true); tecDetails->set_show_sac(true); TEST(tecDetails->show_sac(), true); - tecDetails->set_display_unused_tanks(true); - TEST(tecDetails->display_unused_tanks(), true); tecDetails->set_show_average_depth(true); TEST(tecDetails->show_average_depth(), true); tecDetails->set_show_pictures_in_profile(true); @@ -438,8 +426,6 @@ void TestQPrefTechnicalDetails::test_oldPreferences() TEST(tecDetails->zoomed_plot(), false); tecDetails->set_show_sac(false); TEST(tecDetails->show_sac(), false); - tecDetails->set_display_unused_tanks(false); - TEST(tecDetails->display_unused_tanks(), false); tecDetails->set_show_average_depth(false); TEST(tecDetails->show_average_depth(), false); tecDetails->set_show_pictures_in_profile(false); @@ -454,7 +440,6 @@ void TestQPrefTechnicalDetails::test_signals() QSignalSpy spy4(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::calcndlttsChanged); QSignalSpy spy5(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::dcceilingChanged); QSignalSpy spy6(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::display_deco_modeChanged); - QSignalSpy spy7(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::display_unused_tanksChanged); QSignalSpy spy8(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::eadChanged); QSignalSpy spy9(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gfhighChanged); QSignalSpy spy10(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::gflowChanged); @@ -487,8 +472,6 @@ void TestQPrefTechnicalDetails::test_signals() prefs.dcceiling = true; qPrefTechnicalDetails::set_dcceiling(false); qPrefTechnicalDetails::set_display_deco_mode(VPMB); - prefs.display_unused_tanks = true; - qPrefTechnicalDetails::set_display_unused_tanks(false); prefs.ead = true; qPrefTechnicalDetails::set_ead(false); qPrefTechnicalDetails::set_gfhigh(-29); @@ -532,7 +515,6 @@ void TestQPrefTechnicalDetails::test_signals() QCOMPARE(spy4.count(), 1); QCOMPARE(spy5.count(), 1); QCOMPARE(spy6.count(), 1); - QCOMPARE(spy7.count(), 1); QCOMPARE(spy8.count(), 1); QCOMPARE(spy9.count(), 1); QCOMPARE(spy10.count(), 1); @@ -560,7 +542,6 @@ void TestQPrefTechnicalDetails::test_signals() QVERIFY(spy4.takeFirst().at(0).toBool() == false); QVERIFY(spy5.takeFirst().at(0).toBool() == false); QVERIFY(spy6.takeFirst().at(0).toInt() == VPMB); - QVERIFY(spy7.takeFirst().at(0).toBool() == false); QVERIFY(spy8.takeFirst().at(0).toBool() == false); QVERIFY(spy9.takeFirst().at(0).toInt() == -29); QVERIFY(spy10.takeFirst().at(0).toInt() == -24); |