summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Berthold Stoeger <bstoeger@mail.tuwien.ac.at>2018-11-11 13:09:51 +0100
committerGravatar Dirk Hohndel <dirk@hohndel.org>2018-11-18 16:50:09 -0800
commit64e6e435f82801f4f440ef5b1caf58a91a7c9929 (patch)
tree0f2c662daab035463de05c1564af7026c7edbd7e
parent431b2bb84542d4f45952b48aa91231f979762e00 (diff)
downloadsubsurface-64e6e435f82801f4f440ef5b1caf58a91a7c9929.tar.gz
Core: remove "when" field of struct dive_trip
The when field gives the time of the first dive. Instead of keeping this field in sync, replace it by a function that determines the time of the first dive. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
-rw-r--r--core/dive.h2
-rw-r--r--core/divelist.c17
-rw-r--r--core/divelist.h1
-rw-r--r--core/load-git.c24
-rw-r--r--core/parse-xml.c4
-rw-r--r--core/save-git.c2
-rw-r--r--core/save-xml.c2
-rw-r--r--core/subsurface-qt/DiveObjectHelper.cpp2
-rw-r--r--desktop-widgets/tab-widgets/maintab.cpp4
-rw-r--r--qt-models/divetripmodel.cpp15
-rw-r--r--qt-models/divetripmodel.h2
11 files changed, 23 insertions, 52 deletions
diff --git a/core/dive.h b/core/dive.h
index 76f01a8c0..18c40c6cf 100644
--- a/core/dive.h
+++ b/core/dive.h
@@ -293,7 +293,6 @@ struct dive_table {
typedef struct dive_trip
{
- timestamp_t when;
char *location;
char *notes;
struct dive_table dives;
@@ -432,6 +431,7 @@ extern void delete_single_dive(int idx);
extern void insert_trip(dive_trip_t *trip);
extern void unregister_trip(dive_trip_t *trip);
extern void free_trip(dive_trip_t *trip);
+extern timestamp_t trip_date(const struct dive_trip *trip);
extern const struct units SI_units, IMPERIAL_units;
diff --git a/core/divelist.c b/core/divelist.c
index 0fea7594e..7f946b039 100644
--- a/core/divelist.c
+++ b/core/divelist.c
@@ -739,7 +739,7 @@ void dump_trip_list(void)
for (trip = dive_trip_list; trip; trip = trip->next) {
struct tm tm;
- utc_mkdate(trip->when, &tm);
+ utc_mkdate(trip_date(trip), &tm);
if (trip->when < last_time)
printf("\n\ndive_trip_list OUT OF ORDER!!!\n\n\n");
printf("%s trip %d to \"%s\" on %04u-%02u-%02u %02u:%02u:%02u (%d dives - %p)\n",
@@ -805,9 +805,12 @@ static void delete_trip(dive_trip_t *trip)
free_trip(trip);
}
-void find_new_trip_start_time(dive_trip_t *trip)
+
+timestamp_t trip_date(const struct dive_trip *trip)
{
- trip->when = trip->dives.nr > 0 ? trip->dives.dives[0]->when : 0;
+ if (!trip || trip->dives.nr == 0)
+ return 0;
+ return trip->dives.dives[0]->when;
}
/* check if we have a trip right before / after this dive */
@@ -876,8 +879,6 @@ struct dive_trip *unregister_dive_from_trip(struct dive *dive, short was_autogen
dive->tripflag = TF_NONE;
else
dive->tripflag = NO_TRIP;
- if (trip->dives.nr > 0 && trip->when == dive->when)
- find_new_trip_start_time(trip);
return trip;
}
@@ -908,7 +909,6 @@ dive_trip_t *create_trip_from_dive(struct dive *dive)
dive_trip_t *trip;
trip = alloc_trip();
- trip->when = dive->when;
trip->location = copy_string(get_dive_location(dive));
return trip;
@@ -1345,7 +1345,6 @@ dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *tr
dive_trip_t *trip;
trip = alloc_trip();
- trip->when = trip_a->when;
trip->location = copy_non_empty_string(trip_a->location, trip_b->location);
trip->notes = copy_non_empty_string(trip_a->notes, trip_b->notes);
@@ -1726,9 +1725,9 @@ static int comp_dives(const struct dive *a, const struct dive *b)
return -1;
if (!a->divetrip)
return 1;
- if (a->divetrip->when < b->divetrip->when)
+ if (trip_date(a->divetrip) < trip_date(b->divetrip))
return -1;
- if (a->divetrip->when > b->divetrip->when)
+ if (trip_date(a->divetrip) > trip_date(b->divetrip))
return 1;
}
if (a->id < b->id)
diff --git a/core/divelist.h b/core/divelist.h
index f98587cff..26218af05 100644
--- a/core/divelist.h
+++ b/core/divelist.h
@@ -46,7 +46,6 @@ extern void deselect_dives_in_trip(struct dive_trip *trip);
extern void filter_dive(struct dive *d, bool shown);
extern void combine_trips(struct dive_trip *trip_a, struct dive_trip *trip_b);
extern dive_trip_t *combine_trips_create(struct dive_trip *trip_a, struct dive_trip *trip_b);
-extern void find_new_trip_start_time(dive_trip_t *trip);
extern struct dive *first_selected_dive();
extern struct dive *last_selected_dive();
extern bool is_trip_before_after(const struct dive *dive, bool before);
diff --git a/core/load-git.c b/core/load-git.c
index 8e3254abd..1447becb2 100644
--- a/core/load-git.c
+++ b/core/load-git.c
@@ -799,12 +799,6 @@ static void parse_dc_event(char *line, struct membuffer *str, void *_dc)
}
}
-static void parse_trip_date(char *line, struct membuffer *str, void *_trip)
-{ UNUSED(str); dive_trip_t *trip = _trip; update_date(&trip->when, line); }
-
-static void parse_trip_time(char *line, struct membuffer *str, void *_trip)
-{ UNUSED(str); dive_trip_t *trip = _trip; update_time(&trip->when, line); }
-
static void parse_trip_location(char *line, struct membuffer *str, void *_trip)
{ UNUSED(line); dive_trip_t *trip = _trip; trip->location = get_utf8(str); }
@@ -1007,7 +1001,7 @@ static void site_parser(char *line, struct membuffer *str, void *_ds)
struct keyword_action trip_action[] = {
#undef D
#define D(x) { #x, parse_trip_ ## x }
- D(date), D(location), D(notes), D(time),
+ D(location), D(notes),
};
static void trip_parser(char *line, struct membuffer *str, void *_trip)
@@ -1202,20 +1196,6 @@ static struct dive *create_new_dive(timestamp_t when)
return dive;
}
-static dive_trip_t *create_new_trip(int yyyy, int mm, int dd)
-{
- dive_trip_t *trip = alloc_trip();
- struct tm tm = { 0 };
-
- /* We'll fill in the real data from the trip descriptor file */
- tm.tm_year = yyyy;
- tm.tm_mon = mm-1;
- tm.tm_mday = dd;
- trip->when = utc_mktime(&tm);
-
- return trip;
-}
-
static bool validate_date(int yyyy, int mm, int dd)
{
return yyyy > 1930 && yyyy < 3000 &&
@@ -1243,7 +1223,7 @@ static int dive_trip_directory(const char *root, const char *name)
if (!validate_date(yyyy, mm, dd))
return GIT_WALK_SKIP;
finish_active_trip();
- active_trip = create_new_trip(yyyy, mm, dd);
+ active_trip = alloc_trip();
return GIT_WALK_OK;
}
diff --git a/core/parse-xml.c b/core/parse-xml.c
index 5f70fdc52..d9185cd32 100644
--- a/core/parse-xml.c
+++ b/core/parse-xml.c
@@ -1352,10 +1352,6 @@ static void try_to_fill_trip(dive_trip_t **dive_trip_p, const char *name, char *
dive_trip_t *dive_trip = *dive_trip_p;
- if (MATCH_STATE("date", divedate, &dive_trip->when))
- return;
- if (MATCH_STATE("time", divetime, &dive_trip->when))
- return;
if (MATCH("location", utf8_string, &dive_trip->location))
return;
if (MATCH("notes", utf8_string, &dive_trip->notes))
diff --git a/core/save-git.c b/core/save-git.c
index 422201324..c53c2bb97 100644
--- a/core/save-git.c
+++ b/core/save-git.c
@@ -956,7 +956,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
}
/* Create the date-based hierarchy */
- utc_mkdate(trip ? trip->when : dive->when, &tm);
+ utc_mkdate(trip ? trip_date(trip) : dive->when, &tm);
tree = mktree(repo, root, "%04d", tm.tm_year);
tree = mktree(repo, tree, "%02d", tm.tm_mon + 1);
diff --git a/core/save-xml.c b/core/save-xml.c
index 4a85053ab..4abb3cc12 100644
--- a/core/save-xml.c
+++ b/core/save-xml.c
@@ -520,7 +520,7 @@ static void save_trip(struct membuffer *b, dive_trip_t *trip, bool anonymize)
struct dive *dive;
put_format(b, "<trip");
- show_date(b, trip->when);
+ show_date(b, trip_date(trip));
show_utf8(b, trip->location, " location=\'", "\'", 1);
put_format(b, ">\n");
show_utf8(b, trip->notes, "<notes>", "</notes>\n", 0);
diff --git a/core/subsurface-qt/DiveObjectHelper.cpp b/core/subsurface-qt/DiveObjectHelper.cpp
index b254ed13f..3a9216d63 100644
--- a/core/subsurface-qt/DiveObjectHelper.cpp
+++ b/core/subsurface-qt/DiveObjectHelper.cpp
@@ -343,7 +343,7 @@ QString DiveObjectHelper::tripMeta() const
if (dt) {
QString numDives = tr("(%n dive(s))", "", dt->showndives);
QString title(dt->location);
- QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*dt->when, Qt::UTC);
+ QDateTime firstTime = QDateTime::fromMSecsSinceEpoch(1000*trip_date(dt), Qt::UTC);
QString firstMonth = firstTime.toString("MMM");
QString tripDate = QStringLiteral("%1@%2").arg(firstMonth,firstTime.toString("yy"));
diff --git a/desktop-widgets/tab-widgets/maintab.cpp b/desktop-widgets/tab-widgets/maintab.cpp
index b61c9ab78..567e1737f 100644
--- a/desktop-widgets/tab-widgets/maintab.cpp
+++ b/desktop-widgets/tab-widgets/maintab.cpp
@@ -909,10 +909,6 @@ void MainTab::acceptChanges()
Command::shiftTime(selectedDives, (int)offset);
}
}
- if (editMode != TRIP && current_dive->divetrip) {
- current_dive->divetrip->when = current_dive->when;
- find_new_trip_start_time(current_dive->divetrip);
- }
if (editMode == MANUALLY_ADDED_DIVE) {
// we just added or edited the dive, let fixup_dive() make
// sure we get the max. depth right
diff --git a/qt-models/divetripmodel.cpp b/qt-models/divetripmodel.cpp
index c6b4ae228..c83a14e7b 100644
--- a/qt-models/divetripmodel.cpp
+++ b/qt-models/divetripmodel.cpp
@@ -62,14 +62,14 @@ QVariant DiveTripModel::tripData(const dive_trip *trip, int column, int role)
struct dive *d = trip->dives.dives[i];
if (!d->hidden_by_filter)
countShown++;
- oneDayTrip &= is_same_day (trip->when, d->when);
+ oneDayTrip &= is_same_day(trip_date(trip), d->when);
}
if (countShown < trip->dives.nr)
shownText = tr("(%1 shown)").arg(countShown);
if (!empty_string(trip->location))
- return QString(trip->location) + ", " + get_trip_date_string(trip->when, trip->dives.nr, oneDayTrip) + " "+ shownText;
+ return QString(trip->location) + ", " + get_trip_date_string(trip_date(trip), trip->dives.nr, oneDayTrip) + " "+ shownText;
else
- return get_trip_date_string(trip->when, trip->dives.nr, oneDayTrip) + shownText;
+ return get_trip_date_string(trip_date(trip), trip->dives.nr, oneDayTrip) + shownText;
}
}
@@ -463,7 +463,7 @@ dive *DiveTripModel::Item::getDive() const
timestamp_t DiveTripModel::Item::when() const
{
- return d_or_t.trip ? d_or_t.trip->when : d_or_t.dive->when;
+ return d_or_t.trip ? trip_date(d_or_t.trip) : d_or_t.dive->when;
}
// Find a range of matching elements in a vector.
@@ -678,10 +678,11 @@ int DiveTripModel::findDiveInTrip(int tripIdx, const dive *d) const
return -1;
}
-int DiveTripModel::findInsertionIndex(timestamp_t when) const
+int DiveTripModel::findInsertionIndex(const dive_trip *trip) const
{
+ dive_or_trip d_or_t{ nullptr, (dive_trip *)trip };
for (int i = 0; i < (int)items.size(); ++i) {
- if (when <= items[i].when())
+ if (dive_or_trip_less_than(d_or_t, items[i].d_or_t))
return i;
}
return items.size();
@@ -765,7 +766,7 @@ void DiveTripModel::divesAdded(dive_trip *trip, bool addTrip, const QVector<dive
});
} else if (addTrip) {
// We're supposed to add the whole trip. Just insert the trip.
- int idx = findInsertionIndex(trip->when); // Find the place where we have to insert the thing
+ int idx = findInsertionIndex(trip); // Find the place where to insert the trip
beginInsertRows(QModelIndex(), idx, idx);
items.insert(items.begin() + idx, { trip, dives });
endInsertRows();
diff --git a/qt-models/divetripmodel.h b/qt-models/divetripmodel.h
index 8ff4524b3..6d34d30bb 100644
--- a/qt-models/divetripmodel.h
+++ b/qt-models/divetripmodel.h
@@ -104,7 +104,7 @@ private:
int findTripIdx(const dive_trip *trip) const;
int findDiveIdx(const dive *d) const; // Find _top_level_ dive
int findDiveInTrip(int tripIdx, const dive *d) const; // Find dive inside trip. Second parameter is index of trip
- int findInsertionIndex(timestamp_t when) const; // Where to insert item with timestamp "when"
+ int findInsertionIndex(const dive_trip *trip) const; // Where to insert trip
// Access trip and dive data
static QVariant diveData(const struct dive *d, int column, int role);