summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Tomaz Canabrava <tomaz.canabrava@intel.com>2016-01-25 15:54:23 -0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2016-01-25 13:04:01 -0800
commit2c5fad73e8939409639548571dcb942e6b2cb792 (patch)
treeacd1f2cd4adaeb6f1c642cf6c1d57baecafbea09
parent5afda93b71880395a78c121b76c234e1953edf1b (diff)
downloadsubsurface-2c5fad73e8939409639548571dcb942e6b2cb792.tar.gz
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 <tomaz.canabrava@intel.com> Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
-rw-r--r--desktop-widgets/mainwindow.cpp138
-rw-r--r--desktop-widgets/mainwindow.h17
-rw-r--r--profile-widget/profilewidget2.cpp7
-rw-r--r--profile-widget/profilewidget2.h1
-rw-r--r--subsurface-core/subsurface-qt/SettingsObjectWrapper.cpp6
-rw-r--r--subsurface-core/subsurface-qt/SettingsObjectWrapper.h4
-rw-r--r--subsurface-desktop-main.cpp9
7 files changed, 92 insertions, 90 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp
index c029687fa..ca36cb75c 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 e53c1efc9..7e7f5db1e 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 f89590033..629149030 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 9255fe3aa..ad593a8d7 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 e7975971d..6c455e1c1 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 6a8aa73b8..924ca95d6 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 69fcb572b..d084f2a5f 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)