diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 5924d4fa1..0430e2679 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -333,7 +333,7 @@ void MainWindow::updateAutogroup() void MainWindow::divesSelected(const std::vector &selection, dive *currentDive, int currentDC) { - mainTab->updateDiveInfo(); + mainTab->updateDiveInfo(selection, currentDive, currentDC); if (currentDive) enableDisableOtherDCsActions(); profile->plotCurrentDive(); @@ -827,7 +827,8 @@ void MainWindow::on_actionPreviousDC_triggered() unsigned nrdc = number_of_computers(current_dive); dc_number = (dc_number + nrdc - 1) % nrdc; profile->plotCurrentDive(); - mainTab->updateDiveInfo(); + // TODO: remove + mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number); } void MainWindow::on_actionNextDC_triggered() @@ -835,7 +836,8 @@ void MainWindow::on_actionNextDC_triggered() unsigned nrdc = number_of_computers(current_dive); dc_number = (dc_number + 1) % nrdc; profile->plotCurrentDive(); - mainTab->updateDiveInfo(); + // TODO: remove + mainTab->updateDiveInfo(getDiveSelection(), current_dive, dc_number); } void MainWindow::on_actionFullScreen_triggered(bool checked) diff --git a/desktop-widgets/tab-widgets/TabBase.h b/desktop-widgets/tab-widgets/TabBase.h index fa6be8717..aebce6dff 100644 --- a/desktop-widgets/tab-widgets/TabBase.h +++ b/desktop-widgets/tab-widgets/TabBase.h @@ -11,7 +11,7 @@ class TabBase : public QWidget { public: using QWidget::QWidget; - virtual void updateData() = 0; + virtual void updateData(const std::vector &selection, dive *currentDive, int currentDC) = 0; virtual void clear() = 0; virtual void updateUi(QString titleColor); }; diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp index efceeebf5..88cf8e2d9 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.cpp +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.cpp @@ -137,13 +137,13 @@ void TabDiveEquipment::toggleTriggeredColumn() } } -void TabDiveEquipment::updateData() +void TabDiveEquipment::updateData(const std::vector &, dive *currentDive, int currentDC) { - cylindersModel->updateDive(current_dive, dc_number); - weightModel->updateDive(current_dive); + cylindersModel->updateDive(currentDive, currentDC); + weightModel->updateDive(currentDive); - if (current_dive && current_dive->suit) - ui.suit->setText(QString(current_dive->suit)); + if (currentDive && currentDive->suit) + ui.suit->setText(QString(currentDive->suit)); else ui.suit->clear(); } diff --git a/desktop-widgets/tab-widgets/TabDiveEquipment.h b/desktop-widgets/tab-widgets/TabDiveEquipment.h index f70cd3f57..4db93bd14 100644 --- a/desktop-widgets/tab-widgets/TabDiveEquipment.h +++ b/desktop-widgets/tab-widgets/TabDiveEquipment.h @@ -19,7 +19,7 @@ class TabDiveEquipment : public TabBase { public: TabDiveEquipment(QWidget *parent = 0); ~TabDiveEquipment(); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; void closeWarning(); diff --git a/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp b/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp index 21ee1cdc4..337ccc355 100644 --- a/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp +++ b/desktop-widgets/tab-widgets/TabDiveExtraInfo.cpp @@ -19,9 +19,9 @@ TabDiveExtraInfo::~TabDiveExtraInfo() delete ui; } -void TabDiveExtraInfo::updateData() +void TabDiveExtraInfo::updateData(const std::vector &, dive *currentDive, int currentDC) { - const struct divecomputer *currentdc = get_dive_dc(current_dive, dc_number); + const struct divecomputer *currentdc = get_dive_dc(currentDive, currentDC); if (currentdc) extraDataModel->updateDiveComputer(currentdc); } diff --git a/desktop-widgets/tab-widgets/TabDiveExtraInfo.h b/desktop-widgets/tab-widgets/TabDiveExtraInfo.h index 86ed7abbe..008800788 100644 --- a/desktop-widgets/tab-widgets/TabDiveExtraInfo.h +++ b/desktop-widgets/tab-widgets/TabDiveExtraInfo.h @@ -15,7 +15,7 @@ class TabDiveExtraInfo : public TabBase { public: TabDiveExtraInfo(QWidget *parent = 0); ~TabDiveExtraInfo(); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; private: Ui::TabDiveExtraInfo *ui; diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.cpp b/desktop-widgets/tab-widgets/TabDiveInformation.cpp index 67824f9fa..41c829010 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.cpp +++ b/desktop-widgets/tab-widgets/TabDiveInformation.cpp @@ -203,23 +203,18 @@ void TabDiveInformation::showCurrentWidget(bool show, int position) ui->diveInfoScrollAreaLayout->addWidget(ui->groupBox_current, 6, position, 1, 1); } -void TabDiveInformation::updateData() +void TabDiveInformation::updateData(const std::vector &, dive *currentDive, int currentDC) { - if (!current_dive) { - clear(); - return; - } - int salinity_value; - manualDive = is_manually_added_dc(¤t_dive->dc); + manualDive = is_manually_added_dc(¤tDive->dc); updateWaterTypeWidget(); updateProfile(); updateWhen(); - ui->watertemp->setText(get_temperature_string(current_dive->watertemp, true)); - ui->airtemp->setText(get_temperature_string(current_dive->airtemp, true)); + ui->watertemp->setText(get_temperature_string(currentDive->watertemp, true)); + ui->airtemp->setText(get_temperature_string(currentDive->airtemp, true)); ui->atmPressType->setItemText(1, get_depth_unit()); // Check for changes in depth unit (imperial/metric) ui->atmPressType->setCurrentIndex(0); // Set the atmospheric pressure combo box to mbar - salinity_value = get_dive_salinity(current_dive); + salinity_value = get_dive_salinity(currentDive); if (salinity_value) { // Set water type indicator (EN13319 = 1.020 g/l) if (prefs.salinityEditDefault) { //If edit-salinity is enabled then set correct water type in combobox: ui->waterTypeCombo->setCurrentIndex(updateSalinityComboIndex(salinity_value)); @@ -234,12 +229,12 @@ void TabDiveInformation::updateData() } checkDcSalinityOverWritten(); // If exclamation is needed (i.e. salinity overwrite by user), then show it - updateMode(current_dive); - ui->visibility->setCurrentStars(current_dive->visibility); - ui->wavesize->setCurrentStars(current_dive->wavesize); - ui->current->setCurrentStars(current_dive->current); - ui->surge->setCurrentStars(current_dive->surge); - ui->chill->setCurrentStars(current_dive->chill); + updateMode(currentDive); + ui->visibility->setCurrentStars(currentDive->visibility); + ui->wavesize->setCurrentStars(currentDive->wavesize); + ui->current->setCurrentStars(currentDive->current); + ui->surge->setCurrentStars(currentDive->surge); + ui->chill->setCurrentStars(currentDive->chill); if (prefs.extraEnvironmentalDefault) showCurrentWidget(true, 2); // Show current star widget at 3rd position else diff --git a/desktop-widgets/tab-widgets/TabDiveInformation.h b/desktop-widgets/tab-widgets/TabDiveInformation.h index d8dda7c07..e2450f659 100644 --- a/desktop-widgets/tab-widgets/TabDiveInformation.h +++ b/desktop-widgets/tab-widgets/TabDiveInformation.h @@ -14,7 +14,7 @@ class TabDiveInformation : public TabBase { public: TabDiveInformation(QWidget *parent = 0); ~TabDiveInformation(); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; void updateUi(QString titleColor) override; private slots: diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.cpp b/desktop-widgets/tab-widgets/TabDiveNotes.cpp index 9bc94e371..ad8d8f623 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.cpp +++ b/desktop-widgets/tab-widgets/TabDiveNotes.cpp @@ -191,7 +191,7 @@ void TabDiveNotes::updateDiveSite(struct dive *d) ui.locationTags->show(); } -void TabDiveNotes::updateData() +void TabDiveNotes::updateData(const std::vector &, dive *currentDive, int currentDC) { ui.location->refreshDiveSiteCache(); @@ -246,25 +246,25 @@ void TabDiveNotes::updateData() ui.timeLabel->setVisible(true); ui.timeEdit->setVisible(true); /* and fill them from the dive */ - ui.rating->setCurrentStars(current_dive->rating); + ui.rating->setCurrentStars(currentDive->rating); // reset labels in case we last displayed trip notes ui.LocationLabel->setText(tr("Location")); ui.NotesLabel->setText(tr("Notes")); - ui.tagWidget->setText(get_taglist_string(current_dive->tag_list)); - bool isManual = is_manually_added_dc(¤t_dive->dc); + ui.tagWidget->setText(get_taglist_string(currentDive->tag_list)); + bool isManual = is_manually_added_dc(¤tDive->dc); ui.depth->setVisible(isManual); ui.depthLabel->setVisible(isManual); ui.duration->setVisible(isManual); ui.durationLabel->setVisible(isManual); - updateNotes(current_dive); - updateDiveSite(current_dive); - updateDateTime(current_dive); - ui.diveguide->setText(current_dive->diveguide); - ui.buddy->setText(current_dive->buddy); + updateNotes(currentDive); + updateDiveSite(currentDive); + updateDateTime(currentDive); + ui.diveguide->setText(currentDive->diveguide); + ui.buddy->setText(currentDive->buddy); } - ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds)); - ui.depth->setText(get_depth_string(current_dive->maxdepth, true)); + ui.duration->setText(render_seconds_to_string(currentDive->duration.seconds)); + ui.depth->setText(get_depth_string(currentDive->maxdepth, true)); ui.editDiveSiteButton->setEnabled(!ui.location->text().isEmpty()); /* unset the special value text for date and time, just in case someone dove at midnight */ diff --git a/desktop-widgets/tab-widgets/TabDiveNotes.h b/desktop-widgets/tab-widgets/TabDiveNotes.h index a0fe5490c..6acfb547e 100644 --- a/desktop-widgets/tab-widgets/TabDiveNotes.h +++ b/desktop-widgets/tab-widgets/TabDiveNotes.h @@ -17,7 +17,7 @@ class TabDiveNotes : public TabBase { Q_OBJECT public: TabDiveNotes(QWidget *parent = 0); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; void closeWarning(); diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.cpp b/desktop-widgets/tab-widgets/TabDivePhotos.cpp index 5c920e551..a540ce09e 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.cpp +++ b/desktop-widgets/tab-widgets/TabDivePhotos.cpp @@ -48,7 +48,8 @@ TabDivePhotos::~TabDivePhotos() void TabDivePhotos::clear() { - updateData(); + // TODO: clear model + divePictureModel->updateDivePictures(); } void TabDivePhotos::contextMenuEvent(QContextMenuEvent *event) @@ -159,8 +160,9 @@ void TabDivePhotos::removeAllPhotos() } } -void TabDivePhotos::updateData() +void TabDivePhotos::updateData(const std::vector &, dive *currentDive, int) { + // TODO: pass dive divePictureModel->updateDivePictures(); } diff --git a/desktop-widgets/tab-widgets/TabDivePhotos.h b/desktop-widgets/tab-widgets/TabDivePhotos.h index 1078e1ca2..5c5210f12 100644 --- a/desktop-widgets/tab-widgets/TabDivePhotos.h +++ b/desktop-widgets/tab-widgets/TabDivePhotos.h @@ -15,7 +15,7 @@ class TabDivePhotos : public TabBase { public: TabDivePhotos(QWidget *parent = 0); ~TabDivePhotos(); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; protected: diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp index c161ca6ab..8fd7d874a 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.cpp +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.cpp @@ -59,7 +59,7 @@ void TabDiveStatistics::divesChanged(const QVector &dives, DiveField fie // TODO: make this more fine grained. Currently, the core can only calculate *all* statistics. if (field.duration || field.depth || field.mode || field.air_temp || field.water_temp) - updateData(); + updateData(getDiveSelection(), current_dive, dc_number); // TODO: remember these data } void TabDiveStatistics::cylinderChanged(dive *d) @@ -67,10 +67,10 @@ void TabDiveStatistics::cylinderChanged(dive *d) // If the changed dive is not selected, do nothing if (!d->selected) return; - updateData(); + updateData(getDiveSelection(), current_dive, dc_number); // TODO: remember these data } -void TabDiveStatistics::updateData() +void TabDiveStatistics::updateData(const std::vector &, dive *currentDive, int) { stats_t stats_selection; calculate_stats_selected(&stats_selection); @@ -109,7 +109,7 @@ void TabDiveStatistics::updateData() } - bool is_freedive = current_dive && current_dive->dc.divemode == FREEDIVE; + bool is_freedive = currentDive && currentDive->dc.divemode == FREEDIVE; ui->divesAllText->setText(QString::number(stats_selection.selection_size)); ui->totalTimeAllText->setText(get_dive_duration_string(stats_selection.total_time.seconds, tr("h"), tr("min"), tr("sec"), " ", is_freedive)); diff --git a/desktop-widgets/tab-widgets/TabDiveStatistics.h b/desktop-widgets/tab-widgets/TabDiveStatistics.h index d6b1c1522..8c083cd2d 100644 --- a/desktop-widgets/tab-widgets/TabDiveStatistics.h +++ b/desktop-widgets/tab-widgets/TabDiveStatistics.h @@ -14,7 +14,7 @@ class TabDiveStatistics : public TabBase { public: TabDiveStatistics(QWidget *parent = 0); ~TabDiveStatistics(); - void updateData() override; + void updateData(const std::vector &selection, dive *currentDive, int currentDC) override; void clear() override; private slots: diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index f520a41fa..57b6aed93 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -49,7 +49,7 @@ MainTab::MainTab(QWidget *parent) : QTabWidget(parent), // call colorsChanged() for the initial setup now that the extraWidgets are loaded colorsChanged(); - connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::updateDiveInfo); + connect(&diveListNotifier, &DiveListNotifier::settingsChanged, this, &MainTab::settingsChanged); QShortcut *closeKey = new QShortcut(QKeySequence(Qt::Key_Escape), this); connect(closeKey, &QShortcut::activated, this, &MainTab::escDetected); @@ -70,7 +70,13 @@ void MainTab::nextInputField(QKeyEvent *event) keyPressEvent(event); } -void MainTab::updateDiveInfo() +void MainTab::settingsChanged() +{ + // TODO: remember these + updateDiveInfo(getDiveSelection(), current_dive, dc_number); +} + +void MainTab::updateDiveInfo(const std::vector &selection, dive *currentDive, int currentDC) { // don't execute this while planning a dive if (DivePlannerPointsModel::instance()->isPlanner()) @@ -81,9 +87,9 @@ void MainTab::updateDiveInfo() for (TabBase *widget: extraWidgets) widget->setEnabled(enabled); - if (current_dive) { + if (currentDive) { for (TabBase *widget: extraWidgets) - widget->updateData(); + widget->updateData(selection, currentDive, currentDC); if (single_selected_trip()) { // Remember the tab selected for last dive but only if we're not on the dive site tab if (lastSelectedDive) diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 871e20711..7bf41330c 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -24,7 +24,9 @@ public: public slots: - void updateDiveInfo(); + // Always called with non-null currentDive + void updateDiveInfo(const std::vector &selection, dive *currentDive, int currentDC); + void settingsChanged(); void escDetected(); void colorsChanged(); private: