mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
undo: pass dive as unique_ptr to addDive()
Before, a non-owning pointer was passed and the dive moved away from the dive. Instead, let the caller decide if they still want to keep a copy of the dive, or give up ownership: In MainWindow and QMLManager new dives are generated, so one might just as well give up ownership. In contrast, the planner works on a copy (originally the infamous "displayed_dive") and now moves the data manually. This commit also removes duplicate code, by moving the "create default dive" code from MainWindow and QMLManager to struct dive. Finally, determination of the "time zone offset" is not done in POSIX, since we want to avoid calls form the core into Qt. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
bdd5527005
commit
4a165980e7
13 changed files with 71 additions and 77 deletions
|
@ -1715,23 +1715,11 @@ void QMLManager::cancelDownloadDC()
|
|||
|
||||
int QMLManager::addDive()
|
||||
{
|
||||
// TODO: Duplicate code with desktop-widgets/mainwindow.cpp
|
||||
// create a dive an hour from now with a default depth (15m/45ft) and duration (40 minutes)
|
||||
// as a starting point for the user to edit
|
||||
struct dive d;
|
||||
int diveId = d.id = dive_getUniqID();
|
||||
d.when = QDateTime::currentMSecsSinceEpoch() / 1000L + gettimezoneoffset() + 3600;
|
||||
d.dcs[0].duration.seconds = 40 * 60;
|
||||
d.dcs[0].maxdepth.mm = M_OR_FT(15, 45);
|
||||
d.dcs[0].meandepth.mm = M_OR_FT(13, 39); // this creates a resonable looking safety stop
|
||||
make_manually_added_dive_dc(&d.dcs[0]);
|
||||
fake_dc(&d.dcs[0]);
|
||||
fixup_dive(&d);
|
||||
|
||||
// addDive takes over the dive and clears out the structure passed in
|
||||
// we do NOT save the modified data at this stage because of the UI flow here... this will
|
||||
// be saved once the user finishes editing the newly added dive
|
||||
Command::addDive(&d, divelog.autogroup, true);
|
||||
auto d = dive::default_dive();
|
||||
int diveId = d->id;
|
||||
Command::addDive(std::move(d), divelog.autogroup, true);
|
||||
|
||||
if (verbose)
|
||||
appendTextToLog(QString("Adding new dive with id '%1'").arg(diveId));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue