profile: remove AbstractProfilePolygonItem::modelDataChanged()

The old mechanism to replot the profile items was to listen
to model-change signals. Then the code checked whether it
actually had to update anything by looking at the changed
model-indices.

However, the crucial replot was always initialized with
emitDataChanged(), which simple invalidated the full model
and therefore shouldCalculateStuff() always returned true.

Since now the replot() is called explicitly, remove the whole
logic and simply rename modelDataChanged() to replot().

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2020-12-29 23:31:54 +01:00 committed by Dirk Hohndel
parent 0104b0a915
commit f5e60b9618
2 changed files with 26 additions and 84 deletions

View file

@ -26,32 +26,12 @@ void AbstractProfilePolygonItem::clear()
texts.clear();
}
void AbstractProfilePolygonItem::replot()
{
modelDataChanged();
}
void AbstractProfilePolygonItem::setVisible(bool visible)
{
QGraphicsPolygonItem::setVisible(visible);
}
bool AbstractProfilePolygonItem::shouldCalculateStuff(const QModelIndex &topLeft, const QModelIndex &bottomRight)
{
if (dataModel.rowCount() == 0)
return false;
if (hDataColumn == -1 || vDataColumn == -1)
return false;
if (topLeft.isValid() && bottomRight.isValid()) {
if ((topLeft.column() >= vDataColumn || topLeft.column() >= hDataColumn) &&
(bottomRight.column() <= vDataColumn || topLeft.column() <= hDataColumn)) {
return true;
}
}
return true;
}
void AbstractProfilePolygonItem::modelDataChanged(const QModelIndex&, const QModelIndex&)
void AbstractProfilePolygonItem::replot()
{
// Calculate the polygon. This is the polygon that will be painted on screen
// on the ::paint method. Here we calculate the correct position of the points
@ -123,13 +103,11 @@ int DiveProfileItem::maxCeiling(int row)
return max;
}
void DiveProfileItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveProfileItem::replot()
{
bool eventAdded = false;
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
AbstractProfilePolygonItem::replot();
if (polygon().isEmpty())
return;
@ -226,7 +204,7 @@ DiveHeartrateItem::DiveHeartrateItem(const DivePlotDataModel &model, const DiveC
connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::hrgraphChanged, this, &DiveHeartrateItem::setVisible);
}
void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveHeartrateItem::replot()
{
int last = -300, last_printed_hr = 0, sec = 0;
struct {
@ -234,10 +212,6 @@ void DiveHeartrateItem::modelDataChanged(const QModelIndex &topLeft, const QMode
int hr;
} hist[3] = {};
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
qDeleteAll(texts);
texts.clear();
// Ignore empty values. a heart rate of 0 would be a bad sign.
@ -309,14 +283,10 @@ DivePercentageItem::DivePercentageItem(const DivePlotDataModel &model, const Div
connect(qPrefTechnicalDetails::instance(), &qPrefTechnicalDetails::percentagegraphChanged, this, &DivePercentageItem::setVisible);
}
void DivePercentageItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DivePercentageItem::replot()
{
int sec = 0;
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
// Ignore empty values. a heart rate of 0 would be a bad sign.
QPolygonF poly;
for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) {
@ -389,14 +359,10 @@ DiveAmbPressureItem::DiveAmbPressureItem(const DivePlotDataModel &model, const D
setPen(pen);
}
void DiveAmbPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveAmbPressureItem::replot()
{
int sec = 0;
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
// Ignore empty values. a heart rate of 0 would be a bad sign.
QPolygonF poly;
for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) {
@ -434,14 +400,10 @@ DiveGFLineItem::DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesi
setPen(pen);
}
void DiveGFLineItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveGFLineItem::replot()
{
int sec = 0;
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
// Ignore empty values. a heart rate of 0 would be a bad sign.
QPolygonF poly;
for (int i = 0, modelDataCount = dataModel.rowCount(); i < modelDataCount; i++) {
@ -479,12 +441,9 @@ DiveTemperatureItem::DiveTemperatureItem(const DivePlotDataModel &model, const D
setPen(pen);
}
void DiveTemperatureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveTemperatureItem::replot()
{
int last = -300, last_printed_temp = 0, sec = 0, last_valid_temp = 0;
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
qDeleteAll(texts);
texts.clear();
@ -560,12 +519,9 @@ DiveMeanDepthItem::DiveMeanDepthItem(const DivePlotDataModel &model, const DiveC
lastRunningSum = 0.0;
}
void DiveMeanDepthItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveMeanDepthItem::replot()
{
double meandepthvalue = 0.0;
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
QPolygonF poly;
plot_data *entry = dataModel.data().entry;
@ -610,12 +566,8 @@ void DiveMeanDepthItem::createTextItem()
texts.append(text);
}
void DiveGasPressureItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveGasPressureItem::replot()
{
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
const struct plot_info *pInfo = &dataModel.data();
std::vector<int> plotted_cyl(pInfo->nr_cylinders, false);
std::vector<int> last_plotted(pInfo->nr_cylinders, 0);
@ -787,12 +739,9 @@ DiveCalculatedCeiling::DiveCalculatedCeiling(const DivePlotDataModel &model, con
setVisible(prefs.calcceiling);
}
void DiveCalculatedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveCalculatedCeiling::replot()
{
// We don't have enougth data to calculate things, quit.
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
AbstractProfilePolygonItem::modelDataChanged(topLeft, bottomRight);
AbstractProfilePolygonItem::replot();
// Add 2 points to close the polygon.
QPolygonF poly = polygon();
if (poly.isEmpty())
@ -838,11 +787,8 @@ DiveReportedCeiling::DiveReportedCeiling(const DivePlotDataModel &model, const D
setVisible(prefs.dcceiling);
}
void DiveReportedCeiling::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void DiveReportedCeiling::replot()
{
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
QPolygonF p;
p.append(QPointF(hAxis.posAtValue(0), vAxis.posAtValue(0)));
plot_data *entry = dataModel.data().entry;
@ -874,11 +820,8 @@ void DiveReportedCeiling::paint(QPainter *painter, const QStyleOptionGraphicsIte
QGraphicsPolygonItem::paint(painter, option, widget);
}
void PartialPressureGasItem::modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight)
void PartialPressureGasItem::replot()
{
if (!shouldCalculateStuff(topLeft, bottomRight))
return;
plot_data *entry = dataModel.data().entry;
QPolygonF poly;
QPolygonF alertpoly;

View file

@ -38,10 +38,9 @@ public:
AbstractProfilePolygonItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) = 0;
void clear();
virtual void replot();
public
slots:
virtual void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex());
void replot();
void setVisible(bool visible);
protected:
@ -68,7 +67,7 @@ class DiveProfileItem : public AbstractProfilePolygonItem {
public:
DiveProfileItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void settingsToggled(bool toggled);
void plot_depth_sample(struct plot_data *entry, QFlags<Qt::AlignmentFlag> flags, const QColor &color);
int maxCeiling(int row);
@ -83,7 +82,7 @@ class DiveMeanDepthItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DiveMeanDepthItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private:
@ -96,7 +95,7 @@ class DiveTemperatureItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DiveTemperatureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private:
@ -107,7 +106,7 @@ class DiveHeartrateItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DiveHeartrateItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private:
@ -119,7 +118,7 @@ class DivePercentageItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DivePercentageItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn, int i);
void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private:
@ -133,7 +132,7 @@ class DiveAmbPressureItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DiveAmbPressureItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private:
@ -144,7 +143,7 @@ class DiveGFLineItem : public AbstractProfilePolygonItem {
Q_OBJECT
public:
DiveGFLineItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) override;
private:
@ -156,7 +155,7 @@ class DiveGasPressureItem : public AbstractProfilePolygonItem {
public:
using AbstractProfilePolygonItem::AbstractProfilePolygonItem;
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private:
@ -171,7 +170,7 @@ class DiveCalculatedCeiling : public AbstractProfilePolygonItem {
public:
DiveCalculatedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn,
const DiveCartesianAxis &vAxis, int vColumn, ProfileWidget2 *profileWidget);
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
private:
@ -183,7 +182,7 @@ class DiveReportedCeiling : public AbstractProfilePolygonItem {
public:
DiveReportedCeiling(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
};
@ -200,7 +199,7 @@ class PartialPressureGasItem : public AbstractProfilePolygonItem {
public:
PartialPressureGasItem(const DivePlotDataModel &model, const DiveCartesianAxis &hAxis, int hColumn, const DiveCartesianAxis &vAxis, int vColumn);
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) override;
void modelDataChanged(const QModelIndex &topLeft = QModelIndex(), const QModelIndex &bottomRight = QModelIndex()) override;
void replot() override;
void setThresholdSettingsKey(const double *prefPointerMin, const double *prefPointerMax);
void setVisibilitySettingsKey(const QString &setVisibilitySettingsKey);
void setColors(const QColor &normalColor, const QColor &alertColor);