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:
Berthold Stoeger 2024-06-21 16:43:27 +02:00 committed by bstoeger
parent bdd5527005
commit 4a165980e7
13 changed files with 71 additions and 77 deletions

View file

@ -13,9 +13,9 @@
namespace Command {
// Dive-list related commands
void addDive(dive *d, bool autogroup, bool newNumber)
void addDive(std::unique_ptr<dive> d, bool autogroup, bool newNumber)
{
execute(new AddDive(d, autogroup, newNumber));
execute(new AddDive(std::move(d), autogroup, newNumber));
}
void importDives(struct divelog *log, int flags, const QString &source)