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 <neolit123@gmail.com>
--
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 <dirk@hohndel.org>
This commit is contained in:
Lubomir I. Ivanov 2015-11-06 14:40:20 +02:00 committed by Dirk Hohndel
parent 61e768036e
commit 8e7be1b50a
5 changed files with 21 additions and 8 deletions

View file

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