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>
This commit is contained in:
Berthold Stoeger 2019-03-29 18:29:08 +01:00 committed by Dirk Hohndel
parent bfb6a55707
commit 837ab6c90b
5 changed files with 44 additions and 47 deletions

View file

@ -465,7 +465,7 @@ void MainWindow::selectionChanged()
{ {
if (!current_dive) { if (!current_dive) {
mainTab->clearTabs(); mainTab->clearTabs();
mainTab->updateDiveInfo(true); mainTab->updateDiveInfo();
graphics->setEmptyState(); graphics->setEmptyState();
} else { } else {
graphics->plotDive(nullptr, false, true); graphics->plotDive(nullptr, false, true);
@ -634,8 +634,9 @@ void MainWindow::on_actionCloudOnline_triggered()
void MainWindow::cleanUpEmpty() void MainWindow::cleanUpEmpty()
{ {
current_dive = nullptr;
mainTab->clearTabs(); mainTab->clearTabs();
mainTab->updateDiveInfo(true); mainTab->updateDiveInfo();
graphics->setEmptyState(); graphics->setEmptyState();
diveList->reload(); diveList->reload();
diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder); diveList->setSortOrder(DiveTripModelBase::NR, Qt::DescendingOrder);

View file

@ -419,17 +419,17 @@ void MainTab::nextInputField(QKeyEvent *event)
keyPressEvent(event); keyPressEvent(event);
} }
#define UPDATE_TEXT(d, field) \ #define UPDATE_TEXT(field) \
if (clear || !d.field) \ if (!current_dive || !current_dive->field) \
ui.field->setText(QString()); \ ui.field->setText(QString()); \
else \ else \
ui.field->setText(d.field) ui.field->setText(current_dive->field)
#define UPDATE_TEMP(d, field) \ #define UPDATE_TEMP(field) \
if (clear || d.field.mkelvin == 0) \ if (!current_dive || current_dive->field.mkelvin == 0) \
ui.field->setText(""); \ ui.field->setText(""); \
else \ else \
ui.field->setText(get_temperature_string(d.field, true)) ui.field->setText(get_temperature_string(current_dive->field, true))
bool MainTab::isEditing() bool MainTab::isEditing()
{ {
@ -480,16 +480,16 @@ void MainTab::updateDiveSite(struct dive *d)
} }
} }
void MainTab::updateDiveInfo(bool clear) void MainTab::updateDiveInfo()
{ {
ui.location->refreshDiveSiteCache(); ui.location->refreshDiveSiteCache();
EditMode rememberEM = editMode; EditMode rememberEM = editMode;
// don't execute this while adding / planning a dive // don't execute this while adding / planning a dive
if (editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics->isPlanner()) if (editMode == MANUALLY_ADDED_DIVE || MainWindow::instance()->graphics->isPlanner())
return; return;
if (!isEnabled() && !clear ) if (!isEnabled() && current_dive)
setEnabled(true); setEnabled(true);
if (isEnabled() && clear) if (isEnabled() && !current_dive)
setEnabled(false); setEnabled(false);
editMode = IGNORE; // don't trigger on changes to the widgets editMode = IGNORE; // don't trigger on changes to the widgets
@ -497,19 +497,17 @@ void MainTab::updateDiveInfo(bool clear)
widget->updateData(); widget->updateData();
} }
ui.notes->setText(QString()); UPDATE_TEXT(suit);
if (!clear) UPDATE_TEXT(divemaster);
updateNotes(&displayed_dive); UPDATE_TEXT(buddy);
UPDATE_TEXT(displayed_dive, suit); UPDATE_TEMP(airtemp);
UPDATE_TEXT(displayed_dive, divemaster); UPDATE_TEMP(watertemp);
UPDATE_TEXT(displayed_dive, buddy);
UPDATE_TEMP(displayed_dive, airtemp);
UPDATE_TEMP(displayed_dive, watertemp);
updateMode(&displayed_dive);
if (!clear) { if (current_dive) {
updateDiveSite(&displayed_dive); updateNotes(current_dive);
updateDateTime(&displayed_dive); updateMode(current_dive);
updateDiveSite(current_dive);
updateDateTime(current_dive);
if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) { if (MainWindow::instance() && MainWindow::instance()->diveList->selectedTrips().count() == 1) {
// Remember the tab selected for last dive // Remember the tab selected for last dive
if (lastSelectedDive) if (lastSelectedDive)
@ -603,25 +601,23 @@ void MainTab::updateDiveInfo(bool clear)
ui.timeLabel->setVisible(true); ui.timeLabel->setVisible(true);
ui.timeEdit->setVisible(true); ui.timeEdit->setVisible(true);
/* and fill them from the dive */ /* and fill them from the dive */
ui.rating->setCurrentStars(displayed_dive.rating); ui.rating->setCurrentStars(current_dive->rating);
ui.visibility->setCurrentStars(displayed_dive.visibility); ui.visibility->setCurrentStars(current_dive->visibility);
// reset labels in case we last displayed trip notes // reset labels in case we last displayed trip notes
ui.LocationLabel->setText(tr("Location")); ui.LocationLabel->setText(tr("Location"));
ui.NotesLabel->setText(tr("Notes")); ui.NotesLabel->setText(tr("Notes"));
ui.equipmentTab->setEnabled(true); ui.equipmentTab->setEnabled(true);
cylindersModel->updateDive(); cylindersModel->updateDive();
weightModel->updateDive(); weightModel->updateDive();
ui.tagWidget->setText(get_taglist_string(displayed_dive.tag_list)); ui.tagWidget->setText(get_taglist_string(current_dive->tag_list));
if (current_dive) { bool isManual = same_string(current_dive->dc.model, "manually added dive");
bool isManual = same_string(current_dive->dc.model, "manually added dive"); ui.depth->setVisible(isManual);
ui.depth->setVisible(isManual); ui.depthLabel->setVisible(isManual);
ui.depthLabel->setVisible(isManual); ui.duration->setVisible(isManual);
ui.duration->setVisible(isManual); ui.durationLabel->setVisible(isManual);
ui.durationLabel->setVisible(isManual);
}
} }
ui.duration->setText(render_seconds_to_string(displayed_dive.duration.seconds)); ui.duration->setText(render_seconds_to_string(current_dive->duration.seconds));
ui.depth->setText(get_depth_string(displayed_dive.maxdepth, true)); ui.depth->setText(get_depth_string(current_dive->maxdepth, true));
volume_t gases[MAX_CYLINDERS] = {}; volume_t gases[MAX_CYLINDERS] = {};
get_gas_used(&displayed_dive, gases); get_gas_used(&displayed_dive, gases);
@ -661,8 +657,8 @@ void MainTab::updateDiveInfo(bool clear)
else else
ui.cylinders->view()->hideColumn(CylindersModel::USE); ui.cylinders->view()->hideColumn(CylindersModel::USE);
if (verbose && displayed_dive.dive_site) if (verbose && current_dive && current_dive->dive_site)
qDebug() << "Set the current dive site:" << displayed_dive.dive_site->uuid; qDebug() << "Set the current dive site:" << current_dive->dive_site->uuid;
emit diveSiteChanged(); emit diveSiteChanged();
} }
@ -706,7 +702,7 @@ MainTab::EditMode MainTab::getEditMode() const
void MainTab::refreshDisplayedDiveSite() 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) if (ds)
ui.location->setCurrentDiveSite(ds); ui.location->setCurrentDiveSite(ds);
} }
@ -877,14 +873,14 @@ void MainTab::rejectChanges()
copy_dive(current_dive, &displayed_dive); copy_dive(current_dive, &displayed_dive);
else else
clear_dive(&displayed_dive); clear_dive(&displayed_dive);
updateDiveInfo(!current_dive); updateDiveInfo();
for (auto widget : extraWidgets) { for (auto widget : extraWidgets) {
widget->updateData(); widget->updateData();
} }
// the user could have edited the location and then canceled the edit // the user could have edited the location and then canceled the edit
// let's get the correct location back in view // 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 // show the profile and dive info
MainWindow::instance()->graphics->replot(); MainWindow::instance()->graphics->replot();
MainWindow::instance()->setEnabledToolbar(true); MainWindow::instance()->setEnabledToolbar(true);

