mirror of
https://github.com/subsurface/subsurface.git
synced 2024-12-11 03:21:29 +00:00
core: move clone_delete_divecomputer() to struct dive_table
Since this calls force_fixup_dive() it needs access to other dives in the dive_table. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
576d3a3bc6
commit
79bf79ad7f
5 changed files with 25 additions and 26 deletions
|
@ -905,7 +905,8 @@ MoveDiveComputerToFront::MoveDiveComputerToFront(dive *d, int dc_num)
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteDiveComputer::DeleteDiveComputer(dive *d, int dc_num)
|
DeleteDiveComputer::DeleteDiveComputer(dive *d, int dc_num)
|
||||||
: DiveComputerBase(d, clone_delete_divecomputer(*d, dc_num), dc_num, std::min((int)number_of_computers(d) - 1, dc_num))
|
: DiveComputerBase(d, divelog.dives.clone_delete_divecomputer(*d, dc_num),
|
||||||
|
dc_num, std::min((int)number_of_computers(d) - 1, dc_num))
|
||||||
{
|
{
|
||||||
setText(Command::Base::tr("delete dive computer"));
|
setText(Command::Base::tr("delete dive computer"));
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@
|
||||||
#include "libdivecomputer.h"
|
#include "libdivecomputer.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "divelist.h"
|
#include "divelist.h"
|
||||||
#include "divelog.h"
|
|
||||||
#include "divesite.h"
|
#include "divesite.h"
|
||||||
#include "equipment.h"
|
#include "equipment.h"
|
||||||
#include "errorhelper.h"
|
#include "errorhelper.h"
|
||||||
|
@ -2332,7 +2331,6 @@ void set_informational_units(const char *units)
|
||||||
if (strstr(units, "MINUTES"))
|
if (strstr(units, "MINUTES"))
|
||||||
git_prefs.units.vertical_speed_time = units::MINUTES;
|
git_prefs.units.vertical_speed_time = units::MINUTES;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* clones a dive and moves given dive computer to front */
|
/* clones a dive and moves given dive computer to front */
|
||||||
|
@ -2350,28 +2348,6 @@ std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Clone a dive and delete given dive computer */
|
|
||||||
std::unique_ptr<dive> clone_delete_divecomputer(const struct dive &d, int dc_number)
|
|
||||||
{
|
|
||||||
/* copy the dive */
|
|
||||||
auto res = std::make_unique<dive>(d);
|
|
||||||
|
|
||||||
/* make a new unique id, since we still can't handle two equal ids */
|
|
||||||
res->id = dive_getUniqID();
|
|
||||||
|
|
||||||
if (res->dcs.size() <= 1)
|
|
||||||
return res;
|
|
||||||
|
|
||||||
if (dc_number < 0 || static_cast<size_t>(dc_number) >= res->dcs.size())
|
|
||||||
return res;
|
|
||||||
|
|
||||||
res->dcs.erase(res->dcs.begin() + dc_number);
|
|
||||||
|
|
||||||
divelog.dives.force_fixup_dive(*res);
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Calculate O2 in best mix
|
//Calculate O2 in best mix
|
||||||
fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner)
|
fraction_t best_o2(depth_t depth, const struct dive *dive, bool in_planner)
|
||||||
{
|
{
|
||||||
|
|
|
@ -162,7 +162,6 @@ extern struct divecomputer *get_dive_dc(struct dive *dive, int nr);
|
||||||
extern const struct divecomputer *get_dive_dc(const struct dive *dive, int nr);
|
extern const struct divecomputer *get_dive_dc(const struct dive *dive, int nr);
|
||||||
|
|
||||||
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
extern std::unique_ptr<dive> clone_make_first_dc(const struct dive &d, int dc_number);
|
||||||
extern std::unique_ptr<dive> clone_delete_divecomputer(const struct dive &d, int dc_number);
|
|
||||||
|
|
||||||
extern bool dive_site_has_gps_location(const struct dive_site *ds);
|
extern bool dive_site_has_gps_location(const struct dive_site *ds);
|
||||||
extern int dive_has_gps_location(const struct dive *dive);
|
extern int dive_has_gps_location(const struct dive *dive);
|
||||||
|
|
|
@ -1219,3 +1219,25 @@ struct std::unique_ptr<dive> dive_table::try_to_merge(const struct dive &a, cons
|
||||||
res->dive_site = site; /* Caller has to call site->add_dive()! */
|
res->dive_site = site; /* Caller has to call site->add_dive()! */
|
||||||
return std::move(res);
|
return std::move(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Clone a dive and delete given dive computer */
|
||||||
|
std::unique_ptr<dive> dive_table::clone_delete_divecomputer(const struct dive &d, int dc_number)
|
||||||
|
{
|
||||||
|
/* copy the dive */
|
||||||
|
auto res = std::make_unique<dive>(d);
|
||||||
|
|
||||||
|
/* make a new unique id, since we still can't handle two equal ids */
|
||||||
|
res->id = dive_getUniqID();
|
||||||
|
|
||||||
|
if (res->dcs.size() <= 1)
|
||||||
|
return res;
|
||||||
|
|
||||||
|
if (dc_number < 0 || static_cast<size_t>(dc_number) >= res->dcs.size())
|
||||||
|
return res;
|
||||||
|
|
||||||
|
res->dcs.erase(res->dcs.begin() + dc_number);
|
||||||
|
|
||||||
|
force_fixup_dive(*res);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ struct dive_table : public sorted_owning_table<dive, &comp_dives> {
|
||||||
merge_result merge_dives(const struct dive &a_in, const struct dive &b_in, int offset, bool prefer_downloaded) const;
|
merge_result merge_dives(const struct dive &a_in, const struct dive &b_in, int offset, bool prefer_downloaded) const;
|
||||||
std::unique_ptr<dive> try_to_merge(const struct dive &a, const struct dive &b, bool prefer_downloaded) const;
|
std::unique_ptr<dive> try_to_merge(const struct dive &a, const struct dive &b, bool prefer_downloaded) const;
|
||||||
bool has_dive(unsigned int deviceid, unsigned int diveid) const;
|
bool has_dive(unsigned int deviceid, unsigned int diveid) const;
|
||||||
|
std::unique_ptr<dive> clone_delete_divecomputer(const struct dive &d, int dc_number);
|
||||||
private:
|
private:
|
||||||
int calculate_cns(struct dive &dive) const; // Note: writes into dive->cns
|
int calculate_cns(struct dive &dive) const; // Note: writes into dive->cns
|
||||||
std::array<std::unique_ptr<dive>, 2> split_dive_at(const struct dive &dive, int a, int b) const;
|
std::array<std::unique_ptr<dive>, 2> split_dive_at(const struct dive &dive, int a, int b) const;
|
||||||
|
|
Loading…
Reference in a new issue