From 8cd191c271e49b3228868c54ab74dbbf6e059bbc Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Fri, 9 Sep 2022 18:12:31 +0200 Subject: [PATCH] desktop: store pointer to parent in tab-widgets Make it possible for the individual tab-widgets to access the parent widget. In principle this could have been done by downcasting the pointer returned by parent(), but this makes it explicit. The goal here is to store information on the selection, current dive, etc. without repeating it in every subwidget. Signed-off-by: Berthold Stoeger --- desktop-widgets/tab-widgets/TabBase.cpp | 4 ++++ desktop-widgets/tab-widgets/TabBase.h | 5 ++++- desktop-widgets/tab-widgets/TabDiveEquipment.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveEquipment.h | 2 +- desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveExtraInfo.h | 2 +- desktop-widgets/tab-widgets/TabDiveInformation.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveInformation.h | 2 +- desktop-widgets/tab-widgets/TabDiveNotes.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveNotes.h | 2 +- desktop-widgets/tab-widgets/TabDivePhotos.cpp | 2 +- desktop-widgets/tab-widgets/TabDivePhotos.h | 2 +- desktop-widgets/tab-widgets/TabDiveStatistics.cpp | 2 +- desktop-widgets/tab-widgets/TabDiveStatistics.h | 2 +- 14 files changed, 20 insertions(+), 13 deletions(-) diff --git a/desktop-widgets/tab-widgets/TabBase.cpp b/desktop-widgets/tab-widgets/TabBase.cpp index b6bb390e9..5d31d99a9 100644 --- a/desktop-widgets/tab-widgets/TabBase.cpp +++ b/desktop-widgets/tab-widgets/TabBase.cpp @@ -1,6 +1,10 @@ // SPDX-License-Identifier: GPL-2.0 #include "TabBase.h" +TabBase::TabBase(MainTab *parent) : parent(*parent) +{ +} + void TabBase::updateUi(QString) { } diff --git a/desktop-widgets/tab-widgets/TabBase.h b/desktop-widgets/tab-widgets/TabBase.h index aebce6dff..d08e69075 100644 --- a/desktop-widgets/tab-widgets/TabBase.h +++ b/desktop-widgets/tab-widgets/TabBase.h @@ -5,15 +5,18 @@ #include struct dive; +class MainTab; class TabBase : public QWidget { Q_OBJECT public: - using QWidget::QWidget; + TabBase(MainTab *parent); virtual void updateData(const std::vector &selection, dive *currentDive, int currentDC) = 0; virtual void clear() = 0; virtual void updateUi(QString titleColor); +protected: + MainTab &parent; }; #endif diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index 88cf8e2d9..8e7632d6a 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -28,7 +28,7 @@ static bool hiddenByDefault(int i) return false; } -TabDiveEquipment::TabDiveEquipment(QWidget *parent) : TabBase(parent), +TabDiveEquipment::TabDiveEquipment(MainTab *parent) : TabBase(parent), cylindersModel(new CylindersModel(false, true, this)), weightModel(new WeightModel(this)) { diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.h b/desktop-widgets/tab-widgets/TabDiveEquipment.h index 4db93bd14..934ec9126 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.h +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.h @@ -17,7 +17,7 @@ class CylindersModel; class TabDiveEquipment : public TabBase { Q_OBJECT public: - TabDiveEquipment(QWidget *parent = 0); + TabDiveEquipment(MainTab *parent); ~TabDiveEquipment(); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; diff --git a/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp b/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp index 337ccc355..203f34864 100644 --- a/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp +++ b/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp @@ -5,7 +5,7 @@ #include "core/selection.h" #include "qt-models/divecomputerextradatamodel.h" -TabDiveExtraInfo::TabDiveExtraInfo(QWidget *parent) : +TabDiveExtraInfo::TabDiveExtraInfo(MainTab *parent) : TabBase(parent), ui(new Ui::TabDiveExtraInfo()), extraDataModel(new ExtraDataModel(this)) diff --git a/desktop-widgets/tab-widgets/TabDiveExtraInfo.h b/desktop-widgets/tab-widgets/TabDiveExtraInfo.h index 008800788..5e211f78a 100644 --- a/desktop-widgets/tab-widgets/TabDiveExtraInfo.h +++ b/desktop-widgets/tab-widgets/TabDiveExtraInfo.h @@ -13,7 +13,7 @@ class ExtraDataModel; class TabDiveExtraInfo : public TabBase { Q_OBJECT public: - TabDiveExtraInfo(QWidget *parent = 0); + TabDiveExtraInfo(MainTab *parent); ~TabDiveExtraInfo(); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 41c829010..3623b0534 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -16,7 +16,7 @@ #define COMBO_CHANGED 0 #define TEXT_EDITED 1 -TabDiveInformation::TabDiveInformation(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) +TabDiveInformation::TabDiveInformation(MainTab *parent) : TabBase(parent), ui(new Ui::TabDiveInformation()) { ui->setupUi(this); connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveInformation::divesChanged); diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index e2450f659..207e03c64 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -12,7 +12,7 @@ namespace Ui { class TabDiveInformation : public TabBase { Q_OBJECT public: - TabDiveInformation(QWidget *parent = 0); + TabDiveInformation(MainTab *parent); ~TabDiveInformation(); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.cpp b/desktop-widgets/tab-widgets/TabDiveNotes.cpp index ad8d8f623..9a1db18a5 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.cpp +++ b/desktop-widgets/tab-widgets/TabDiveNotes.cpp @@ -20,7 +20,7 @@ struct Completers { QCompleter *tags; }; -TabDiveNotes::TabDiveNotes(QWidget *parent) : TabBase(parent), +TabDiveNotes::TabDiveNotes(MainTab *parent) : TabBase(parent), ignoreInput(false), currentTrip(0) { diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.h b/desktop-widgets/tab-widgets/TabDiveNotes.h index 6acfb547e..0b67ef11d 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.h +++ b/desktop-widgets/tab-widgets/TabDiveNotes.h @@ -16,7 +16,7 @@ class DivePictureModel; class TabDiveNotes : public TabBase { Q_OBJECT public: - TabDiveNotes(QWidget *parent = 0); + TabDiveNotes(MainTab *parent); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; void closeWarning(); diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index a540ce09e..65d901480 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -19,7 +19,7 @@ #include "../mainwindow.h" #include "../divelistview.h" -TabDivePhotos::TabDivePhotos(QWidget *parent) +TabDivePhotos::TabDivePhotos(MainTab *parent) : TabBase(parent), ui(new Ui::TabDivePhotos()), divePictureModel(DivePictureModel::instance()) diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.h b/desktop-widgets/tab-widgets/TabDivePhotos.h index 5c5210f12..ff815081a 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.h +++ b/desktop-widgets/tab-widgets/TabDivePhotos.h @@ -13,7 +13,7 @@ class DivePictureModel; class TabDivePhotos : public TabBase { Q_OBJECT public: - TabDivePhotos(QWidget *parent = 0); + TabDivePhotos(MainTab *parent); ~TabDivePhotos(); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp index 8fd7d874a..0a9f505a2 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp @@ -8,7 +8,7 @@ #include #include -TabDiveStatistics::TabDiveStatistics(QWidget *parent) : TabBase(parent), ui(new Ui::TabDiveStatistics()) +TabDiveStatistics::TabDiveStatistics(MainTab *parent) : TabBase(parent), ui(new Ui::TabDiveStatistics()) { ui->setupUi(this); ui->sacLimits->overrideMaxToolTipText(tr("Highest total SAC of a dive")); diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.h b/desktop-widgets/tab-widgets/TabDiveStatistics.h index 8c083cd2d..0410e8cb0 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.h +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.h @@ -12,7 +12,7 @@ namespace Ui { class TabDiveStatistics : public TabBase { Q_OBJECT public: - TabDiveStatistics(QWidget *parent = 0); + TabDiveStatistics(MainTab *parent); ~TabDiveStatistics(); void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override;