View file

@ -63,7 +63,7 @@ slots:
void tripChanged(dive_trip *trip, TripField field); void tripChanged(dive_trip *trip, TripField field);
void addCylinder_clicked(); void addCylinder_clicked();
void addWeight_clicked(); void addWeight_clicked();
void updateDiveInfo(bool clear = false); void updateDiveInfo();
void updateNotes(const struct dive *d); void updateNotes(const struct dive *d);
void updateMode(struct dive *d); void updateMode(struct dive *d);
void updateDateTime(struct dive *d); void updateDateTime(struct dive *d);

View file

@ -1696,7 +1696,7 @@ void ProfileWidget2::splitDive()
duration_t time; duration_t time;
time.seconds = lrint(timeAxis->valueAt(scenePos)); time.seconds = lrint(timeAxis->valueAt(scenePos));
Command::splitDives(d, time); Command::splitDives(d, time);
emit updateDiveInfo(false); emit updateDiveInfo();
#endif #endif
} }
@ -1742,7 +1742,7 @@ void ProfileWidget2::changeGas()
// FIXME - this no longer gets written to the dive list - so we need to enableEdition() here // FIXME - this no longer gets written to the dive list - so we need to enableEdition() here
emit updateDiveInfo(false); emit updateDiveInfo();
mark_divelist_changed(true); mark_divelist_changed(true);
replot(); replot();
} }

View file

@ -97,7 +97,7 @@ signals:
void enableShortcuts(); void enableShortcuts();
void disableShortcuts(bool paste); void disableShortcuts(bool paste);
void refreshDisplay(bool recreateDivelist); void refreshDisplay(bool recreateDivelist);
void updateDiveInfo(bool clear); void updateDiveInfo();
void editCurrentDive(); void editCurrentDive();
void dateTimeChangedItems(); void dateTimeChangedItems();