diff options
author | Robert C. Helling <helling@atdotde.de> | 2019-01-01 18:02:04 +0100 |
---|---|---|
committer | Robert C. Helling <helling@atdotde.de> | 2019-01-08 10:39:06 +0100 |
commit | c349692d984f417bf56f5fecb8f733d8fb007518 (patch) | |
tree | d66682b3d0426ad03bc9d53f6190c0023e0fd344 | |
parent | f1fc89b978c178fcd0f4f3ddb7629dc7df0d939d (diff) | |
download | subsurface-c349692d984f417bf56f5fecb8f733d8fb007518.tar.gz |
Helper function to determined planned dives
... to reduce code duplication.
Signed-off-by: Robert C. Helling <helling@atdotde.de>
-rw-r--r-- | core/dive.c | 6 | ||||
-rw-r--r-- | core/dive.h | 1 | ||||
-rw-r--r-- | core/subsurface-qt/DiveObjectHelper.cpp | 2 | ||||
-rw-r--r-- | desktop-widgets/mainwindow.cpp | 2 |
4 files changed, 8 insertions, 3 deletions
diff --git a/core/dive.c b/core/dive.c index 49431bffe..0ec9e381c 100644 --- a/core/dive.c +++ b/core/dive.c @@ -3357,6 +3357,10 @@ void dump_taglist(const char *intro, struct tag_entry *tl) fprintf(stderr, "\n"); } +bool is_dc_planner(const struct divecomputer *dc) { + return same_string(dc->model, "planned dive"); +} + /* * Merging two dives can be subtle, because there's two different ways * of merging: @@ -3401,7 +3405,7 @@ struct dive *merge_dives(const struct dive *a, const struct dive *b, int offset, offset = 0; } - if (same_string(a->dc.model, "planned dive")) { + if (is_dc_planner(&a->dc)) { const struct dive *tmp = a; a = b; b = tmp; diff --git a/core/dive.h b/core/dive.h index 0f6d72a81..f447c88b5 100644 --- a/core/dive.h +++ b/core/dive.h @@ -652,6 +652,7 @@ extern void nuclear_regeneration(struct deco_state *ds, double time); extern void vpmb_start_gradient(struct deco_state *ds); extern void vpmb_next_gradient(struct deco_state *ds, double deco_time, double surface_pressure); extern double tissue_tolerance_calc(struct deco_state *ds, const struct dive *dive, double pressure); +extern bool is_dc_planner(const struct divecomputer *dc); /* this should be converted to use our types */ struct divedatapoint { diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp index c85a3475e..0742e382f 100644 --- a/core/subsurface-qt/DiveObjectHelper.cpp +++ b/core/subsurface-qt/DiveObjectHelper.cpp @@ -169,7 +169,7 @@ QString DiveObjectHelper::waterTemp() const QString DiveObjectHelper::notes() const { QString tmp = m_dive->notes ? QString::fromUtf8(m_dive->notes) : QString(); - if (same_string(m_dive->dc.model, "planned dive")) { + if (is_dc_planner(&m_dive->dc)) { QTextDocument notes; #define _NOTES_BR "\n" tmp.replace("<thead>", "<thead>" _NOTES_BR) diff --git a/desktop-widgets/mainwindow.cpp b/desktop-widgets/mainwindow.cpp index aba1cfc63..d836e8e61 100644 --- a/desktop-widgets/mainwindow.cpp +++ b/desktop-widgets/mainwindow.cpp @@ -965,7 +965,7 @@ void MainWindow::on_actionReplanDive_triggered() { if (!plannerStateClean() || !current_dive) return; - else if (!current_dive->dc.model || strcmp(current_dive->dc.model, "planned dive")) { + else if (!is_dc_planner(¤t_dive->dc)) { if (QMessageBox::warning(this, tr("Warning"), tr("Trying to replan a dive that's not a planned dive."), QMessageBox::Ok | QMessageBox::Cancel) == QMessageBox::Cancel) return; |