diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2019-03-29 18:29:08 +0100 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2019-04-12 18:19:07 +0300 |
commit | 837ab6c90b7952095c0dadf2de18db883b0f5ecf (patch) | |
tree | 3e6a619cdda0b5cc06308887a2df265fa95fdf2f /desktop-widgets | |
parent | bfb6a55707ffe1ffc36fddf2c98b9d5f91721317 (diff) | |
download | subsurface-837ab6c90b7952095c0dadf2de18db883b0f5ecf.tar.gz |
Desktop: read tab-items from current_dive, not displayed_dive
The whole edit logic moved from displayed_dive to current_dive
and it became more and more tedious to keep these in sync.
Therefore, simply always display current_dive. The only exceptions
are the equipment tab and the planner, as these are not yet
integrated in the undo system. Once this is done, displayed_dive
can be removed.
Moreover, remove the clear parameter from updateDiveInfo().
Instead simply clear of there is no current_dive set.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 5 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.cpp | 80 | ||||
-rw-r--r-- | desktop-widgets/tab-widgets/maintab.h | 2 |
3 files changed, 42 insertions, 45 deletions
diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index 0e4daf0e2..cc1adc3b2 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -465,7 +465,7 @@ void MainWindow::selectionChanged() { if (!current_dive) { mainTab->clearTabs(); - mainTab->updateDiveInfo(true); + mainTab->updateDiveInfo(); graphics->setEmptyState(); } else { graphics->plotDive(nullptr, false, true); @@ -634,8 +634,9 @@ void MainWindow::on_actionCloudOnline_triggered() void MainWindow::cleanUpEmpty() { + current_dive = nullptr; mainTab->clearTabs(); - mainTab->updateDiveInfo(true); + mainTab->updateDiveInfo(); graphics->setEmptyState(); diveList->reload(); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp index 9a5405583..cc4f4faac 100644 --- a/desktop-widgets/tab-widgets/maintab.cpp +++ b/desktop-widgets/tab-widgets/maintab.cpp @@ -419,17 +419,17 @@ void MainTab::nextInputField(QKeyEvent *event) keyPressEvent(event); } -#define UPDATE_TEXT(d, field) \ - if (clear || !d.field) \ +#define UPDATE_TEXT(field) \ + if (!current_dive || !current_dive->field) \ ui.field->setText(QString()); \ - else \ - ui.field->setText(d.field) + else \ + ui.field->setText(current_dive->field) -#define UPDATE_TEMP(d, field) \ - if (clear || d.field.mkelvin == 0) \ - ui.field->setText(""); \ - else \ - ui.field->setText(get_temperature_string(d.field, true)) +#define UPDATE_TEMP(field) \ + if (!current_dive || current_dive->field.mkelvin == 0) \ + ui.field->setText(""); \ + else \ + ui.field->setText(get_temperature_string(current_dive->field, true)) bool MainTab::isEditing() { @@ -480,16 +480,16 @@ void MainTab::updateDiveSite(struct dive *d) } } -void MainTab::updateDiveInfo(bool clear) +void MainTab::updateDiveInfo() { ui.location->refreshDiveSiteCache(); EditMode rememberEM = editMode; // don't execute this while adding / planning a dive if (editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics->isPlanner()) return; - if (!isEnabled() && !clear ) + if (!isEnabled() && current_dive) setEnabled(true); - if (isEnabled() && clear) + if (isEnabled() && !current_dive) setEnabled(false); editMode = IGNORE; // don't trigger on changes to the widgets @@ -497,19 +497,17 @@ void MainTab::updateDiveInfo(bool clear) widget->updateData(); } - ui.notes->setText(QString()); - if (!clear) - updateNotes(&displayed_dive); - UPDATE_TEXT(displayed_dive, suit); - UPDATE_TEXT(displayed_dive, divemaster); - UPDATE_TEXT(displayed_dive, buddy); - UPDATE_TEMP(displayed_dive, airtemp); - UPDATE_TEMP(displayed_dive, watertemp); - updateMode(&displayed_dive); - - if (!clear) { - updateDiveSite(&displayed_dive); - updateDateTime(&displayed_dive); + UPDATE_TEXT(suit); + UPDATE_TEXT(divemaster); + UPDATE_TEXT(buddy); + UPDATE_TEMP(airtemp); + UPDATE_TEMP(watertemp); + + if (current_dive) { + updateNotes(current_dive); + updateMode(current_dive); + updateDiveSite(current_dive); + updateDateTime(current_dive); if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) { // Remember the tab selected for last dive if (lastSelectedDive) @@ -603,25 +601,23 @@ void MainTab::updateDiveInfo(bool clear) ui.timeLabel->setVisible(true); ui.timeEdit->setVisible(true); /* and fill them from the dive */ - ui.rating->setCurrentStars(displayed_dive.rating); - ui.visibility->setCurrentStars(displayed_dive.visibility); + ui.rating->setCurrentStars(current_dive->rating); + ui.visibility->setCurrentStars(current_dive->visibility); // reset labels in case we last displayed trip notes ui.LocationLabel->setText(tr("Location")); ui.NotesLabel->setText(tr("Notes")); ui.equipmentTab->setEnabled(true); cylindersModel->updateDive(); weightModel->updateDive(); - ui.tagWidget->setText(get_taglist_string(displayed_dive.tag_list)); - if (current_dive) { - bool isManual = same_string(current_dive->dc.model, "manually added dive"); - ui.depth->setVisible(isManual); - ui.depthLabel->setVisible(isManual); - ui.duration->setVisible(isManual); - ui.durationLabel->setVisible(isManual); - } + ui.tagWidget->setText(get_taglist_string(current_dive->tag_list)); + bool isManual = same_string(current_dive->dc.model, "manually added dive"); + ui.depth->setVisible(isManual); + ui.depthLabel->setVisible(isManual); + ui.duration->setVisible(isManual); + ui.durationLabel->setVisible(isManual); } - ui.duration->setText(render_seconds_to_string(displayed_dive.duration.seconds)); - ui.depth->setText(get_depth_string(displayed_dive.maxdepth, true)); + ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds)); + ui.depth->setText(get_depth_string(current_dive->maxdepth, true)); volume_t gases[MAX_CYLINDERS] = {}; get_gas_used(&displayed_dive, gases); @@ -661,8 +657,8 @@ void MainTab::updateDiveInfo(bool clear) else ui.cylinders->view()->hideColumn(CylindersModel::USE); - if (verbose && displayed_dive.dive_site) - qDebug() << "Set the current dive site:" << displayed_dive.dive_site->uuid; + if (verbose && current_dive && current_dive->dive_site) + qDebug() << "Set the current dive site:" << current_dive->dive_site->uuid; emit diveSiteChanged(); } @@ -706,7 +702,7 @@ MainTab::EditMode MainTab::getEditMode() const void MainTab::refreshDisplayedDiveSite() { - struct dive_site *ds = get_dive_site_for_dive(&displayed_dive); + struct dive_site *ds = get_dive_site_for_dive(current_dive); if (ds) ui.location->setCurrentDiveSite(ds); } @@ -877,14 +873,14 @@ void MainTab::rejectChanges() copy_dive(current_dive, &displayed_dive); else clear_dive(&displayed_dive); - updateDiveInfo(!current_dive); + updateDiveInfo(); for (auto widget : extraWidgets) { widget->updateData(); } // the user could have edited the location and then canceled the edit // let's get the correct location back in view - MapWidget::instance()->centerOnDiveSite(displayed_dive.dive_site); + MapWidget::instance()->centerOnDiveSite(current_dive ? current_dive->dive_site : nullptr); // show the profile and dive info MainWindow::instance()->graphics->replot(); MainWindow::instance()->setEnabledToolbar(true); diff --git a/desktop-widgets/tab-widgets/maintab.h b/desktop-widgets/tab-widgets/maintab.h index 67657fe8d..59503fa06 100644 --- a/desktop-widgets/tab-widgets/maintab.h +++ b/desktop-widgets/tab-widgets/maintab.h @@ -63,7 +63,7 @@ slots: void tripChanged(dive_trip *trip, TripField field); void addCylinder_clicked(); void addWeight_clicked(); - void updateDiveInfo(bool clear = false); + void updateDiveInfo(); void updateNotes(const struct dive *d); void updateMode(struct dive *d); void updateDateTime(struct dive *d); |