mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Core: turn add_single_dive() to append_dive()
The only external caller of add_single_dive() used it to append a dive to the global dive list. Rename the function accordingly and remove the index parameter. The internal caller can use the local insert_dive() function, which doesn't consider selection. That shouldn't be a problem, as the caller is doing import. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
5729f93e1f
commit
88dc32fdfc
3 changed files with 15 additions and 20 deletions
|
@ -845,6 +845,12 @@ MAKE_SORT(trip_table, struct dive_trip *, trips, comp_trips)
|
|||
MAKE_REMOVE(dive_table, struct dive *, dive)
|
||||
MAKE_REMOVE(trip_table, struct dive_trip *, trip)
|
||||
|
||||
static void insert_dive(struct dive_table *table, struct dive *d)
|
||||
{
|
||||
int idx = dive_table_get_insertion_index(table, d);
|
||||
add_to_dive_table(table, idx, d);
|
||||
}
|
||||
|
||||
/* remove a dive from the trip it's associated to, but don't delete the
|
||||
* trip if this was the last dive in the trip. the caller is responsible
|
||||
* for removing the trip, if the trip->dives.nr went to 0.
|
||||
|
@ -878,13 +884,11 @@ void remove_dive_from_trip(struct dive *dive, struct trip_table *trip_table_arg)
|
|||
* from trip beforehand. */
|
||||
void add_dive_to_trip(struct dive *dive, dive_trip_t *trip)
|
||||
{
|
||||
int idx;
|
||||
if (dive->divetrip == trip)
|
||||
return;
|
||||
if (dive->divetrip)
|
||||
fprintf(stderr, "Warning: adding dive to trip that has trip set\n");
|
||||
idx = dive_table_get_insertion_index(&trip->dives, dive);
|
||||
add_to_dive_table(&trip->dives, idx, dive);
|
||||
insert_dive(&trip->dives, dive);
|
||||
dive->divetrip = trip;
|
||||
}
|
||||
|
||||
|
@ -1085,12 +1089,11 @@ void delete_single_dive(int idx)
|
|||
delete_dive_from_table(&dive_table, idx);
|
||||
}
|
||||
|
||||
/* add a dive at the given index in the global dive table and keep track
|
||||
* of the number of selected dives. if the index is negative, the dive will
|
||||
* be added according to dive_less_than() order */
|
||||
void add_single_dive(int idx, struct dive *dive)
|
||||
/* add a dive at the end of the global dive table and keep track
|
||||
* of the number of selected dives. */
|
||||
void append_dive(struct dive *dive)
|
||||
{
|
||||
add_to_dive_table(&dive_table, idx, dive);
|
||||
add_to_dive_table(&dive_table, dive_table.nr, dive);
|
||||
if (dive->selected)
|
||||
amount_selected++;
|
||||
}
|
||||
|
@ -1279,12 +1282,6 @@ static void merge_imported_dives(struct dive_table *table)
|
|||
}
|
||||
}
|
||||
|
||||
static void insert_dive(struct dive_table *table, struct dive *d)
|
||||
{
|
||||
int idx = dive_table_get_insertion_index(table, d);
|
||||
add_to_dive_table(table, idx, d);
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear a dive_table, trip_table and dive_site_table. Think about generating these with macros.
|
||||
*/
|
||||
|
@ -1471,10 +1468,8 @@ void add_imported_dives(struct dive_table *import_table, struct trip_table *impo
|
|||
dives_to_remove.nr = 0;
|
||||
|
||||
/* Add new dives */
|
||||
for (i = 0; i < dives_to_add.nr; i++) {
|
||||
idx = dive_table_get_insertion_index(&dive_table, dives_to_add.dives[i]);
|
||||
add_single_dive(idx, dives_to_add.dives[i]);
|
||||
}
|
||||
for (i = 0; i < dives_to_add.nr; i++)
|
||||
insert_dive(&dive_table, dives_to_add.dives[i]);
|
||||
dives_to_add.nr = 0;
|
||||
|
||||
/* Add new trips */
|
||||
|
|
|
@ -34,7 +34,7 @@ extern char *get_dive_gas_string(const struct dive *dive);
|
|||
extern struct dive **grow_dive_table(struct dive_table *table);
|
||||
extern int dive_table_get_insertion_index(struct dive_table *table, struct dive *dive);
|
||||
extern void add_to_dive_table(struct dive_table *table, int idx, struct dive *dive);
|
||||
extern void add_single_dive(int idx, struct dive *dive);
|
||||
extern void append_dive(struct dive *dive);
|
||||
extern void get_dive_gas(const struct dive *dive, int *o2_p, int *he_p, int *o2low_p);
|
||||
extern int get_divenr(const struct dive *dive);
|
||||
extern struct dive_trip *unregister_dive_from_trip(struct dive *dive);
|
||||
|
|
|
@ -278,7 +278,7 @@ QString DiveListModel::startAddDive()
|
|||
nr++;
|
||||
d->number = nr;
|
||||
d->dc.model = strdup("manually added dive");
|
||||
add_single_dive(dive_table.nr, d);
|
||||
append_dive(d);
|
||||
insertDive(get_idx_by_uniq_id(d->id), new DiveObjectHelper(d));
|
||||
return QString::number(d->id);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue