From 2d7be7a0e366b562fdff914e92219ab1852cd3c8 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Tue, 24 Nov 2020 12:50:52 +0100 Subject: 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 --- desktop-widgets/divelistview.cpp | 8 ++++++++ desktop-widgets/divelistview.h | 1 + desktop-widgets/diveplanner.cpp | 4 ++++ desktop-widgets/filterconstraintwidget.cpp | 4 ++-- desktop-widgets/mainwindow.cpp | 10 ++-------- desktop-widgets/preferences/preferencesdialog.cpp | 9 +++++---- desktop-widgets/preferences/preferencesdialog.h | 2 -- desktop-widgets/tab-widgets/maintab.cpp | 4 ++-- 8 files changed, 24 insertions(+), 18 deletions(-) (limited to 'desktop-widgets') 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 #include #include @@ -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::of(&QSpinBox::valueChanged), &PlannerShared::set_bestmixend); connect(ui.bottomSAC, QOverload::of(&QDoubleSpinBox::valueChanged), &PlannerShared::set_bottomsac); connect(ui.decoStopSAC, QOverload::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 #include @@ -25,7 +26,7 @@ #include #include -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())); -- cgit v1.2.3-70-g09d2