diff options
Diffstat (limited to 'desktop-widgets/tab-widgets')
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveStatistics.cpp | 24 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/TabDiveStatistics.h | 4 |
2 files changed, 28 insertions, 0 deletions
diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp index 2de8a8013..3719363df 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp @@ -21,6 +21,8 @@ TabDiveStatistics::TabDiveStatistics(QWidget *parent) : TabBase(parent), ui(new ui->timeLimits->overrideMinToolTipText(tr("Shortest dive")); ui->timeLimits->overrideAvgToolTipText(tr("Average length of all selected dives")); + connect(&diveListNotifier, &DiveListNotifier::divesChanged, this, &TabDiveStatistics::divesChanged); + const auto l = findChildren<QLabel *>(QString(), Qt::FindDirectChildrenOnly); for (QLabel *label: l) { label->setAlignment(Qt::AlignHCenter); @@ -42,6 +44,28 @@ void TabDiveStatistics::clear() ui->timeLimits->clear(); } +// This function gets called if a field gets updated by an undo command. +// Refresh the corresponding UI field. +void TabDiveStatistics::divesChanged(const QVector<dive *> &dives, DiveField field) +{ + // If none of the changed dives is selected, do nothing + if (std::none_of(dives.begin(), dives.end(), [] (const dive *d) { return d->selected; })) + return; + + // TODO: make this more fine grained. Currently, the core can only calculate *all* statistics. + switch(field) { + case DiveField::DURATION: + case DiveField::DEPTH: + case DiveField::MODE: + case DiveField::AIR_TEMP: + case DiveField::WATER_TEMP: + updateData(); + break; + default: + break; + } +} + void TabDiveStatistics::updateData() { stats_t stats_selection; diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.h b/desktop-widgets/tab-widgets/TabDiveStatistics.h index c763b2e88..2fb4ebc85 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.h +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.h @@ -3,6 +3,7 @@ #define TAB_DIVE_STATISTICS_H #include "TabBase.h" +#include "core/subsurface-qt/DiveListNotifier.h" namespace Ui { class TabDiveStatistics; @@ -16,6 +17,9 @@ public: void updateData() override; void clear() override; +private slots: + void divesChanged(const QVector<dive *> &dives, DiveField field); + private: Ui::TabDiveStatistics *ui; }; |