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

@ -225,3 +225,18 @@ const char *monthname(int mon)
};
return translate("gettextFromC", month_array[mon]);
}
int gettimezoneoffset()
{
time_t now = time(nullptr);
#ifdef WIN32
// Somewhat surprisingly, Windows doesn't have localtime_r (I thought this was POSIX?).
// Let's use the global timezone variable.
// Ultimately, use the portable C++20 API.
return static_cast<int>(-timezone);
#else
struct tm local;
localtime_r(&now, &local);
return local.tm_gmtoff;
#endif
}