and I think I need to clarify something, if we didn't had the prefs.h, I could have made a QObjectification of the settings there is much, much smaller than the one I did right now (around 1.6k LOC) because for each variable of the prefs struct ( and it's substructs ) I needed to do:
a Q_PROPERTY (type name READ name WRITE setName SIGNAL nameChanged) for that specific property a getter that is mostly an one liner, return prefs.something; a setter that creates a QSettings, updates it, and also updates the prefs variable and emits the changed signal a signal to be emitted if we didn't had the prefs struct (or if it was a C++ class instead of a C Struct) I only needed to do the Q_PROPERTY (type name MEMBER var_name) so - maybe it's something to consider in the far - far - far future? either way, Here is the usage of the 1.6k LOC monster for the toolbar buttons that trigger the replot of the profile: (it already helped to simplify the handling of it, yey) I'm not pretty sure that this is bug free, but I tested this together with master so there isn't any obvious bugs. Tomaz
From 42012d8fb142abb49f367609b0fb693fa25bdb8b Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 15:54:23 -0200 Subject: [PATCH 1/6] Start to use the QSettings ObjectWrapper start of the QSettinsg Object Wrapper usage on the code this first patch removes two macros that generated around 200 lines in runtime for something like a quarter of it Basically, whenever we changed anything we called the PreferencesDialog::settingsChanged and connected everythign to that signal, now each setting has it's own changed signal and we can call it directly. The best thing about this approach is that we don't trigger repaints for things that are not directly profile related. ( actually we still do, but the plan is to remove them in due time) this commit breaks correct atualization of the profile (because everything was connected to PreferencesDialog::settingsChanged) and now I need to hunt a bit for the correct connections Signed-off-by: Tomaz Canabrava <[email protected]> --- desktop-widgets/mainwindow.cpp | 138 +++++++++++---------- desktop-widgets/mainwindow.h | 17 --- profile-widget/profilewidget2.cpp | 7 ++ profile-widget/profilewidget2.h | 1 + .../subsurface-qt/SettingsObjectWrapper.cpp | 6 + .../subsurface-qt/SettingsObjectWrapper.h | 4 +- subsurface-desktop-main.cpp | 9 -- 7 files changed, 92 insertions(+), 90 deletions(-) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index c029687..ca36cb7 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -55,6 +55,7 @@ #include "subsurface-core/color.h" #include "subsurface-core/isocialnetworkintegration.h" #include "subsurface-core/pluginmanager.h" +#include <subsurface-qt/SettingsObjectWrapper.h> #if defined(FBSUPPORT) #include "plugins/facebook/facebook_integration.h" @@ -247,6 +248,75 @@ MainWindow::MainWindow() : QMainWindow(), setupSocialNetworkMenu(); set_git_update_cb(&updateProgress); + + // Toolbar Connections related to the Profile Update + SettingsObjectWrapper *sWrapper = SettingsObjectWrapper::instance(); sWrapper->techDetails; + connect(ui.profCalcAllTissues, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setCalcalltissues); + connect(ui.profCalcCeiling, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setCalcceiling); + connect(ui.profDcCeiling, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setDCceiling); + connect(ui.profEad, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setEad); + connect(ui.profIncrement3m, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setCalcceiling3m); + connect(ui.profMod, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setMod); + connect(ui.profNdl_tts, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setCalcndltts); + connect(ui.profHR, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setHRgraph); + connect(ui.profRuler, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setRulerGraph); + connect(ui.profSAC, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setShowSac); + connect(ui.profScaled, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setZoomedPlot); + connect(ui.profTogglePicture, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setShowPicturesInProfile); + connect(ui.profTankbar, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setTankBar); + connect(ui.profTissues, &QAction::triggered, sWrapper->techDetails, &TechnicalDetailsSettings::setPercentageGraph); + + connect(ui.profPhe, &QAction::triggered, sWrapper->pp_gas, &PartialPressureGasSettings::setShowPhe); + connect(ui.profPn2, &QAction::triggered, sWrapper->pp_gas, &PartialPressureGasSettings::setShowPn2); + connect(ui.profPO2, &QAction::triggered, sWrapper->pp_gas, &PartialPressureGasSettings::setShowPo2); + + connect(sWrapper->techDetails, &TechnicalDetailsSettings::calcalltissuesChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::calcceilingChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::dcceilingChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::eadChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::calcceiling3mChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::modChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::calcndlttsChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::hrgraphChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::rulerGraphChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::showSacChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::zoomedPlotChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::showPicturesInProfileChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::tankBarChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->techDetails, &TechnicalDetailsSettings::percentageGraphChanged , graphics(), &ProfileWidget2::actionRequestedReplot); + + connect(sWrapper->pp_gas, &PartialPressureGasSettings::showPheChanged, graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->pp_gas, &PartialPressureGasSettings::showPn2Changed, graphics(), &ProfileWidget2::actionRequestedReplot); + connect(sWrapper->pp_gas, &PartialPressureGasSettings::showPo2Changed, graphics(), &ProfileWidget2::actionRequestedReplot); + + // now let's set up some connections + connect(graphics(), &ProfileWidget2::enableToolbar ,this, &MainWindow::setEnabledToolbar); + connect(graphics(), &ProfileWidget2::showError, this, &MainWindow::showError); + connect(graphics(), &ProfileWidget2::disableShortcuts, this, &MainWindow::disableShortcuts); + connect(graphics(), &ProfileWidget2::enableShortcuts, this, &MainWindow::enableShortcuts); + connect(graphics(), &ProfileWidget2::refreshDisplay, this, &MainWindow::refreshDisplay); + connect(graphics(), &ProfileWidget2::editCurrentDive, this, &MainWindow::editCurrentDive); + connect(graphics(), &ProfileWidget2::updateDiveInfo, information(), &MainTab::updateDiveInfo); + + connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), graphics(), SLOT(settingsChanged())); + + ui.profCalcAllTissues->setChecked(sWrapper->techDetails->calcalltissues()); + ui.profCalcCeiling->setChecked(sWrapper->techDetails->calcceiling()); + ui.profDcCeiling->setChecked(sWrapper->techDetails->dcceiling()); + ui.profEad->setChecked(sWrapper->techDetails->ead()); + ui.profIncrement3m->setChecked(sWrapper->techDetails->calcceiling3m()); + ui.profMod->setChecked(sWrapper->techDetails->mod()); + ui.profNdl_tts->setChecked(sWrapper->techDetails->calcndltts()); + ui.profPhe->setChecked(sWrapper->pp_gas->showPhe()); + ui.profPn2->setChecked(sWrapper->pp_gas->showPn2()); + ui.profPO2->setChecked(sWrapper->pp_gas->showPo2()); + ui.profHR->setChecked(sWrapper->techDetails->hrgraph()); + ui.profRuler->setChecked(sWrapper->techDetails->rulerGraph()); + ui.profSAC->setChecked(sWrapper->techDetails->showSac()); + ui.profTogglePicture->setChecked(sWrapper->techDetails->showPicturesInProfile()); + ui.profTankbar->setChecked(sWrapper->techDetails->tankBar()); + ui.profTissues->setChecked(sWrapper->techDetails->percentageGraph()); + ui.profScaled->setChecked(sWrapper->techDetails->zoomedPlot()); } MainWindow::~MainWindow() @@ -1226,36 +1296,13 @@ const char *getSetting(const QSettings &s,const QString& name) return NULL; } -#define TOOLBOX_PREF_BUTTON(pref, setting, button) \ - prefs.pref = s.value(#setting).toBool(); \ - ui.button->setChecked(prefs.pref); - void MainWindow::readSettings() { static bool firstRun = true; - QSettings s; - // the static object for preferences already reads in the settings - // and sets up the font, so just get what we need for the toolbox and other widgets here - - s.beginGroup("TecDetails"); - TOOLBOX_PREF_BUTTON(calcalltissues, calcalltissues, profCalcAllTissues); - TOOLBOX_PREF_BUTTON(calcceiling, calcceiling, profCalcCeiling); - TOOLBOX_PREF_BUTTON(dcceiling, dcceiling, profDcCeiling); - TOOLBOX_PREF_BUTTON(ead, ead, profEad); - TOOLBOX_PREF_BUTTON(calcceiling3m, calcceiling3m, profIncrement3m); - TOOLBOX_PREF_BUTTON(mod, mod, profMod); - TOOLBOX_PREF_BUTTON(calcndltts, calcndltts, profNdl_tts); - TOOLBOX_PREF_BUTTON(pp_graphs.phe, phegraph, profPhe); - TOOLBOX_PREF_BUTTON(pp_graphs.pn2, pn2graph, profPn2); - TOOLBOX_PREF_BUTTON(pp_graphs.po2, po2graph, profPO2); - TOOLBOX_PREF_BUTTON(hrgraph, hrgraph, profHR); - TOOLBOX_PREF_BUTTON(rulergraph, rulergraph, profRuler); - TOOLBOX_PREF_BUTTON(show_sac, show_sac, profSAC); - TOOLBOX_PREF_BUTTON(show_pictures_in_profile, show_pictures_in_profile, profTogglePicture); - TOOLBOX_PREF_BUTTON(tankbar, tankbar, profTankbar); - TOOLBOX_PREF_BUTTON(percentagegraph, percentagegraph, profTissues); - TOOLBOX_PREF_BUTTON(zoomed_plot, zoomed_plot, profScaled); - s.endGroup(); // note: why doesn't the list of 17 buttons match the order in the gui? + + SettingsObjectWrapper *settings = SettingsObjectWrapper::instance(); + + QSettings s; //WARNING: Why those prefs are not on the prefs struct? s.beginGroup("DiveComputer"); default_dive_computer_vendor = getSetting(s, "dive_computer_vendor"); default_dive_computer_product = getSetting(s, "dive_computer_product"); @@ -1804,45 +1851,10 @@ void MainWindow::editCurrentDive() } } -// TODO: Remove the dependency to the PreferencesDialog here. -#define PREF_PROFILE(QT_PREFS) \ - QSettings s; \ - s.beginGroup("TecDetails"); \ - s.setValue(#QT_PREFS, triggered); \ - PreferencesDialog::instance()->emitSettingsChanged(); - -#define TOOLBOX_PREF_PROFILE(METHOD, INTERNAL_PREFS, QT_PREFS) \ - void MainWindow::on_##METHOD##_triggered(bool triggered) \ - { \ - prefs.INTERNAL_PREFS = triggered; \ - PREF_PROFILE(QT_PREFS); \ - } - -// note: why doesn't the list of 17 buttons match the order in the gui? or the order above? (line 1136) -TOOLBOX_PREF_PROFILE(profCalcAllTissues, calcalltissues, calcalltissues); -TOOLBOX_PREF_PROFILE(profCalcCeiling, calcceiling, calcceiling); -TOOLBOX_PREF_PROFILE(profDcCeiling, dcceiling, dcceiling); -TOOLBOX_PREF_PROFILE(profEad, ead, ead); -TOOLBOX_PREF_PROFILE(profIncrement3m, calcceiling3m, calcceiling3m); -TOOLBOX_PREF_PROFILE(profMod, mod, mod); -TOOLBOX_PREF_PROFILE(profNdl_tts, calcndltts, calcndltts); -TOOLBOX_PREF_PROFILE(profPhe, pp_graphs.phe, phegraph); -TOOLBOX_PREF_PROFILE(profPn2, pp_graphs.pn2, pn2graph); -TOOLBOX_PREF_PROFILE(profPO2, pp_graphs.po2, po2graph); -TOOLBOX_PREF_PROFILE(profHR, hrgraph, hrgraph); -TOOLBOX_PREF_PROFILE(profRuler, rulergraph, rulergraph); -TOOLBOX_PREF_PROFILE(profSAC, show_sac, show_sac); -TOOLBOX_PREF_PROFILE(profScaled, zoomed_plot, zoomed_plot); -TOOLBOX_PREF_PROFILE(profTogglePicture, show_pictures_in_profile, show_pictures_in_profile); -TOOLBOX_PREF_PROFILE(profTankbar, tankbar, tankbar); -TOOLBOX_PREF_PROFILE(profTissues, percentagegraph, percentagegraph); -// couldn't the args to TOOLBOX_PREF_PROFILE be made to go in the same sequence as TOOLBOX_PREF_BUTTON? - void MainWindow::turnOffNdlTts() { const bool triggered = false; - prefs.calcndltts = triggered; - PREF_PROFILE(calcndltts); + SettingsObjectWrapper::instance()->techDetails->setCalcndltts(false); } #undef TOOLBOX_PREF_PROFILE diff --git a/desktop-widgets/mainwindow.h b/desktop-widgets/mainwindow.h index e53c1ef..7e7f5db 100644 --- a/desktop-widgets/mainwindow.h +++ b/desktop-widgets/mainwindow.h @@ -147,23 +147,6 @@ slots: void on_actionImportDiveLog_triggered(); /* TODO: Move those slots below to it's own class */ - void on_profCalcAllTissues_triggered(bool triggered); - void on_profCalcCeiling_triggered(bool triggered); - void on_profDcCeiling_triggered(bool triggered); - void on_profEad_triggered(bool triggered); - void on_profIncrement3m_triggered(bool triggered); - void on_profMod_triggered(bool triggered); - void on_profNdl_tts_triggered(bool triggered); - void on_profPO2_triggered(bool triggered); - void on_profPhe_triggered(bool triggered); - void on_profPn2_triggered(bool triggered); - void on_profHR_triggered(bool triggered); - void on_profRuler_triggered(bool triggered); - void on_profSAC_triggered(bool triggered); - void on_profScaled_triggered(bool triggered); - void on_profTogglePicture_triggered(bool triggered); - void on_profTankbar_triggered(bool triggered); - void on_profTissues_triggered(bool triggered); void on_actionExport_triggered(); void on_copy_triggered(); void on_paste_triggered(); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index f895900..6291490 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -15,6 +15,7 @@ #include "models.h" #include "divepicturemodel.h" #include "divelist.h" +#include <subsurface-qt/SettingsObjectWrapper.h> #ifndef SUBSURFACE_MOBILE #include "diveplanner.h" #include "simplewidgets.h" @@ -732,6 +733,12 @@ void ProfileWidget2::dateTimeChanged() emit dateTimeChangedItems(); } +void ProfileWidget2::actionRequestedReplot(bool triggered) +{ + Q_UNUSED(triggered); + settingsChanged(); +} + void ProfileWidget2::settingsChanged() { // if we are showing calculated ceilings then we have to replot() diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 9255fe3..ad593a8 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -103,6 +103,7 @@ public slots: // Necessary to call from QAction's signals. void dateTimeChanged(); void settingsChanged(); + void actionRequestedReplot(bool triggered); void setEmptyState(); void setProfileState(); void setPlanState(); diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp index e797597..6c455e1 100644 --- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp @@ -1604,3 +1604,9 @@ short int SettingsObjectWrapper::saveUserIdLocal() const { return prefs.save_userid_local; } + +SettingsObjectWrapper* SettingsObjectWrapper::instance() +{ + static SettingsObjectWrapper settings; + return &settings; +} diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h index 6a8aa73..924ca95 100644 --- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h +++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h @@ -614,7 +614,7 @@ class SettingsObjectWrapper : public QObject { Q_PROPERTY(AnimationsSettingsObjectWrapper* animation MEMBER animation_settings CONSTANT) Q_PROPERTY(LocationServiceSettingsObjectWrapper* Location MEMBER location_settings CONSTANT) public: - SettingsObjectWrapper(QObject *parent = NULL); + static SettingsObjectWrapper *instance(); short saveUserIdLocal() const; TechnicalDetailsSettings *techDetails; @@ -633,6 +633,8 @@ public: public slots: void setSaveUserIdLocal(short value); +private: + SettingsObjectWrapper(QObject *parent = NULL); signals: void saveUserIdLocalChanged(short value); }; diff --git a/subsurface-desktop-main.cpp b/subsurface-desktop-main.cpp index 69fcb57..d084f2a 100644 --- a/subsurface-desktop-main.cpp +++ b/subsurface-desktop-main.cpp @@ -88,15 +88,6 @@ int main(int argc, char **argv) // in case something has gone wrong make sure we show the error message m->showError(); - // now let's set up some connections - QObject::connect(m->graphics(), &ProfileWidget2::enableToolbar ,m, &MainWindow::setEnabledToolbar, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::showError, m, &MainWindow::showError, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::disableShortcuts, m, &MainWindow::disableShortcuts, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::enableShortcuts, m, &MainWindow::enableShortcuts, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::refreshDisplay, m, &MainWindow::refreshDisplay, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::updateDiveInfo, m->information(), &MainTab::updateDiveInfo, Qt::AutoConnection); - QObject::connect(m->graphics(), &ProfileWidget2::editCurrentDive, m, &MainWindow::editCurrentDive, Qt::AutoConnection); - QObject::connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), m->graphics(), SLOT(settingsChanged())); if (verbose > 0) print_files(); if (!quit) -- 2.7.0
From dfa02a013ab4fd7c711664fbde1a39bee6ea2b62 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 16:49:51 -0200 Subject: [PATCH 2/6] Changed quite a few shorts to bool on the c++ implementtion The shorts where being used on the preferences since a long while and we cannot just simply change them to bool since this could break the preferences files, so work around that by changing them to booleans, since it's the correct type for a true / false answer. Also, move some plot curves to the new settings style Signed-off-by: Tomaz Canabrava <[email protected]> --- profile-widget/divecartesianaxis.cpp | 1 + profile-widget/diveprofileitem.cpp | 45 +++---- profile-widget/diveprofileitem.h | 7 +- .../subsurface-qt/SettingsObjectWrapper.cpp | 72 +++++------ .../subsurface-qt/SettingsObjectWrapper.h | 144 ++++++++++----------- 5 files changed, 130 insertions(+), 139 deletions(-) diff --git a/profile-widget/divecartesianaxis.cpp b/profile-widget/divecartesianaxis.cpp index 41d6bc3..2c3b7fe 100644 --- a/profile-widget/divecartesianaxis.cpp +++ b/profile-widget/divecartesianaxis.cpp @@ -1,6 +1,7 @@ #include "divecartesianaxis.h" #include "divetextitem.h" #include "helpers.h" +#include <subsurface-qt/SettingsObjectWrapper.h> #ifndef SUBSURFACE_MOBILE #include "preferences/preferencesdialog.h" #endif diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index b7729bd..f567801 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -10,6 +10,7 @@ #endif #include "diveplannermodel.h" #include "helpers.h" +#include <subsurface-qt/SettingsObjectWrapper.h> #include "libdivecomputer/parser.h" #include "profilewidget2.h" @@ -27,6 +28,11 @@ void AbstractProfilePolygonItem::settingsChanged() { } +void AbstractProfilePolygonItem::setVisible(bool visible) +{ + QGraphicsPolygonItem::setVisible(visible); +} + void AbstractProfilePolygonItem::setHorizontalAxis(DiveCartesianAxis *horizontal) { hAxis = horizontal; @@ -255,7 +261,7 @@ DiveHeartrateItem::DiveHeartrateItem() pen.setCosmetic(true); pen.setWidth(1); setPen(pen); - settingsChanged(); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::hrgraphChanged, this, &DiveHeartrateItem::setVisible); } void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) @@ -334,11 +340,6 @@ void DiveHeartrateItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->restore(); } -void DiveHeartrateItem::settingsChanged() -{ - setVisible(prefs.hrgraph); -} - DivePercentageItem::DivePercentageItem(int i) { QPen pen; @@ -383,11 +384,7 @@ void DivePercentageItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(pen()); painter->drawPolyline(polygon()); painter->restore(); -} - -void DivePercentageItem::settingsChanged() -{ - setVisible(prefs.percentagegraph); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::percentageGraphChanged, this, &DivePercentageItem::setVisible); } DiveAmbPressureItem::DiveAmbPressureItem() @@ -432,11 +429,7 @@ void DiveAmbPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte painter->setPen(pen()); painter->drawPolyline(polygon()); painter->restore(); -} - -void DiveAmbPressureItem::settingsChanged() -{ - setVisible(prefs.percentagegraph); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::percentageGraphChanged, this, &DiveAmbPressureItem::setVisible); } DiveGFLineItem::DiveGFLineItem() @@ -481,11 +474,7 @@ void DiveGFLineItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *op painter->setPen(pen()); painter->drawPolyline(polygon()); painter->restore(); -} - -void DiveGFLineItem::settingsChanged() -{ - setVisible(prefs.percentagegraph); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::percentageGraphChanged, this, &DiveAmbPressureItem::setVisible); } DiveTemperatureItem::DiveTemperatureItem() @@ -610,11 +599,7 @@ void DiveMeanDepthItem::paint(QPainter *painter, const QStyleOptionGraphicsItem painter->setPen(pen()); painter->drawPolyline(polygon()); painter->restore(); -} - -void DiveMeanDepthItem::settingsChanged() -{ - setVisible(prefs.show_average_depth); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::showAverageDepthChanged, this, &DiveAmbPressureItem::setVisible); } void DiveMeanDepthItem::createTextItem() { @@ -838,6 +823,14 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI DiveCalculatedTissue::DiveCalculatedTissue(ProfileWidget2 *widget) : DiveCalculatedCeiling(widget) { settingsChanged(); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::calcalltissuesChanged, this, &DiveCalculatedTissue::setVisible); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::calcceilingChanged, this, &DiveCalculatedTissue::setVisible); +} + +void DiveCalculatedTissue::setVisible(bool visible) +{ + Q_UNUSED(visible); + settingsChanged(); } void DiveCalculatedTissue::settingsChanged() diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index 8f9a56f..ce60b41 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -49,6 +49,7 @@ slots: virtual void settingsChanged(); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); virtual void modelDataRemoved(const QModelIndex &parent, int from, int to); + void setVisible(bool visible); protected: /* when the model emits a 'datachanged' signal, this method below should be used to check if the @@ -91,7 +92,6 @@ public: DiveMeanDepthItem(); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - virtual void settingsChanged(); private: void createTextItem(); @@ -116,7 +116,6 @@ public: DiveHeartrateItem(); virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void settingsChanged(); private: void createTextItem(int seconds, int hr); @@ -129,7 +128,6 @@ public: DivePercentageItem(int i); virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void settingsChanged(); private: QString visibilityKey; @@ -141,7 +139,6 @@ public: DiveAmbPressureItem(); virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void settingsChanged(); private: QString visibilityKey; @@ -153,7 +150,6 @@ public: DiveGFLineItem(); virtual void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget); - virtual void settingsChanged(); private: QString visibilityKey; @@ -205,6 +201,7 @@ class DiveCalculatedTissue : public DiveCalculatedCeiling { Q_OBJECT public: DiveCalculatedTissue(ProfileWidget2 *profileWidget); + void setVisible(bool visible); virtual void settingsChanged(); }; diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp index 6c455e1..02ec8a0 100644 --- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp @@ -110,67 +110,67 @@ double TechnicalDetailsSettings:: modp02() const return prefs.modpO2; } -short TechnicalDetailsSettings::ead() const +bool TechnicalDetailsSettings::ead() const { return prefs.ead; } -short TechnicalDetailsSettings::dcceiling() const +bool TechnicalDetailsSettings::dcceiling() const { return prefs.dcceiling; } -short TechnicalDetailsSettings::redceiling() const +bool TechnicalDetailsSettings::redceiling() const { return prefs.redceiling; } -short TechnicalDetailsSettings::calcceiling() const +bool TechnicalDetailsSettings::calcceiling() const { return prefs.calcceiling; } -short TechnicalDetailsSettings::calcceiling3m() const +bool TechnicalDetailsSettings::calcceiling3m() const { return prefs.calcceiling3m; } -short TechnicalDetailsSettings::calcalltissues() const +bool TechnicalDetailsSettings::calcalltissues() const { return prefs.calcalltissues; } -short TechnicalDetailsSettings::calcndltts() const +bool TechnicalDetailsSettings::calcndltts() const { return prefs.calcndltts; } -short TechnicalDetailsSettings::gflow() const +bool TechnicalDetailsSettings::gflow() const { return prefs.gflow; } -short TechnicalDetailsSettings::gfhigh() const +bool TechnicalDetailsSettings::gfhigh() const { return prefs.gfhigh; } -short TechnicalDetailsSettings::hrgraph() const +bool TechnicalDetailsSettings::hrgraph() const { return prefs.hrgraph; } -short TechnicalDetailsSettings::tankBar() const +bool TechnicalDetailsSettings::tankBar() const { return prefs.tankbar; } -short TechnicalDetailsSettings::percentageGraph() const +bool TechnicalDetailsSettings::percentageGraph() const { return prefs.percentagegraph; } -short TechnicalDetailsSettings::rulerGraph() const +bool TechnicalDetailsSettings::rulerGraph() const { return prefs.rulergraph; } @@ -185,12 +185,12 @@ bool TechnicalDetailsSettings::showCCRSensors() const return prefs.show_ccr_sensors; } -short TechnicalDetailsSettings::zoomedPlot() const +bool TechnicalDetailsSettings::zoomedPlot() const { return prefs.zoomed_plot; } -short TechnicalDetailsSettings::showSac() const +bool TechnicalDetailsSettings::showSac() const { return prefs.show_sac; } @@ -200,17 +200,17 @@ bool TechnicalDetailsSettings::gfLowAtMaxDepth() const return prefs.gf_low_at_maxdepth; } -short TechnicalDetailsSettings::displayUnusedTanks() const +bool TechnicalDetailsSettings::displayUnusedTanks() const { return prefs.display_unused_tanks; } -short TechnicalDetailsSettings::showAverageDepth() const +bool TechnicalDetailsSettings::showAverageDepth() const { return prefs.show_average_depth; } -short int TechnicalDetailsSettings::mod() const +bool TechnicalDetailsSettings::mod() const { return prefs.mod; } @@ -238,7 +238,7 @@ void TechnicalDetailsSettings::setShowPicturesInProfile(bool value) emit showPicturesInProfileChanged(value); } -void TechnicalDetailsSettings::setEad(short value) +void TechnicalDetailsSettings::setEad(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -247,7 +247,7 @@ void TechnicalDetailsSettings::setEad(short value) emit eadChanged(value); } -void TechnicalDetailsSettings::setMod(short value) +void TechnicalDetailsSettings::setMod(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -256,7 +256,7 @@ void TechnicalDetailsSettings::setMod(short value) emit modChanged(value); } -void TechnicalDetailsSettings::setDCceiling(short value) +void TechnicalDetailsSettings::setDCceiling(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -265,7 +265,7 @@ void TechnicalDetailsSettings::setDCceiling(short value) emit dcceilingChanged(value); } -void TechnicalDetailsSettings::setRedceiling(short value) +void TechnicalDetailsSettings::setRedceiling(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -274,7 +274,7 @@ void TechnicalDetailsSettings::setRedceiling(short value) emit redceilingChanged(value); } -void TechnicalDetailsSettings::setCalcceiling(short value) +void TechnicalDetailsSettings::setCalcceiling(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -283,7 +283,7 @@ void TechnicalDetailsSettings::setCalcceiling(short value) emit calcceilingChanged(value); } -void TechnicalDetailsSettings::setCalcceiling3m(short value) +void TechnicalDetailsSettings::setCalcceiling3m(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -292,7 +292,7 @@ void TechnicalDetailsSettings::setCalcceiling3m(short value) emit calcceiling3mChanged(value); } -void TechnicalDetailsSettings::setCalcalltissues(short value) +void TechnicalDetailsSettings::setCalcalltissues(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -301,7 +301,7 @@ void TechnicalDetailsSettings::setCalcalltissues(short value) emit calcalltissuesChanged(value); } -void TechnicalDetailsSettings::setCalcndltts(short value) +void TechnicalDetailsSettings::setCalcndltts(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -310,7 +310,7 @@ void TechnicalDetailsSettings::setCalcndltts(short value) emit calcndlttsChanged(value); } -void TechnicalDetailsSettings::setGflow(short value) +void TechnicalDetailsSettings::setGflow(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -320,7 +320,7 @@ void TechnicalDetailsSettings::setGflow(short value) emit gflowChanged(value); } -void TechnicalDetailsSettings::setGfhigh(short value) +void TechnicalDetailsSettings::setGfhigh(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -330,7 +330,7 @@ void TechnicalDetailsSettings::setGfhigh(short value) emit gfhighChanged(value); } -void TechnicalDetailsSettings::setHRgraph(short value) +void TechnicalDetailsSettings::setHRgraph(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -339,7 +339,7 @@ void TechnicalDetailsSettings::setHRgraph(short value) emit hrgraphChanged(value); } -void TechnicalDetailsSettings::setTankBar(short value) +void TechnicalDetailsSettings::setTankBar(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -348,7 +348,7 @@ void TechnicalDetailsSettings::setTankBar(short value) emit tankBarChanged(value); } -void TechnicalDetailsSettings::setPercentageGraph(short value) +void TechnicalDetailsSettings::setPercentageGraph(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -357,7 +357,7 @@ void TechnicalDetailsSettings::setPercentageGraph(short value) emit percentageGraphChanged(value); } -void TechnicalDetailsSettings::setRulerGraph(short value) +void TechnicalDetailsSettings::setRulerGraph(bool value) { /* TODO: search for the QSettings of the RulerBar */ QSettings s; @@ -385,7 +385,7 @@ void TechnicalDetailsSettings::setShowCCRSensors(bool value) emit showCCRSensorsChanged(value); } -void TechnicalDetailsSettings::setZoomedPlot(short value) +void TechnicalDetailsSettings::setZoomedPlot(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -394,7 +394,7 @@ void TechnicalDetailsSettings::setZoomedPlot(short value) emit zoomedPlotChanged(value); } -void TechnicalDetailsSettings::setShowSac(short value) +void TechnicalDetailsSettings::setShowSac(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -413,7 +413,7 @@ void TechnicalDetailsSettings::setGfLowAtMaxDepth(bool value) emit gfLowAtMaxDepthChanged(value); } -void TechnicalDetailsSettings::setDisplayUnusedTanks(short value) +void TechnicalDetailsSettings::setDisplayUnusedTanks(bool value) { QSettings s; s.beginGroup(tecDetails); @@ -422,7 +422,7 @@ void TechnicalDetailsSettings::setDisplayUnusedTanks(short value) emit displayUnusedTanksChanged(value); } -void TechnicalDetailsSettings::setShowAverageDepth(short value) +void TechnicalDetailsSettings::setShowAverageDepth(bool value) { QSettings s; s.beginGroup(tecDetails); diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h index 924ca95..f115e2d 100644 --- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.h +++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.h @@ -52,103 +52,103 @@ private: class TechnicalDetailsSettings : public QObject { Q_OBJECT Q_PROPERTY(double modpO2 READ modp02 WRITE setModp02 NOTIFY modpO2Changed) - Q_PROPERTY(short ead READ ead WRITE setEad NOTIFY eadChanged) - Q_PROPERTY(short mod READ mod WRITE setMod NOTIFY modChanged); - Q_PROPERTY(short dcceiling READ dcceiling WRITE setDCceiling NOTIFY dcceilingChanged) - Q_PROPERTY(short redceiling READ redceiling WRITE setRedceiling NOTIFY redceilingChanged) - Q_PROPERTY(short calcceiling READ calcceiling WRITE setCalcceiling NOTIFY calcceilingChanged) - Q_PROPERTY(short calcceiling3m READ calcceiling3m WRITE setCalcceiling3m NOTIFY calcceiling3mChanged) - Q_PROPERTY(short calcalltissues READ calcalltissues WRITE setCalcalltissues NOTIFY calcalltissuesChanged) - Q_PROPERTY(short calcndltts READ calcndltts WRITE setCalcndltts NOTIFY calcndlttsChanged) - Q_PROPERTY(short gflow READ gflow WRITE setGflow NOTIFY gflowChanged) - Q_PROPERTY(short gfhigh READ gfhigh WRITE setGfhigh NOTIFY gfhighChanged) - Q_PROPERTY(short hrgraph READ hrgraph WRITE setHRgraph NOTIFY hrgraphChanged) - Q_PROPERTY(short tankbar READ tankBar WRITE setTankBar NOTIFY tankBarChanged) - Q_PROPERTY(short percentagegraph READ percentageGraph WRITE setPercentageGraph NOTIFY percentageGraphChanged) - Q_PROPERTY(short rulergraph READ rulerGraph WRITE setRulerGraph NOTIFY rulerGraphChanged) + Q_PROPERTY(bool ead READ ead WRITE setEad NOTIFY eadChanged) + Q_PROPERTY(bool mod READ mod WRITE setMod NOTIFY modChanged); + Q_PROPERTY(bool dcceiling READ dcceiling WRITE setDCceiling NOTIFY dcceilingChanged) + Q_PROPERTY(bool redceiling READ redceiling WRITE setRedceiling NOTIFY redceilingChanged) + Q_PROPERTY(bool calcceiling READ calcceiling WRITE setCalcceiling NOTIFY calcceilingChanged) + Q_PROPERTY(bool calcceiling3m READ calcceiling3m WRITE setCalcceiling3m NOTIFY calcceiling3mChanged) + Q_PROPERTY(bool calcalltissues READ calcalltissues WRITE setCalcalltissues NOTIFY calcalltissuesChanged) + Q_PROPERTY(bool calcndltts READ calcndltts WRITE setCalcndltts NOTIFY calcndlttsChanged) + Q_PROPERTY(bool gflow READ gflow WRITE setGflow NOTIFY gflowChanged) + Q_PROPERTY(bool gfhigh READ gfhigh WRITE setGfhigh NOTIFY gfhighChanged) + Q_PROPERTY(bool hrgraph READ hrgraph WRITE setHRgraph NOTIFY hrgraphChanged) + Q_PROPERTY(bool tankbar READ tankBar WRITE setTankBar NOTIFY tankBarChanged) + Q_PROPERTY(bool percentagegraph READ percentageGraph WRITE setPercentageGraph NOTIFY percentageGraphChanged) + Q_PROPERTY(bool rulergraph READ rulerGraph WRITE setRulerGraph NOTIFY rulerGraphChanged) Q_PROPERTY(bool show_ccr_setpoint READ showCCRSetpoint WRITE setShowCCRSetpoint NOTIFY showCCRSetpointChanged) Q_PROPERTY(bool show_ccr_sensors READ showCCRSensors WRITE setShowCCRSensors NOTIFY showCCRSensorsChanged) - Q_PROPERTY(short zoomed_plot READ zoomedPlot WRITE setZoomedPlot NOTIFY zoomedPlotChanged) - Q_PROPERTY(short show_sac READ showSac WRITE setShowSac NOTIFY showSacChanged) + Q_PROPERTY(bool zoomed_plot READ zoomedPlot WRITE setZoomedPlot NOTIFY zoomedPlotChanged) + Q_PROPERTY(bool show_sac READ showSac WRITE setShowSac NOTIFY showSacChanged) Q_PROPERTY(bool gf_low_at_maxdepth READ gfLowAtMaxDepth WRITE setGfLowAtMaxDepth NOTIFY gfLowAtMaxDepthChanged) - Q_PROPERTY(short display_unused_tanks READ displayUnusedTanks WRITE setDisplayUnusedTanks NOTIFY displayUnusedTanksChanged) - Q_PROPERTY(short show_average_depth READ showAverageDepth WRITE setShowAverageDepth NOTIFY showAverageDepthChanged) + Q_PROPERTY(bool display_unused_tanks READ displayUnusedTanks WRITE setDisplayUnusedTanks NOTIFY displayUnusedTanksChanged) + Q_PROPERTY(bool show_average_depth READ showAverageDepth WRITE setShowAverageDepth NOTIFY showAverageDepthChanged) Q_PROPERTY(bool show_pictures_in_profile READ showPicturesInProfile WRITE setShowPicturesInProfile NOTIFY showPicturesInProfileChanged) public: TechnicalDetailsSettings(QObject *parent); double modp02() const; - short ead() const; - short mod() const; - short dcceiling() const; - short redceiling() const; - short calcceiling() const; - short calcceiling3m() const; - short calcalltissues() const; - short calcndltts() const; - short gflow() const; - short gfhigh() const; - short hrgraph() const; - short tankBar() const; - short percentageGraph() const; - short rulerGraph() const; + bool ead() const; + bool mod() const; + bool dcceiling() const; + bool redceiling() const; + bool calcceiling() const; + bool calcceiling3m() const; + bool calcalltissues() const; + bool calcndltts() const; + bool gflow() const; + bool gfhigh() const; + bool hrgraph() const; + bool tankBar() const; + bool percentageGraph() const; + bool rulerGraph() const; bool showCCRSetpoint() const; bool showCCRSensors() const; - short zoomedPlot() const; - short showSac() const; + bool zoomedPlot() const; + bool showSac() const; bool gfLowAtMaxDepth() const; - short displayUnusedTanks() const; - short showAverageDepth() const; + bool displayUnusedTanks() const; + bool showAverageDepth() const; bool showPicturesInProfile() const; public slots: - void setMod(short value); + void setMod(bool value); void setModp02(double value); - void setEad(short value); - void setDCceiling(short value); - void setRedceiling(short value); - void setCalcceiling(short value); - void setCalcceiling3m(short value); - void setCalcalltissues(short value); - void setCalcndltts(short value); - void setGflow(short value); - void setGfhigh(short value); - void setHRgraph(short value); - void setTankBar(short value); - void setPercentageGraph(short value); - void setRulerGraph(short value); + void setEad(bool value); + void setDCceiling(bool value); + void setRedceiling(bool value); + void setCalcceiling(bool value); + void setCalcceiling3m(bool value); + void setCalcalltissues(bool value); + void setCalcndltts(bool value); + void setGflow(bool value); + void setGfhigh(bool value); + void setHRgraph(bool value); + void setTankBar(bool value); + void setPercentageGraph(bool value); + void setRulerGraph(bool value); void setShowCCRSetpoint(bool value); void setShowCCRSensors(bool value); - void setZoomedPlot(short value); - void setShowSac(short value); + void setZoomedPlot(bool value); + void setShowSac(bool value); void setGfLowAtMaxDepth(bool value); - void setDisplayUnusedTanks(short value); - void setShowAverageDepth(short value); + void setDisplayUnusedTanks(bool value); + void setShowAverageDepth(bool value); void setShowPicturesInProfile(bool value); signals: void modpO2Changed(double value); - void eadChanged(short value); - void modChanged(short value); - void dcceilingChanged(short value); - void redceilingChanged(short value); - void calcceilingChanged(short value); - void calcceiling3mChanged(short value); - void calcalltissuesChanged(short value); - void calcndlttsChanged(short value); - void gflowChanged(short value); - void gfhighChanged(short value); - void hrgraphChanged(short value); - void tankBarChanged(short value); - void percentageGraphChanged(short value); - void rulerGraphChanged(short value); + void eadChanged(bool value); + void modChanged(bool value); + void dcceilingChanged(bool value); + void redceilingChanged(bool value); + void calcceilingChanged(bool value); + void calcceiling3mChanged(bool value); + void calcalltissuesChanged(bool value); + void calcndlttsChanged(bool value); + void gflowChanged(bool value); + void gfhighChanged(bool value); + void hrgraphChanged(bool value); + void tankBarChanged(bool value); + void percentageGraphChanged(bool value); + void rulerGraphChanged(bool value); void showCCRSetpointChanged(bool value); void showCCRSensorsChanged(bool value); - void zoomedPlotChanged(short value); - void showSacChanged(short value); + void zoomedPlotChanged(bool value); + void showSacChanged(bool value); void gfLowAtMaxDepthChanged(bool value); - void displayUnusedTanksChanged(short value); - void showAverageDepthChanged(short value); + void displayUnusedTanksChanged(bool value); + void showAverageDepthChanged(bool value); void showPicturesInProfileChanged(bool value); }; -- 2.7.0
From 901cb45a86bfd12db1bafa898ff4c173980c75e4 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 17:20:18 -0200 Subject: [PATCH 3/6] More Profile Itens on the new Settings Signed-off-by: Tomaz Canabrava <[email protected]> --- profile-widget/diveprofileitem.cpp | 22 +++------------------- profile-widget/diveprofileitem.h | 2 -- profile-widget/profilewidget2.cpp | 29 ++++++++++++++++++++--------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index f567801..e46adca 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -784,6 +784,8 @@ DiveCalculatedCeiling::DiveCalculatedCeiling(ProfileWidget2 *widget) : profileWidget(widget), is3mIncrement(false) { + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::dcceilingChanged, this, &DiveCalculatedCeiling::setVisible); + setVisible(prefs.calcceiling); settingsChanged(); } @@ -835,7 +837,7 @@ void DiveCalculatedTissue::setVisible(bool visible) void DiveCalculatedTissue::settingsChanged() { - setVisible(prefs.calcalltissues && prefs.calcceiling); + DiveCalculatedCeiling::setVisible(prefs.calcalltissues && prefs.calcceiling); } void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) @@ -879,12 +881,6 @@ void DiveCalculatedCeiling::settingsChanged() recalc(); } is3mIncrement = prefs.calcceiling3m; - setVisible(prefs.calcceiling); -} - -void DiveReportedCeiling::settingsChanged() -{ - setVisible(prefs.dcceiling); } void DiveReportedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) @@ -956,18 +952,6 @@ PartialPressureGasItem::PartialPressureGasItem() : { } -void PartialPressureGasItem::settingsChanged() -{ - QSettings s; - s.beginGroup("TecDetails"); - setVisible(s.value(visibilityKey).toBool()); -} - -void PartialPressureGasItem::setVisibilitySettingsKey(const QString &key) -{ - visibilityKey = key; -} - void PartialPressureGasItem::setColors(const QColor &normal, const QColor &alert) { normalColor = normal; diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index ce60b41..0a009d0 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -194,7 +194,6 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem { public: virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); - virtual void settingsChanged(); }; class DiveCalculatedTissue : public DiveCalculatedCeiling { @@ -211,7 +210,6 @@ public: PartialPressureGasItem(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); - virtual void settingsChanged(); void setThreshouldSettingsKey(double *prefPointer); void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey); void setColors(const QColor &normalColor, const QColor &alertColor); diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 6291490..e37b403 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -325,21 +325,32 @@ void ProfileWidget2::setupItemOnScene() setupItem(meanDepthItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::INSTANT_MEANDEPTH, DivePlotDataModel::TIME, 1); -#define CREATE_PP_GAS(ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS, VISIBILITY_SETTINGS) \ +#define CREATE_PP_GAS(ITEM, VERTICAL_COLUMN, COLOR, COLOR_ALERT, THRESHOULD_SETTINGS) \ setupItem(ITEM, timeAxis, gasYAxis, dataModel, DivePlotDataModel::VERTICAL_COLUMN, DivePlotDataModel::TIME, 0); \ ITEM->setThreshouldSettingsKey(THRESHOULD_SETTINGS); \ - ITEM->setVisibilitySettingsKey(VISIBILITY_SETTINGS); \ ITEM->setColors(getColor(COLOR, isGrayscale), getColor(COLOR_ALERT, isGrayscale)); \ ITEM->settingsChanged(); \ ITEM->setZValue(99); - CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, &prefs.pp_graphs.pn2_threshold, "pn2graph"); - CREATE_PP_GAS(pheGasItem, PHE, PHE, PHE_ALERT, &prefs.pp_graphs.phe_threshold, "phegraph"); - CREATE_PP_GAS(po2GasItem, PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "po2graph"); - CREATE_PP_GAS(o2SetpointGasItem, O2SETPOINT, PO2_ALERT, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "po2graph"); - CREATE_PP_GAS(ccrsensor1GasItem, CCRSENSOR1, CCRSENSOR1, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "ccrsensorgraph"); - CREATE_PP_GAS(ccrsensor2GasItem, CCRSENSOR2, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "ccrsensorgraph"); - CREATE_PP_GAS(ccrsensor3GasItem, CCRSENSOR3, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold, "ccrsensorgraph"); + CREATE_PP_GAS(pn2GasItem, PN2, PN2, PN2_ALERT, &prefs.pp_graphs.pn2_threshold); + CREATE_PP_GAS(pheGasItem, PHE, PHE, PHE_ALERT, &prefs.pp_graphs.phe_threshold); + CREATE_PP_GAS(po2GasItem, PO2, PO2, PO2_ALERT, &prefs.pp_graphs.po2_threshold); + CREATE_PP_GAS(o2SetpointGasItem, O2SETPOINT, PO2_ALERT, PO2_ALERT, &prefs.pp_graphs.po2_threshold); + CREATE_PP_GAS(ccrsensor1GasItem, CCRSENSOR1, CCRSENSOR1, PO2_ALERT, &prefs.pp_graphs.po2_threshold); + CREATE_PP_GAS(ccrsensor2GasItem, CCRSENSOR2, CCRSENSOR2, PO2_ALERT, &prefs.pp_graphs.po2_threshold); + CREATE_PP_GAS(ccrsensor3GasItem, CCRSENSOR3, CCRSENSOR3, PO2_ALERT, &prefs.pp_graphs.po2_threshold); + + // Visibility Connections + connect(SettingsObjectWrapper::instance()->pp_gas, &PartialPressureGasSettings::showPheChanged, pheGasItem, &PartialPressureGasItem::setVisible); + connect(SettingsObjectWrapper::instance()->pp_gas, &PartialPressureGasSettings::showPo2Changed, po2GasItem, &PartialPressureGasItem::setVisible); + connect(SettingsObjectWrapper::instance()->pp_gas, &PartialPressureGasSettings::showPn2Changed, pn2GasItem, &PartialPressureGasItem::setVisible); + connect(SettingsObjectWrapper::instance()->pp_gas, &PartialPressureGasSettings::showPo2Changed, o2SetpointGasItem, &PartialPressureGasItem::setVisible); + + //WARNING: The old code was broken, I'm not sure what should trigger the visibility of those graphs, since the old code didn't triggered them + // because it was using a wrong settings. + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::showCCRSensorsChanged, ccrsensor1GasItem, &PartialPressureGasItem::setVisible); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::showCCRSensorsChanged, ccrsensor2GasItem, &PartialPressureGasItem::setVisible); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::showCCRSensorsChanged, ccrsensor3GasItem, &PartialPressureGasItem::setVisible); #undef CREATE_PP_GAS temperatureAxis->setTextVisible(false); -- 2.7.0
From 126475f10cba7094b3cca884b0926ea5e64e8668 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 17:33:52 -0200 Subject: [PATCH 4/6] Fix Display / Hide Calculated Ceiling Signed-off-by: Tomaz Canabrava <[email protected]> --- profile-widget/diveprofileitem.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index e46adca..986ecae 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -784,7 +784,7 @@ DiveCalculatedCeiling::DiveCalculatedCeiling(ProfileWidget2 *widget) : profileWidget(widget), is3mIncrement(false) { - connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::dcceilingChanged, this, &DiveCalculatedCeiling::setVisible); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::calcceilingChanged, this, &DiveCalculatedCeiling::setVisible); setVisible(prefs.calcceiling); settingsChanged(); } -- 2.7.0
From f7fd375abf8938396b7ae7fc18d9f75179ec13c6 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 17:48:57 -0200 Subject: [PATCH 5/6] Fix Ceiling Graph Signed-off-by: Tomaz Canabrava <[email protected]> --- profile-widget/diveprofileitem.cpp | 8 ++++++++ profile-widget/diveprofileitem.h | 1 + 2 files changed, 9 insertions(+) diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 986ecae..b090d21 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -116,6 +116,14 @@ void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex &topLeft, co DiveProfileItem::DiveProfileItem() : show_reported_ceiling(0), reported_ceiling_in_red(0) { + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::dcceilingChanged, this, &DiveProfileItem::settingsToggled); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::redceilingChanged, this, &DiveProfileItem::settingsToggled); +} + +void DiveProfileItem::settingsToggled(bool toggled) +{ + Q_UNUSED(toggled); + settingsChanged(); } void DiveProfileItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index 0a009d0..0c3f9a6 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -76,6 +76,7 @@ public: DiveProfileItem(); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); + void settingsToggled(bool toggled); virtual void settingsChanged(); void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color); int maxCeiling(int row); -- 2.7.0
From 872a954b5060a2ac78355758cd784014f2f4c8e7 Mon Sep 17 00:00:00 2001 From: Tomaz Canabrava <[email protected]> Date: Mon, 25 Jan 2016 18:15:06 -0200 Subject: [PATCH 6/6] Fix bug on the visibility of the Ruler Graph Signed-off-by: Tomaz Canabrava <[email protected]> --- profile-widget/ruleritem.cpp | 10 ++++------ profile-widget/ruleritem.h | 2 +- subsurface-core/qthelper.cpp | 1 + subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp | 2 +- 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/profile-widget/ruleritem.cpp b/profile-widget/ruleritem.cpp index 1b9c0e9..ce217b9 100644 --- a/profile-widget/ruleritem.cpp +++ b/profile-widget/ruleritem.cpp @@ -4,6 +4,7 @@ #endif #include "profilewidget2.h" #include "display.h" +#include "subsurface-core/subsurface-qt/SettingsObjectWrapper.h" #include <qgraphicssceneevent.h> @@ -81,20 +82,17 @@ RulerItem2::RulerItem2() : source(new RulerNodeItem2()), textItemBack->setFlag(QGraphicsItem::ItemIgnoresTransformations); setPen(QPen(QColor(Qt::black), 0.0)); #ifndef SUBSURFACE_MOBILE - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged())); + connect(SettingsObjectWrapper::instance()->techDetails, &TechnicalDetailsSettings::rulerGraphChanged, this, &RulerItem2::settingsChanged); #endif } -void RulerItem2::settingsChanged() +void RulerItem2::settingsChanged(bool value) { ProfileWidget2 *profWidget = NULL; if (scene() && scene()->views().count()) profWidget = qobject_cast<ProfileWidget2 *>(scene()->views().first()); - if (profWidget && profWidget->currentState == ProfileWidget2::PROFILE) - setVisible(prefs.rulergraph); - else - setVisible(false); + setVisible( (profWidget && profWidget->currentState == ProfileWidget2::PROFILE) ? value : false); } void RulerItem2::recalculate() diff --git a/profile-widget/ruleritem.h b/profile-widget/ruleritem.h index 4fad045..343a248 100644 --- a/profile-widget/ruleritem.h +++ b/profile-widget/ruleritem.h @@ -44,7 +44,7 @@ public: public slots: - void settingsChanged(); + void settingsChanged(bool toggled); private: struct plot_info pInfo; diff --git a/subsurface-core/qthelper.cpp b/subsurface-core/qthelper.cpp index b8e1688..e5cb2ce 100644 --- a/subsurface-core/qthelper.cpp +++ b/subsurface-core/qthelper.cpp @@ -1310,6 +1310,7 @@ void loadPreferences() GET_BOOL("calcalltissues", calcalltissues); GET_BOOL("hrgraph", hrgraph); GET_BOOL("tankbar", tankbar); + GET_BOOL("RulerBar", rulergraph); GET_BOOL("percentagegraph", percentagegraph); GET_INT("gflow", gflow); GET_INT("gfhigh", gfhigh); diff --git a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp index 02ec8a0..22d9a09 100644 --- a/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp +++ b/subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp @@ -363,7 +363,7 @@ void TechnicalDetailsSettings::setRulerGraph(bool value) QSettings s; s.beginGroup(tecDetails); s.setValue("RulerBar", value); - prefs.pp_graphs.phe_threshold = value; + prefs.rulergraph = value; emit rulerGraphChanged(value); } -- 2.7.0
_______________________________________________ subsurface mailing list [email protected] http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
