summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--core/divelist.c31
-rw-r--r--core/divelist.h2
-rw-r--r--qt-models/divelistmodel.cpp2
3 files changed, 15 insertions, 20 deletions
diff --git a/core/divelist.c b/core/divelist.c
index be0d95852..010ef244a 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -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 */
diff --git a/core/divelist.h b/core/divelist.h
index c09b8651a..ae71040c4 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -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);
diff --git a/qt-models/divelistmodel.cpp b/qt-models/divelistmodel.cpp
index 4d66c5406..b13c1fcc3 100644
--- a/qt-models/divelistmodel.cpp
+++ b/qt-models/divelistmodel.cpp
@@ -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);
}