diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-11-24 12:50:52 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-12-12 15:52:40 -0800 |
commit | 2d7be7a0e366b562fdff914e92219ab1852cd3c8 (patch) | |
tree | 7f4501cfe26b31f3a98f3b66cfaf925107a588d9 /desktop-widgets | |
parent | 8bbd778c28f52277dbee4a8d7bcb577c61a611f6 (diff) | |
download | subsurface-2d7be7a0e366b562fdff914e92219ab1852cd3c8.tar.gz |
preferences: create global settingsChanged signal
So far, the PreferencesDialog emitted a settingsChanged signal.
This meant that models that listened to that signal had to
conditionally compile out the code for mobile or the connection
had to be made in MainWindow.
Instead, introduce a global signal that does this and move
the connects to the listeners to remove inter-dependencies.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 8 | ||||
-rw-r--r-- | desktop-widgets/divelistview.h | 1 | ||||
-rw-r--r-- | desktop-widgets/diveplanner.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/filterconstraintwidget.cpp | 4 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 10 | ||||
-rw-r--r-- | desktop-widgets/preferences/preferencesdialog.cpp | 9 | ||||
-rw-r--r-- | desktop-widgets/preferences/preferencesdialog.h | 2 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 4 |
8 files changed, 24 insertions, 18 deletions
diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index f98b298f4..07f7435c0 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -9,6 +9,7 @@ #include "desktop-widgets/modeldelegates.h" #include "desktop-widgets/mainwindow.h" #include "core/selection.h" +#include "core/subsurface-qt/divelistnotifier.h" #include <unistd.h> #include <QSettings> #include <QKeyEvent> @@ -39,6 +40,7 @@ DiveListView::DiveListView(QWidget *parent) : QTreeView(parent), setModel(m); connect(m, &MultiFilterSortModel::selectionChanged, this, &DiveListView::diveSelectionChanged); connect(m, &MultiFilterSortModel::currentDiveChanged, this, &DiveListView::currentDiveChanged); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DiveListView::settingsChanged); setSortingEnabled(true); setContextMenuPolicy(Qt::DefaultContextMenu); @@ -348,6 +350,12 @@ void DiveListView::reload() } } +void DiveListView::settingsChanged() +{ + update(); + reloadHeaderActions(); +} + void DiveListView::reloadHeaderActions() { // Populate the context menu of the headers that will show diff --git a/desktop-widgets/divelistview.h b/desktop-widgets/divelistview.h index 17cff4b02..990d0446b 100644 --- a/desktop-widgets/divelistview.h +++ b/desktop-widgets/divelistview.h @@ -33,6 +33,7 @@ signals: void divesSelected(); public slots: + void settingsChanged(); void reloadHeaderActions(); private slots: diff --git a/desktop-widgets/diveplanner.cpp b/desktop-widgets/diveplanner.cpp index 3e63e5ffe..95375643f 100644 --- a/desktop-widgets/diveplanner.cpp +++ b/desktop-widgets/diveplanner.cpp @@ -6,6 +6,7 @@ #include "core/qthelper.h" #include "core/units.h" #include "core/settings/qPrefDivePlanner.h" +#include "core/subsurface-qt/divelistnotifier.h" #include "core/gettextfromc.h" #include "backend-shared/plannershared.h" @@ -175,6 +176,8 @@ DivePlannerWidget::DivePlannerWidget(QWidget *parent) : QWidget(parent, QFlag(0) ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::DURATION, new SpinBoxDelegate(0, 6000, 1, this)); ui.tableWidget->view()->setItemDelegateForColumn(DivePlannerPointsModel::CCSETPOINT, new DoubleSpinBoxDelegate(0, 2, 0.1, this)); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DivePlannerWidget::settingsChanged); + /* set defaults. */ ui.ATMPressure->setValue(1013); ui.atmHeight->setValue(0); @@ -506,6 +509,7 @@ PlannerSettingsWidget::PlannerSettingsWidget(QWidget *parent) : QWidget(parent, connect(ui.bestmixEND, QOverload<int>::of(&QSpinBox::valueChanged), &PlannerShared::set_bestmixend); connect(ui.bottomSAC, QOverload<double>::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_bottomsac); connect(ui.decoStopSAC, QOverload<double>::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_decosac); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &PlannerSettingsWidget::settingsChanged); settingsChanged(); ui.gflow->setValue(prefs.gflow); diff --git a/desktop-widgets/filterconstraintwidget.cpp b/desktop-widgets/filterconstraintwidget.cpp index 418fca0d5..6e5c2d032 100644 --- a/desktop-widgets/filterconstraintwidget.cpp +++ b/desktop-widgets/filterconstraintwidget.cpp @@ -2,7 +2,7 @@ #include "filterconstraintwidget.h" #include "starwidget.h" #include "core/pref.h" -#include "desktop-widgets/preferences/preferencesdialog.h" +#include "core/subsurface-qt/divelistnotifier.h" #include "qt-models/cleanertablemodel.h" // for trashIcon() #include "qt-models/filterconstraintmodel.h" @@ -225,7 +225,7 @@ FilterConstraintWidget::FilterConstraintWidget(FilterConstraintModel *modelIn, c rangeLayout->addStretch(); // Update the widget if the settings changed to reflect new units. - connect(PreferencesDialog::instance(), &PreferencesDialog::settingsChanged, this, &FilterConstraintWidget::update); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &FilterConstraintWidget::update); addToLayout(); update(); diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index b9ee3a15a..dfe039c51 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -189,13 +189,7 @@ MainWindow::MainWindow() : QMainWindow(), QIcon::setThemeName("subsurface"); } connect(diveList, &DiveListView::divesSelected, this, &MainWindow::selectionChanged); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(readSettings())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(update())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), diveList, SLOT(reloadHeaderActions())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), mainTab.get(), SLOT(updateDiveInfo())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerWidget, SLOT(settingsChanged())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), divePlannerSettingsWidget, SLOT(settingsChanged())); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), TankInfoModel::instance(), SLOT(update())); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainWindow::readSettings); for (int i = 0; i < NUM_RECENT_FILES; i++) { actionsRecent[i] = new QAction(this); actionsRecent[i]->setData(i); @@ -324,7 +318,7 @@ MainWindow::MainWindow() : QMainWindow(), connect(graphics, &ProfileWidget2::editCurrentDive, this, &MainWindow::editCurrentDive); connect(graphics, &ProfileWidget2::updateDiveInfo, mainTab.get(), &MainTab::updateDiveInfo); - connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), graphics, SLOT(settingsChanged())); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, graphics, &ProfileWidget2::settingsChanged); ui.profCalcAllTissues->setChecked(qPrefTechnicalDetails::calcalltissues()); ui.profCalcCeiling->setChecked(qPrefTechnicalDetails::calcceiling()); diff --git a/desktop-widgets/preferences/preferencesdialog.cpp b/desktop-widgets/preferences/preferencesdialog.cpp index e1c737f99..ca5e606cd 100644 --- a/desktop-widgets/preferences/preferencesdialog.cpp +++ b/desktop-widgets/preferences/preferencesdialog.cpp @@ -16,6 +16,7 @@ #include "preferences_reset.h" #include "core/qthelper.h" +#include "core/subsurface-qt/divelistnotifier.h" #include <QVBoxLayout> #include <QHBoxLayout> @@ -25,7 +26,7 @@ #include <QAbstractButton> #include <QDebug> -PreferencesDialog* PreferencesDialog::instance() +PreferencesDialog *PreferencesDialog::instance() { static PreferencesDialog *self = new PreferencesDialog(); return self; @@ -130,10 +131,10 @@ void PreferencesDialog::refreshPages() void PreferencesDialog::applyRequested(bool closeIt) { Q_FOREACH(AbstractPreferencesWidget *page, pages) { - connect(page, &AbstractPreferencesWidget::settingsChanged, this, &PreferencesDialog::settingsChanged, Qt::UniqueConnection); + connect(page, &AbstractPreferencesWidget::settingsChanged, &diveListNotifier, &DiveListNotifier::settingsChanged, Qt::UniqueConnection); page->syncSettings(); } - emit settingsChanged(); + emit diveListNotifier.settingsChanged(); if (closeIt) accept(); } @@ -152,6 +153,6 @@ void PreferencesDialog::defaultsRequested() Q_FOREACH(AbstractPreferencesWidget *page, pages) { page->refreshSettings(); } - emit settingsChanged(); + emit diveListNotifier.settingsChanged(); accept(); } diff --git a/desktop-widgets/preferences/preferencesdialog.h b/desktop-widgets/preferences/preferencesdialog.h index 67433f0fd..8abf812e9 100644 --- a/desktop-widgets/preferences/preferencesdialog.h +++ b/desktop-widgets/preferences/preferencesdialog.h @@ -19,8 +19,6 @@ public: void addPreferencePage(AbstractPreferencesWidget *page); void refreshPages(); void defaultsRequested(); -signals: - void settingsChanged(); private: PreferencesDialog(); void cancelRequested(); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 386fa454e..8b1973721 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -8,7 +8,6 @@ #include "desktop-widgets/tab-widgets/maintab.h" #include "desktop-widgets/mainwindow.h" #include "desktop-widgets/mapwidget.h" -#include "desktop-widgets/preferences/preferencesdialog.h" #include "core/qthelper.h" #include "core/trip.h" #include "qt-models/diveplannermodel.h" @@ -91,6 +90,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), connect(&diveListNotifier, &DiveListNotifier::tripChanged, this, &MainTab::tripChanged); connect(&diveListNotifier, &DiveListNotifier::diveSiteChanged, this, &MainTab::diveSiteEdited); connect(&diveListNotifier, &DiveListNotifier::commandExecuted, this, &MainTab::closeWarning); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo); connect(ui.editDiveSiteButton, &QToolButton::clicked, MainWindow::instance(), &MainWindow::startDiveSiteEdit); connect(ui.location, &DiveLocationLineEdit::entered, MapWidget::instance(), &MapWidget::centerOnIndex); @@ -100,7 +100,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), // One might think that we could listen to the precise property-changed signals of the preferences system. // Alas, this is not the case. When the user switches to system-format, the preferences sends the according // signal. However, the correct date and time format is set by the preferences dialog later. This should be fixed. - connect(PreferencesDialog::instance(), &PreferencesDialog::settingsChanged, this, &MainTab::updateDateTimeFields); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDateTimeFields); QAction *action = new QAction(tr("Apply changes"), this); connect(action, SIGNAL(triggered(bool)), this, SLOT(acceptChanges())); |