summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--desktop-widgets/mainwindow.cpp5
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp80
-rw-r--r--desktop-widgets/tab-widgets/maintab.h2
-rw-r--r--profile-widget/profilewidget2.cpp4
-rw-r--r--profile-widget/profilewidget2.h2
5 files changed, 45 insertions, 48 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);
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 236afb850..f9655127e 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1696,7 +1696,7 @@ void ProfileWidget2::splitDive()
duration_t time;
time.seconds = lrint(timeAxis->valueAt(scenePos));
Command::splitDives(d, time);
- emit updateDiveInfo(false);
+ emit updateDiveInfo();
#endif
}
@@ -1742,7 +1742,7 @@ void ProfileWidget2::changeGas()
// 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);
replot();
}
diff --git a/profile-widget/profilewidget2.h b/profile-widget/profilewidget2.h
index 4cf69efa6..fbc43c623 100644
--- a/profile-widget/profilewidget2.h
+++ b/profile-widget/profilewidget2.h
@@ -97,7 +97,7 @@ signals:
void enableShortcuts();
void disableShortcuts(bool paste);
void refreshDisplay(bool recreateDivelist);
- void updateDiveInfo(bool clear);
+ void updateDiveInfo();
void editCurrentDive();
void dateTimeChangedItems();