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>
This commit is contained in:
Berthold Stoeger 2020-11-24 12:50:52 +01:00 committed by Dirk Hohndel
parent 8bbd778c28
commit 2d7be7a0e3
16 changed files with 36 additions and 49 deletions

View file

@ -83,6 +83,9 @@ signals:
// The core structures were completely reset. Repopulate all models.
void dataReset();
// The settings changed. Repopulate / rerender unit-dependent data, etc.
void settingsChanged();
// Note that there are no signals for trips being added and created
// because these events never happen without a dive being added, removed or moved.
// The dives are always sorted according to the dives_less_than() function of the core.

View file

@ -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

View file

@ -33,6 +33,7 @@ signals:
void divesSelected();
public
slots:
void settingsChanged();
void reloadHeaderActions();
private
slots:

View file

@ -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);

View file

@ -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();

View file

@ -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());

View file

@ -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();
}

View file

@ -19,8 +19,6 @@ public:
void addPreferencePage(AbstractPreferencesWidget *page);
void refreshPages();
void defaultsRequested();
signals:
void settingsChanged();
private:
PreferencesDialog();
void cancelRequested();

View file

@ -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()));

View file

@ -3,9 +3,7 @@
#include "profile-widget/divetextitem.h"
#include "core/qthelper.h"
#include "core/subsurface-string.h"
#ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h"
#endif
#include "core/subsurface-qt/divelistnotifier.h"
#include "qt-models/diveplotdatamodel.h"
#include "profile-widget/animationfunctions.h"
#include "profile-widget/divelineitem.h"
@ -365,9 +363,7 @@ QColor DepthAxis::colorForValue(double)
DepthAxis::DepthAxis(ProfileWidget2 *widget) : DiveCartesianAxis(widget)
{
#ifndef SUBSURFACE_MOBILE
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
#endif
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DepthAxis::settingsChanged);
changed = true;
settingsChanged();
}
@ -422,9 +418,7 @@ PartialGasPressureAxis::PartialGasPressureAxis(ProfileWidget2 *widget) :
DiveCartesianAxis(widget),
model(NULL)
{
#ifndef SUBSURFACE_MOBILE
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
#endif
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &PartialGasPressureAxis::settingsChanged);
}
void PartialGasPressureAxis::setModel(DivePlotDataModel *m)

View file

@ -4,8 +4,8 @@
#include "core/pref.h"
#include "core/qthelper.h"
#include "core/settings/qPrefDisplay.h"
#include "core/subsurface-qt/divelistnotifier.h"
#ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h"
#include "core/dive.h" // for displayed_dive
#include "commands/command.h"
#endif
@ -50,9 +50,7 @@ DivePictureItem::DivePictureItem(QGraphicsItem *parent): DivePixmapItem(parent),
setFlag(ItemIgnoresTransformations);
setAcceptHoverEvents(true);
setScale(0.2);
#ifndef SUBSURFACE_MOBILE
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
#endif
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &DivePictureItem::settingsChanged);
canvas->setPen(Qt::NoPen);
canvas->setBrush(QColor(Qt::white));

View file

@ -5,22 +5,18 @@
#include "profile-widget/divetextitem.h"
#include "profile-widget/animationfunctions.h"
#include "core/profile.h"
#ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h"
#endif
#include "qt-models/diveplannermodel.h"
#include "core/qthelper.h"
#include "core/settings/qPrefTechnicalDetails.h"
#include "core/settings/qPrefLog.h"
#include "core/subsurface-qt/divelistnotifier.h"
#include "libdivecomputer/parser.h"
#include "profile-widget/profilewidget2.h"
AbstractProfilePolygonItem::AbstractProfilePolygonItem() : QObject(), QGraphicsPolygonItem(), hAxis(NULL), vAxis(NULL), dataModel(NULL), hDataColumn(-1), vDataColumn(-1)
{
setCacheMode(DeviceCoordinateCache);
#ifndef SUBSURFACE_MOBILE
connect(PreferencesDialog::instance(), SIGNAL(settingsChanged()), this, SLOT(settingsChanged()));
#endif
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &AbstractProfilePolygonItem::settingsChanged);
}
void AbstractProfilePolygonItem::settingsChanged()

View file

@ -31,8 +31,8 @@
#include "core/qthelper.h"
#include "core/gettextfromc.h"
#include "core/imagedownloader.h"
#include "core/subsurface-qt/divelistnotifier.h"
#endif
#include "core/subsurface-qt/divelistnotifier.h"
#include <libdivecomputer/parser.h>
#include <QScrollBar>
@ -47,9 +47,6 @@
#ifndef QT_NO_DEBUG
#include <QTableView>
#endif
#ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h"
#endif
#include <QtWidgets>
#define PP_GRAPHS_ENABLED (prefs.pp_graphs.po2 || prefs.pp_graphs.pn2 || prefs.pp_graphs.phe)

View file

@ -1,8 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include "profile-widget/ruleritem.h"
#ifndef SUBSURFACE_MOBILE
#include "desktop-widgets/preferences/preferencesdialog.h"
#endif
#include "profile-widget/profilewidget2.h"
#include "core/display.h"
#include "core/settings/qPrefTechnicalDetails.h"

View file

@ -87,6 +87,7 @@ TankInfoModel::TankInfoModel()
{
setHeaderDataStrings(QStringList() << tr("Description") << tr("ml") << tr("bar"));
connect(&diveListNotifier, &DiveListNotifier::dataReset, this, &TankInfoModel::update);
connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &TankInfoModel::update);
update();
}

View file

@ -6,7 +6,6 @@
#include <string.h>
#include <time.h>
#include "core/color.h"
#include "core/downloadfromdcthread.h" // for fill_computer_list
#include "core/errorhelper.h"
#include "core/parse.h"
@ -15,11 +14,7 @@
#include "core/subsurfacestartup.h"
#include "core/settings/qPref.h"
#include "core/tag.h"
#include "desktop-widgets/diveplanner.h"
#include "desktop-widgets/mainwindow.h"
#include "desktop-widgets/preferences/preferencesdialog.h"
#include "desktop-widgets/tab-widgets/maintab.h"
#include "profile-widget/profilewidget2.h"
#include <QApplication>
#include <QLoggingCategory>