summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-12-23 12:00:55 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-01-10 15:57:39 -0800
commit27810f321743e4e3c341e3d89257d82fc23946e6 (patch)
tree0dbf58b824d27f04a184c73cbcd80471449b9722
parent72427adc1c063ae5de08f4d92dc79824f6227614 (diff)
downloadsubsurface-27810f321743e4e3c341e3d89257d82fc23946e6.tar.gz
profile: remove model parameter from TankItem::setData()
This one is extremely obscure: TankItem::setData(), which is called on every replot, was passed the DivePlotDataModel, even though it doesn't access that model at all. Instead, it connect()s to the model to stay informed of changes to the data. First of all, this should obviously be done once in the constructor, not on every replot. But also, the setData() function is called on every replot one lines before sending the model-changed signal. Thus, the tankitem was always repainted twice. Just remove the whole connect() thing and go for a more deterministic model. Should the tankbar not be repainted anywhere, add the appropriate calls there. Accordingly rename the "modelDataChanged" slot to "replot". Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--profile-widget/profilewidget2.cpp2
-rw-r--r--profile-widget/tankitem.cpp14
-rw-r--r--profile-widget/tankitem.h7
3 files changed, 8 insertions, 15 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 05a1fcff1..ae215e67a 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -735,7 +735,7 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
ocpo2GasItem->setVisible(false);
}
#endif
- tankItem->setData(dataModel, &plotInfo, &displayed_dive);
+ tankItem->setData(&plotInfo, &displayed_dive);
dataModel->emitDataChanged();
// The event items are a bit special since we don't know how many events are going to
diff --git a/profile-widget/tankitem.cpp b/profile-widget/tankitem.cpp
index adf9ba99c..5469ffc0d 100644
--- a/profile-widget/tankitem.cpp
+++ b/profile-widget/tankitem.cpp
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-2.0
#include "profile-widget/tankitem.h"
-#include "qt-models/diveplotdatamodel.h"
#include "profile-widget/divetextitem.h"
#include "core/event.h"
#include "core/profile.h"
@@ -33,7 +32,7 @@ TankItem::TankItem(QObject *parent) :
hAxis = nullptr;
}
-void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d)
+void TankItem::setData(struct plot_info *plotInfo, struct dive *d)
{
// If there is nothing to plot, quit early.
if (plotInfo->nr <= 0) {
@@ -45,10 +44,7 @@ void TankItem::setData(DivePlotDataModel *model, struct plot_info *plotInfo, str
struct plot_data *last_entry = &plotInfo->entry[plotInfo->nr - 1];
plotEndTime = last_entry->sec;
- // Stay informed of changes to the tanks.
- connect(model, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SLOT(modelDataChanged(QModelIndex, QModelIndex)), Qt::UniqueConnection);
-
- modelDataChanged();
+ replot();
}
void TankItem::createBar(int startTime, int stopTime, struct gasmix gas)
@@ -79,7 +75,7 @@ void TankItem::createBar(int startTime, int stopTime, struct gasmix gas)
label->setZValue(101);
}
-void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
+void TankItem::replot()
{
// We don't have enougth data to calculate things, quit.
if (plotEndTime < 0)
@@ -115,6 +111,6 @@ void TankItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
void TankItem::setHorizontalAxis(DiveCartesianAxis *horizontal)
{
hAxis = horizontal;
- connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(modelDataChanged()));
- modelDataChanged();
+ connect(hAxis, SIGNAL(sizeChanged()), this, SLOT(replot()));
+ replot();
}
diff --git a/profile-widget/tankitem.h b/profile-widget/tankitem.h
index 73994444b..b89b6b0ff 100644
--- a/profile-widget/tankitem.h
+++ b/profile-widget/tankitem.h
@@ -3,7 +3,6 @@
#define TANKITEM_H
#include <QGraphicsItem>
-#include <QModelIndex>
#include <QBrush>
#include "profile-widget/divelineitem.h"
#include "profile-widget/divecartesianaxis.h"
@@ -16,12 +15,10 @@ class TankItem : public QObject, public QGraphicsRectItem
public:
explicit TankItem(QObject *parent = 0);
void setHorizontalAxis(DiveCartesianAxis *horizontal);
- void setData(DivePlotDataModel *model, struct plot_info *plotInfo, struct dive *d);
-
-signals:
+ void setData(struct plot_info *plotInfo, struct dive *d);
public slots:
- void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
+ void replot();
private:
void createBar(int startTime, int stopTime, struct gasmix gas);