From 8e7be1b50a93e667663b29d84dbd66c2a31975dc Mon Sep 17 00:00:00 2001 From: "Lubomir I. Ivanov" Date: Fri, 6 Nov 2015 14:40:20 +0200 Subject: Untangle DiveCalculatedCeiling from MainWindow DiveCalculatedCeiling is the last class the references MainWindow in the profile-widget stack. In modelDataChanged() it looks for the information() widget and sets a slot for the dateTimeChanged() signal that information() emits. To solve the issue we make DiveCalculatedCeiling recieve a ProfileWidget2 reference and make ProfileWidget2 emit the dateTimeChangedItems() signal. ProfileWidget2 itself listens for the dateTimeChanged() signal that information() emits and emits dateTimeChangedItems() to notify any possible children/item listeners in the ProfileWidget2::dateTimeChanged() slot. The connection between ProfileWidget2 and information() is set in MainWindow. This makes DiveCalculatedCeiling unaware of MainWindow and which class originally emits the dateTimeChanged() signal to ProfileWidget2. Signed-off-by: Lubomir I. Ivanov -- Think delegation. Tomaz, please take a look at this one, to double check if i messed up. also i have zero idea how the mobile app is setting these connections, if it does so even. Signed-off-by: Dirk Hohndel --- profile-widget/diveprofileitem.cpp | 9 +++++---- profile-widget/diveprofileitem.h | 8 ++++++-- profile-widget/profilewidget2.cpp | 9 +++++++-- profile-widget/profilewidget2.h | 2 ++ 4 files changed, 20 insertions(+), 8 deletions(-) (limited to 'profile-widget') diff --git a/profile-widget/diveprofileitem.cpp b/profile-widget/diveprofileitem.cpp index 9805c4df5..ddc771ab2 100644 --- a/profile-widget/diveprofileitem.cpp +++ b/profile-widget/diveprofileitem.cpp @@ -791,15 +791,16 @@ void DiveGasPressureItem::paint(QPainter *painter, const QStyleOptionGraphicsIte painter->restore(); } -DiveCalculatedCeiling::DiveCalculatedCeiling() : is3mIncrement(false) +DiveCalculatedCeiling::DiveCalculatedCeiling(ProfileWidget2 *widget) : + profileWidget(widget), + is3mIncrement(false) { settingsChanged(); } void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) { - if (MainWindow::instance()->information()) - connect(MainWindow::instance()->information(), SIGNAL(dateTimeChanged()), this, SLOT(recalc()), Qt::UniqueConnection); + connect(profileWidget, SIGNAL(dateTimeChangedItems()), this, SLOT(recalc()), Qt::UniqueConnection); // We don't have enougth data to calculate things, quit. if (!shouldCalculateStuff(topLeft, bottomRight)) @@ -830,7 +831,7 @@ void DiveCalculatedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsI QGraphicsPolygonItem::paint(painter, option, widget); } -DiveCalculatedTissue::DiveCalculatedTissue() +DiveCalculatedTissue::DiveCalculatedTissue(ProfileWidget2 *widget) : DiveCalculatedCeiling(widget) { settingsChanged(); } diff --git a/profile-widget/diveprofileitem.h b/profile-widget/diveprofileitem.h index 0bba7f7a3..8f9a56f6e 100644 --- a/profile-widget/diveprofileitem.h +++ b/profile-widget/diveprofileitem.h @@ -21,6 +21,7 @@ This is a generically item and should be used as a base for others, I think... */ +class ProfileWidget2; class DivePlotDataModel; class DiveTextItem; class DiveCartesianAxis; @@ -175,7 +176,7 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem { Q_OBJECT public: - DiveCalculatedCeiling(); + DiveCalculatedCeiling(ProfileWidget2 *profileWidget); virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()); virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0); virtual void settingsChanged(); @@ -184,6 +185,9 @@ public slots: void recalc(); +protected: + ProfileWidget2 *profileWidget; + private: bool is3mIncrement; }; @@ -200,7 +204,7 @@ public: class DiveCalculatedTissue : public DiveCalculatedCeiling { Q_OBJECT public: - DiveCalculatedTissue(); + DiveCalculatedTissue(ProfileWidget2 *profileWidget); virtual void settingsChanged(); }; diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 6b83508b4..177ceab75 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -92,7 +92,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent), cylinderPressureAxis(new DiveCartesianAxis(this)), gasPressureItem(new DiveGasPressureItem()), diveComputerText(new DiveTextItem()), - diveCeiling(new DiveCalculatedCeiling()), + diveCeiling(new DiveCalculatedCeiling(this)), decoModelParameters(new DiveTextItem()), reportedCeiling(new DiveReportedCeiling()), pn2GasItem(new PartialPressureGasItem()), @@ -302,7 +302,7 @@ void ProfileWidget2::setupItemOnScene() setupItem(reportedCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); setupItem(diveCeiling, timeAxis, profileYAxis, dataModel, DivePlotDataModel::CEILING, DivePlotDataModel::TIME, 1); for (int i = 0; i < 16; i++) { - DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(); + DiveCalculatedTissue *tissueItem = new DiveCalculatedTissue(this); setupItem(tissueItem, timeAxis, profileYAxis, dataModel, DivePlotDataModel::TISSUE_1 + i, DivePlotDataModel::TIME, 1 + i); allTissues.append(tissueItem); DivePercentageItem *percentageItem = new DivePercentageItem(i); @@ -708,6 +708,11 @@ void ProfileWidget2::recalcCeiling() diveCeiling->recalc(); } +void ProfileWidget2::dateTimeChanged() +{ + emit dateTimeChangedItems(); +} + void ProfileWidget2::settingsChanged() { // if we are showing calculated ceilings then we have to replot() diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h index 7b7030a7f..c73d675bb 100644 --- a/profile-widget/profilewidget2.h +++ b/profile-widget/profilewidget2.h @@ -97,9 +97,11 @@ signals: void refreshDisplay(bool recreateDivelist); void updateDiveInfo(bool clear); void editCurrentDive(); + void dateTimeChangedItems(); public slots: // Necessary to call from QAction's signals. + void dateTimeChanged(); void settingsChanged(); void setEmptyState(); void setProfileState(); -- cgit v1.2.3-70-g09d2