summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2021-01-27 23:41:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2021-02-06 10:00:39 -0800
commit0b0e6672d5622238c2fb583dad6b51813b9338b3 (patch)
treed720b6d5b6d176667b029de691822c54ca8718c9
parentaefbde93ce161c08b4aca31aee4e3fc45ab72003 (diff)
downloadsubsurface-0b0e6672d5622238c2fb583dad6b51813b9338b3.tar.gz
profile: detect dive-mode change in profile
The profile must be replotted when the dive mode changes. Weirdly, this was routed via the dive-information tab (making it inherently non-mobile compatible). Detect such a change directly in the profile. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--desktop-widgets/tab-widgets/TabDiveInformation.cpp9
-rw-r--r--profile-widget/profilewidget2.cpp12
-rw-r--r--profile-widget/profilewidget2.h2
3 files changed, 14 insertions, 9 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp
index 46d5c4f8b..c8112b2cd 100644
--- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp
+++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp
@@ -316,7 +316,6 @@ void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField fi
if (!current_dive || !dives.contains(current_dive))
return;
- bool replot = false;
if (field.visibility)
ui->visibility->setCurrentStars(current_dive->visibility);
if (field.wavesize)
@@ -327,10 +326,8 @@ void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField fi
ui->surge->setCurrentStars(current_dive->surge);
if (field.chill)
ui->chill->setCurrentStars(current_dive->chill);
- if (field.mode) {
+ if (field.mode)
updateMode(current_dive);
- replot = true;
- }
if (field.duration || field.depth || field.mode)
updateProfile();
if (field.air_temp)
@@ -347,10 +344,6 @@ void TabDiveInformation::divesChanged(const QVector<dive *> &dives, DiveField fi
salinity_value = current_dive->salinity;
ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value));
ui->salinityText->setText(QString("%L1g/ℓ").arg(salinity_value / 10.0));
- // TODO: The profile should recognize itself when the dive mode changed.
- // It seem awkward to route this via the dive-information tab.
- if (replot)
- MainWindow::instance()->graphics->plotDive(current_dive, true);
}
void TabDiveInformation::on_visibility_valueChanged(int value)
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 128793fd9..5d37496e3 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -32,7 +32,6 @@
#include "core/gettextfromc.h"
#include "core/imagedownloader.h"
#endif
-#include "core/subsurface-qt/divelistnotifier.h"
#include <libdivecomputer/parser.h>
#include <QScrollBar>
@@ -174,6 +173,7 @@ ProfileWidget2::ProfileWidget2(QWidget *parent) : QGraphicsView(parent),
connect(&diveListNotifier, &DiveListNotifier::cylinderEdited, this, &ProfileWidget2::profileChanged);
connect(&diveListNotifier, &DiveListNotifier::eventsChanged, this, &ProfileWidget2::profileChanged);
connect(&diveListNotifier, &DiveListNotifier::pictureOffsetChanged, this, &ProfileWidget2::pictureOffsetChanged);
+ connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &ProfileWidget2::divesChanged);
#endif // SUBSURFACE_MOBILE
#if !defined(QT_NO_DEBUG) && defined(SHOW_PLOT_INFO_TABLE)
@@ -814,6 +814,16 @@ void ProfileWidget2::plotDive(const struct dive *d, bool force, bool doClearPict
}
}
+void ProfileWidget2::divesChanged(const QVector<dive *> &dives, DiveField field)
+{
+ // If the mode of the currently displayed dive changed, replot
+ if (field.mode &&
+ std::any_of(dives.begin(), dives.end(),
+ [id = displayed_dive.id] (const dive *d)
+ { return d->id == id; } ))
+ replot();
+}
+
void ProfileWidget2::actionRequestedReplot(bool)
{
settingsChanged();
diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h
index be40694a7..b2632d511 100644
--- a/profile-widget/profilewidget2.h
+++ b/profile-widget/profilewidget2.h
@@ -22,6 +22,7 @@
#include "core/color.h"
#include "core/pictureobj.h"
#include "core/units.h"
+#include "core/subsurface-qt/divelistnotifier.h"
class RulerItem2;
struct dive;
@@ -102,6 +103,7 @@ public
slots: // Necessary to call from QAction's signals.
void settingsChanged();
void actionRequestedReplot(bool triggered);
+ void divesChanged(const QVector<dive *> &dives, DiveField field);
void setEmptyState();
void setProfileState();
#ifndef SUBSURFACE_MOBILE