fix copy/paste of dive-site

The copy/pasting of dive-sites was fundamentally broken in at least two
ways:

1) The dive-site pointer in struct dive was simply overwritten, which
   breaks internal consistency. Also, no dive-site changed signals where
   sent.

2) The copied dive-site was stored as a pointer in a struct dive. Thus,
   the user could copy a dive, then delete the dive-site and paste.
   This would lead to a dangling pointer and ultimately crash the
   application.

Fix this by storing the UUID of the dive-site, not a pointer.
To do that, don't store a copy of the dive, but collect all
the data in a `dive_paste_data` structure.
If the dive site has been deleted on paste, do nothing.
Send the appropriate signals on pasting.

The mobile version had an additional bug: It kept a pointer to the
dive to be copied, which might become stale by undo.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
Berthold Stoeger 2024-08-13 07:04:52 +02:00 committed by Michael Keller
parent 48b4308a7d
commit 152e6966c9
17 changed files with 359 additions and 425 deletions

View file

@ -38,6 +38,7 @@
#include "core/settings/qPrefDisplay.h"
#include "desktop-widgets/about.h"
#include "desktop-widgets/divecomponentselection.h"
#include "desktop-widgets/divelistview.h"
#include "desktop-widgets/divelogexportdialog.h"
#include "desktop-widgets/divelogimportdialog.h"
@ -207,7 +208,6 @@ MainWindow::MainWindow() :
#ifdef NO_USERMANUAL
ui.menuHelp->removeAction(ui.actionUserManual);
#endif
memset(&what, 0, sizeof(what));
updateManager = new UpdateManager(this);
undoAction = Command::undoAction(this);
@ -1424,13 +1424,13 @@ void MainWindow::on_copy_triggered()
{
// open dialog to select what gets copied
// copy the displayed dive
DiveComponentSelection dialog(this, &copyPasteDive, &what);
DiveComponentSelection dialog(paste_data, this);
dialog.exec();
}
void MainWindow::on_paste_triggered()
{
Command::pasteDives(&copyPasteDive, what);
Command::pasteDives(paste_data);
}
void MainWindow::on_actionFilterTags_triggered()