mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
core: include trip table directly in divelog
Having this as a pointer is an artifact from the C/C++ split. The triptable header is small enough so that we can include it directly Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
5af9d28291
commit
2bdcdab391
13 changed files with 39 additions and 39 deletions
|
@ -16,7 +16,7 @@ static std::unique_ptr<dive_trip> remove_trip_from_backend(dive_trip *trip)
|
|||
{
|
||||
if (trip->selected)
|
||||
deselect_trip(trip);
|
||||
auto [t, idx] = divelog.trips->pull(trip);
|
||||
auto [t, idx] = divelog.trips.pull(trip);
|
||||
return std::move(t);
|
||||
}
|
||||
|
||||
|
@ -39,7 +39,7 @@ DiveToAdd DiveListBase::removeDive(struct dive *d, std::vector<std::unique_ptr<d
|
|||
diveSiteCountChanged(d->dive_site);
|
||||
res.site = unregister_dive_from_dive_site(d);
|
||||
if (res.trip && res.trip->dives.empty()) {
|
||||
divelog.trips->sort(); // Removal of dives has changed order of trips! (TODO: remove this)
|
||||
divelog.trips.sort(); // Removal of dives has changed order of trips! (TODO: remove this)
|
||||
auto trip = remove_trip_from_backend(res.trip); // Remove trip from backend
|
||||
tripsToAdd.push_back(std::move(trip)); // Take ownership of trip
|
||||
}
|
||||
|
@ -200,7 +200,7 @@ DivesAndSitesToRemove DiveListBase::addDives(DivesAndTripsToAdd &toAdd)
|
|||
std::vector<dive_trip *> addedTrips;
|
||||
addedTrips.reserve(toAdd.trips.size());
|
||||
for (std::unique_ptr<dive_trip> &trip: toAdd.trips) {
|
||||
auto [t, idx] = divelog.trips->put(std::move(trip)); // Return ownership to backend
|
||||
auto [t, idx] = divelog.trips.put(std::move(trip)); // Return ownership to backend
|
||||
addedTrips.push_back(t);
|
||||
}
|
||||
toAdd.trips.clear();
|
||||
|
@ -287,7 +287,7 @@ static void moveDivesBetweenTrips(DivesToTrip &dives)
|
|||
|
||||
// First, bring back the trip(s)
|
||||
for (std::unique_ptr<dive_trip> &trip: dives.tripsToAdd) {
|
||||
auto [t, idx] = divelog.trips->put(std::move(trip)); // Return ownership to backend
|
||||
auto [t, idx] = divelog.trips.put(std::move(trip)); // Return ownership to backend
|
||||
createdTrips.push_back(t);
|
||||
}
|
||||
dives.tripsToAdd.clear();
|
||||
|
@ -438,7 +438,7 @@ void AddDive::redoit()
|
|||
currentDive = current_dive;
|
||||
|
||||
divesAndSitesToRemove = addDives(divesToAdd);
|
||||
divelog.trips->sort(); // Though unlikely, adding a dive may reorder trips
|
||||
divelog.trips.sort(); // Though unlikely, adding a dive may reorder trips
|
||||
|
||||
// Select the newly added dive
|
||||
setSelection(divesAndSitesToRemove.dives, divesAndSitesToRemove.dives[0], -1);
|
||||
|
@ -448,7 +448,7 @@ void AddDive::undoit()
|
|||
{
|
||||
// Simply remove the dive that was previously added...
|
||||
divesToAdd = removeDives(divesAndSitesToRemove);
|
||||
divelog.trips->sort(); // Though unlikely, removing a dive may reorder trips
|
||||
divelog.trips.sort(); // Though unlikely, removing a dive may reorder trips
|
||||
|
||||
// ...and restore the selection
|
||||
setSelection(selection, currentDive, -1);
|
||||
|
@ -583,7 +583,7 @@ bool DeleteDive::workToBeDone()
|
|||
void DeleteDive::undoit()
|
||||
{
|
||||
divesToDelete = addDives(divesToAdd);
|
||||
divelog.trips->sort(); // Though unlikely, removing a dive may reorder trips
|
||||
divelog.trips.sort(); // Though unlikely, removing a dive may reorder trips
|
||||
|
||||
// Select all re-added dives and make the first one current
|
||||
dive *currentDive = !divesToDelete.dives.empty() ? divesToDelete.dives[0] : nullptr;
|
||||
|
@ -593,7 +593,7 @@ void DeleteDive::undoit()
|
|||
void DeleteDive::redoit()
|
||||
{
|
||||
divesToAdd = removeDives(divesToDelete);
|
||||
divelog.trips->sort(); // Though unlikely, adding a dive may reorder trips
|
||||
divelog.trips.sort(); // Though unlikely, adding a dive may reorder trips
|
||||
|
||||
// Deselect all dives and select dive that was close to the first deleted dive
|
||||
dive *newCurrent = nullptr;
|
||||
|
@ -622,7 +622,7 @@ void ShiftTime::redoit()
|
|||
|
||||
// Changing times may have unsorted the dive and trip tables
|
||||
divelog.dives.sort();
|
||||
divelog.trips->sort();
|
||||
divelog.trips.sort();
|
||||
for (dive_trip *trip: trips)
|
||||
trip->sort_dives();
|
||||
|
||||
|
@ -690,7 +690,7 @@ bool TripBase::workToBeDone()
|
|||
void TripBase::redoit()
|
||||
{
|
||||
moveDivesBetweenTrips(divesToMove);
|
||||
divelog.trips->sort(); // Though unlikely, moving dives may reorder trips
|
||||
divelog.trips.sort(); // Though unlikely, moving dives may reorder trips
|
||||
|
||||
// Select the moved dives
|
||||
std::vector<dive *> dives;
|
||||
|
|
|
@ -1442,7 +1442,7 @@ void EditDive::exchangeDives()
|
|||
timestamp_t delta = oldDive->when - newDive->when;
|
||||
if (delta != 0) {
|
||||
divelog.dives.sort();
|
||||
divelog.trips->sort();
|
||||
divelog.trips.sort();
|
||||
if (newDive->divetrip != oldDive->divetrip)
|
||||
qWarning("Command::EditDive::redo(): This command does not support moving between trips!");
|
||||
if (oldDive->divetrip)
|
||||
|
|
|
@ -727,10 +727,10 @@ struct dive *register_dive(std::unique_ptr<dive> d)
|
|||
void process_loaded_dives()
|
||||
{
|
||||
divelog.dives.sort();
|
||||
divelog.trips->sort();
|
||||
divelog.trips.sort();
|
||||
|
||||
/* Autogroup dives if desired by user. */
|
||||
autogroup_dives(divelog.dives, *divelog.trips);
|
||||
autogroup_dives(divelog.dives, divelog.trips);
|
||||
|
||||
fulltext_populate();
|
||||
|
||||
|
@ -926,7 +926,7 @@ void add_imported_dives(struct divelog &import_log, int flags)
|
|||
|
||||
/* Add new trips */
|
||||
for (auto &trip: trips_to_add)
|
||||
divelog.trips->put(std::move(trip));
|
||||
divelog.trips.put(std::move(trip));
|
||||
trips_to_add.clear();
|
||||
|
||||
/* Add new dive sites */
|
||||
|
@ -960,7 +960,7 @@ static bool try_to_merge_trip(dive_trip &trip_import, struct dive_table &import_
|
|||
struct dive_table &dives_to_add, std::vector<dive *> &dives_to_remove,
|
||||
bool &sequence_changed, int &start_renumbering_at)
|
||||
{
|
||||
for (auto &trip_old: *divelog.trips) {
|
||||
for (auto &trip_old: divelog.trips) {
|
||||
if (trips_overlap(trip_import, *trip_old)) {
|
||||
sequence_changed |= merge_dive_tables(trip_import.dives, import_table, trip_old->dives,
|
||||
prefer_imported, trip_old.get(),
|
||||
|
@ -1044,7 +1044,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
|
|||
/* Autogroup tripless dives if desired by user. But don't autogroup
|
||||
* if tripless dives should be added to a new trip. */
|
||||
if (!(flags & IMPORT_ADD_TO_NEW_TRIP))
|
||||
autogroup_dives(import_log.dives, *import_log.trips);
|
||||
autogroup_dives(import_log.dives, import_log.trips);
|
||||
|
||||
/* If dive sites already exist, use the existing versions. */
|
||||
for (auto &new_ds: import_log.sites) {
|
||||
|
@ -1072,7 +1072,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
|
|||
* could be smarter here, but realistically not a whole lot of trips
|
||||
* will be imported so do a simple n*m loop until someone complains.
|
||||
*/
|
||||
for (auto &trip_import: *import_log.trips) {
|
||||
for (auto &trip_import: import_log.trips) {
|
||||
if ((flags & IMPORT_MERGE_ALL_TRIPS) || trip_import->autogen) {
|
||||
if (try_to_merge_trip(*trip_import, import_log.dives, flags & IMPORT_PREFER_IMPORTED,
|
||||
res.dives_to_add, res.dives_to_remove,
|
||||
|
@ -1096,7 +1096,7 @@ process_imported_dives_result process_imported_dives(struct divelog &import_log,
|
|||
/* Finally, add trip to list of trips to add */
|
||||
res.trips_to_add.put(std::move(trip_import));
|
||||
}
|
||||
import_log.trips->clear(); /* All trips were consumed */
|
||||
import_log.trips.clear(); /* All trips were consumed */
|
||||
|
||||
if ((flags & IMPORT_ADD_TO_NEW_TRIP) && !import_log.dives.empty()) {
|
||||
/* Create a new trip for unassigned dives, if desired. */
|
||||
|
|
|
@ -11,7 +11,6 @@
|
|||
struct divelog divelog;
|
||||
|
||||
divelog::divelog() :
|
||||
trips(std::make_unique<trip_table>()),
|
||||
filter_presets(std::make_unique<filter_preset_table>()),
|
||||
autogroup(false)
|
||||
{
|
||||
|
@ -34,10 +33,10 @@ void divelog::delete_single_dive(int idx)
|
|||
|
||||
// Deleting a dive may change the order of trips!
|
||||
if (trip)
|
||||
trips->sort();
|
||||
trips.sort();
|
||||
|
||||
if (trip && trip->dives.empty())
|
||||
trips->pull(trip);
|
||||
trips.pull(trip);
|
||||
unregister_dive_from_dive_site(dive);
|
||||
dives.erase(dives.begin() + idx);
|
||||
}
|
||||
|
@ -51,7 +50,7 @@ void divelog::delete_multiple_dives(const std::vector<dive *> &dives_to_delete)
|
|||
struct dive_trip *trip = unregister_dive_from_trip(d);
|
||||
if (trip && trip->dives.empty()) {
|
||||
trips_changed = true;
|
||||
trips->pull(trip);
|
||||
trips.pull(trip);
|
||||
}
|
||||
|
||||
unregister_dive_from_dive_site(d);
|
||||
|
@ -60,14 +59,14 @@ void divelog::delete_multiple_dives(const std::vector<dive *> &dives_to_delete)
|
|||
|
||||
// Deleting a dive may change the order of trips!
|
||||
if (trips_changed)
|
||||
trips->sort();
|
||||
trips.sort();
|
||||
}
|
||||
|
||||
void divelog::clear()
|
||||
{
|
||||
dives.clear();
|
||||
sites.clear();
|
||||
trips->clear();
|
||||
trips.clear();
|
||||
devices.clear();
|
||||
filter_presets->clear();
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "divelist.h"
|
||||
#include "divesitetable.h"
|
||||
#include "triptable.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -15,7 +16,7 @@ struct filter_preset_table;
|
|||
|
||||
struct divelog {
|
||||
dive_table dives;
|
||||
std::unique_ptr<trip_table> trips;
|
||||
trip_table trips;
|
||||
dive_site_table sites;
|
||||
std::vector<device> devices;
|
||||
std::unique_ptr<filter_preset_table> filter_presets;
|
||||
|
|
|
@ -1384,7 +1384,7 @@ static void finish_active_trip(struct git_parser_state *state)
|
|||
auto &trip = state->active_trip;
|
||||
|
||||
if (trip)
|
||||
state->log->trips->put(std::move(trip));
|
||||
state->log->trips.put(std::move(trip));
|
||||
}
|
||||
|
||||
static void finish_active_dive(struct git_parser_state *state)
|
||||
|
|
|
@ -288,7 +288,7 @@ void trip_end(struct parser_state *state)
|
|||
{
|
||||
if (!state->cur_trip)
|
||||
return;
|
||||
state->log->trips->put(std::move(state->cur_trip));
|
||||
state->log->trips.put(std::move(state->cur_trip));
|
||||
}
|
||||
|
||||
void picture_start(struct parser_state *state)
|
||||
|
|
|
@ -985,7 +985,7 @@ static int create_git_tree(git_repository *repo, struct dir *root, bool select_o
|
|||
save_divesites(repo, root);
|
||||
save_filter_presets(repo, root);
|
||||
|
||||
for (auto &trip: *divelog.trips)
|
||||
for (auto &trip: divelog.trips)
|
||||
trip->saved = false;
|
||||
|
||||
/* save the dives */
|
||||
|
|
|
@ -436,7 +436,7 @@ static void write_trips(struct membuffer *b, const char *photos_dir, bool select
|
|||
char sep_ = ' ';
|
||||
char *sep = &sep_;
|
||||
|
||||
for (auto &trip: *divelog.trips)
|
||||
for (auto &trip: divelog.trips)
|
||||
trip->saved = 0;
|
||||
|
||||
for (auto &dive: divelog.dives) {
|
||||
|
|
|
@ -678,7 +678,7 @@ static void save_dives_buffer(struct membuffer *b, bool select_only, bool anonym
|
|||
put_format(b, "</site>\n");
|
||||
}
|
||||
put_format(b, "</divesites>\n<dives>\n");
|
||||
for (auto &trip: *divelog.trips)
|
||||
for (auto &trip: divelog.trips)
|
||||
trip->saved = 0;
|
||||
|
||||
/* save the filter presets */
|
||||
|
|
|
@ -156,7 +156,7 @@ QVector<dive *> setSelectionCore(const std::vector<dive *> &selection, dive *cur
|
|||
static void clear_trip_selection()
|
||||
{
|
||||
amount_trips_selected = 0;
|
||||
for (auto &trip: *divelog.trips)
|
||||
for (auto &trip: divelog.trips)
|
||||
trip->selected = false;
|
||||
}
|
||||
|
||||
|
@ -202,7 +202,7 @@ void setTripSelection(dive_trip *trip, dive *currentDive)
|
|||
current_dive = currentDive;
|
||||
for (auto &d: divelog.dives)
|
||||
d->selected = d->divetrip == trip;
|
||||
for (auto &t: *divelog.trips)
|
||||
for (auto &t: divelog.trips)
|
||||
t->selected = t.get() == trip;
|
||||
|
||||
amount_selected = static_cast<int>(trip->dives.size());
|
||||
|
@ -291,7 +291,7 @@ struct dive_trip *single_selected_trip()
|
|||
{
|
||||
if (amount_trips_selected != 1)
|
||||
return NULL;
|
||||
for (auto &trip: *divelog.trips) {
|
||||
for (auto &trip: divelog.trips) {
|
||||
if (trip->selected)
|
||||
return trip.get();
|
||||
}
|
||||
|
|
|
@ -18,8 +18,8 @@ TripSelectionDialog::TripSelectionDialog(QWidget *parent) : QDialog(parent)
|
|||
|
||||
// We could use a model, but it seems barely worth the hassle.
|
||||
QStringList list;
|
||||
list.reserve(divelog.trips->size());
|
||||
for (auto &trip: *divelog.trips)
|
||||
list.reserve(divelog.trips.size());
|
||||
for (auto &trip: divelog.trips)
|
||||
list.push_back(formatTripTitleWithDives(*trip));
|
||||
ui.trips->addItems(list);
|
||||
}
|
||||
|
@ -37,9 +37,9 @@ dive_trip *TripSelectionDialog::selectedTrip() const
|
|||
if (rows.size() != 1)
|
||||
return nullptr;
|
||||
int idx = rows[0].row();
|
||||
if (idx < 0 || static_cast<size_t>(idx) >= divelog.trips->size())
|
||||
if (idx < 0 || static_cast<size_t>(idx) >= divelog.trips.size())
|
||||
return nullptr;
|
||||
return (*divelog.trips)[idx].get();
|
||||
return divelog.trips[idx].get();
|
||||
}
|
||||
|
||||
dive_trip *TripSelectionDialog::getTrip()
|
||||
|
|
|
@ -1369,7 +1369,7 @@ void QMLManager::commitChanges(QString diveId, QString number, QString date, QSt
|
|||
void QMLManager::updateTripDetails(QString tripIdString, QString tripLocation, QString tripNotes)
|
||||
{
|
||||
int tripId = tripIdString.toInt();
|
||||
dive_trip *trip = divelog.trips->get_by_uniq_id(tripId);
|
||||
dive_trip *trip = divelog.trips.get_by_uniq_id(tripId);
|
||||
if (!trip) {
|
||||
report_info("updateTripData: cannot find trip for tripId %s", qPrintable(tripIdString));
|
||||
return;
|
||||
|
@ -1428,7 +1428,7 @@ void QMLManager::addDiveToTrip(int id, int tripId)
|
|||
appendTextToLog(QString("Asked to add non-existing dive with id %1 to trip %2.").arg(id).arg(tripId));
|
||||
return;
|
||||
}
|
||||
struct dive_trip *dt = divelog.trips->get_by_uniq_id(tripId);
|
||||
struct dive_trip *dt = divelog.trips.get_by_uniq_id(tripId);
|
||||
if (!dt) {
|
||||
appendTextToLog(QString("Asked to add dive with id %1 to trip with id %2 which cannot be found.").arg(id).arg(tripId));
|
||||
return;
|
||||
|
|
Loading…
Add table
Reference in a new issue