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 <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2022-09-09 18:12:31 +02:00 committed by bstoeger
parent cded7ef5fe
commit 8cd191c271
14 changed files with 20 additions and 13 deletions

View file

@ -1,6 +1,10 @@
// SPDX-License-Identifier: GPL-2.0
#include "TabBase.h"
TabBase::TabBase(MainTab *parent) : parent(*parent)
{
}
void TabBase::updateUi(QString)
{
}

View file

@ -5,15 +5,18 @@
#include <QWidget>
struct dive;
class MainTab;
class TabBase : public QWidget {
Q_OBJECT
public:
using QWidget::QWidget;
TabBase(MainTab *parent);
virtual void updateData(const std::vector<dive *> &selection, dive *currentDive, int currentDC) = 0;
virtual void clear() = 0;
virtual void updateUi(QString titleColor);
protected:
MainTab &parent;
};
#endif

View file

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

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;

View file

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

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;

View file

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

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;

View file

@ -20,7 +20,7 @@ struct Completers {
QCompleter *tags;
};
TabDiveNotes::TabDiveNotes(QWidget *parent) : TabBase(parent),
TabDiveNotes::TabDiveNotes(MainTab *parent) : TabBase(parent),
ignoreInput(false),
currentTrip(0)
{

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;
void closeWarning();

View file

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

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;

View file

@ -8,7 +8,7 @@
#include <QLabel>
#include <QIcon>
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"));

View file

@ -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<dive *> &selection, dive *currentDive, int currentDC) override;
void clear() override;