aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2020-09-06 17:41:25 +0200
committerGravatar Dirk Hohndel <dirk@hohndel.org>2020-09-08 17:20:09 -0700
commit048cdcaa318f111e12d78c60927a0e2fc30eb1d6 (patch)
treebd790310bf18472427874af3ef484bd495cc4859
parent0424ee8996f231dbba1ffb6e6db087855dbb26a2 (diff)
downloadsubsurface-048cdcaa318f111e12d78c60927a0e2fc30eb1d6.tar.gz
cleanup: remove count_divecomputers() function
There is a number_of_computers() function which does the same thing with two exceptions: 1) checks for null-dive 2) returns an unsigned int Replace calls to count_divecomputers() by calls to number_of_computers(). In one case, the return type makes a different - add a cast to int there. Ultimately, we should probably change the dc_number to signed int throughout the code. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--commands/command_divelist.cpp2
-rw-r--r--core/dive.c13
-rw-r--r--core/dive.h1
-rw-r--r--profile-widget/profilewidget2.cpp4
4 files changed, 4 insertions, 16 deletions
diff --git a/commands/command_divelist.cpp b/commands/command_divelist.cpp
index 8f769514a..6d81482e0 100644
--- a/commands/command_divelist.cpp
+++ b/commands/command_divelist.cpp
@@ -905,7 +905,7 @@ MoveDiveComputerToFront::MoveDiveComputerToFront(dive *d, int dc_num)
}
DeleteDiveComputer::DeleteDiveComputer(dive *d, int dc_num)
- : DiveComputerBase(d, clone_delete_divecomputer(d, dc_num), std::min(count_divecomputers(d) - 1, dc_num))
+ : DiveComputerBase(d, clone_delete_divecomputer(d, dc_num), std::min((int)number_of_computers(d) - 1, dc_num))
{
setText(Command::Base::tr("delete dive computer"));
}
diff --git a/core/dive.c b/core/dive.c
index 2408ba57c..ae468cf1d 100644
--- a/core/dive.c
+++ b/core/dive.c
@@ -3535,17 +3535,6 @@ struct dive *make_first_dc(const struct dive *d, int dc_number)
return res;
}
-int count_divecomputers(const struct dive *d)
-{
- int ret = 1;
- struct divecomputer *dc = d->dc.next;
- while (dc) {
- ret++;
- dc = dc->next;
- }
- return ret;
-}
-
static void delete_divecomputer(struct dive *d, int num)
{
int i;
@@ -3574,7 +3563,7 @@ static void delete_divecomputer(struct dive *d, int num)
/* If this is the currently displayed dive, we might have to adjust
* the currently displayed dive computer. */
- if (d == current_dive && dc_number >= count_divecomputers(d))
+ if (d == current_dive && dc_number >= number_of_computers(d))
dc_number--;
invalidate_dive_cache(d);
}
diff --git a/core/dive.h b/core/dive.h
index 4f94dba6b..b29cf9857 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -248,7 +248,6 @@ extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
extern timestamp_t dive_endtime(const struct dive *dive);
extern struct dive *make_first_dc(const struct dive *d, int dc_number);
-extern int count_divecomputers(const struct dive *d);
extern struct dive *clone_delete_divecomputer(const struct dive *d, int dc_number);
void split_divecomputer(const struct dive *src, int num, struct dive **out1, struct dive **out2);
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp
index 01870406b..3373b96cd 100644
--- a/profile-widget/profilewidget2.cpp
+++ b/profile-widget/profilewidget2.cpp
@@ -1436,13 +1436,13 @@ void ProfileWidget2::contextMenuEvent(QContextMenuEvent *event)
parentItem = parentItem->parentItem();
}
if (isDCName) {
- if (dc_number == 0 && count_divecomputers(current_dive) == 1)
+ if (dc_number == 0 && number_of_computers(current_dive) == 1)
// nothing to do, can't delete or reorder
return;
// create menu to show when right clicking on dive computer name
if (dc_number > 0)
m.addAction(tr("Make first dive computer"), this, &ProfileWidget2::makeFirstDC);
- if (count_divecomputers(current_dive) > 1) {
+ if (number_of_computers(current_dive) > 1) {
m.addAction(tr("Delete this dive computer"), this, &ProfileWidget2::deleteCurrentDC);
m.addAction(tr("Split this dive computer into own dive"), this, &ProfileWidget2::splitCurrentDC);
}