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

@ -43,6 +43,17 @@ class QMLManager : public QObject {
Q_PROPERTY(QString progressMessage MEMBER m_progressMessage WRITE setProgressMessage NOTIFY progressMessageChanged)
Q_PROPERTY(bool btEnabled MEMBER m_btEnabled WRITE setBtEnabled NOTIFY btEnabledChanged)
Q_PROPERTY(bool pasteDiveSite MEMBER m_pasteDiveSite)
Q_PROPERTY(bool pasteNotes MEMBER m_pasteNotes)
Q_PROPERTY(bool pasteDiveGuide MEMBER m_pasteDiveGuide)
Q_PROPERTY(bool pasteBuddy MEMBER m_pasteBuddy)
Q_PROPERTY(bool pasteSuit MEMBER m_pasteSuit)
Q_PROPERTY(bool pasteRating MEMBER m_pasteRating)
Q_PROPERTY(bool pasteVisibility MEMBER m_pasteVisibility)
Q_PROPERTY(bool pasteTags MEMBER m_pasteTags)
Q_PROPERTY(bool pasteCylinders MEMBER m_pasteCylinders)
Q_PROPERTY(bool pasteWeights MEMBER m_pasteWeights)
Q_PROPERTY(QString DC_vendor READ DC_vendor WRITE DC_setVendor)
Q_PROPERTY(QString DC_product READ DC_product WRITE DC_setProduct)
Q_PROPERTY(QString DC_devName READ DC_devName WRITE DC_setDevName)
@ -187,16 +198,6 @@ public slots:
void toggleDiveInvalid(int id);
void copyDiveData(int id);
void pasteDiveData(int id);
bool toggleDiveSite(bool toggle);
bool toggleNotes(bool toggle);
bool toggleDiveGuide(bool toggle);
bool toggleBuddy(bool toggle);
bool toggleSuit(bool toggle);
bool toggleRating(bool toggle);
bool toggleVisibility(bool toggle);
bool toggleTags(bool toggle);
bool toggleCylinders(bool toggle);
bool toggleWeights(bool toggle);
void undo();
void redo();
int addDive();
@ -250,11 +251,21 @@ private:
void updateAllGlobalLists();
void updateHaveLocalChanges(bool status);
bool m_pasteDiveSite;
bool m_pasteNotes;
bool m_pasteDiveGuide;
bool m_pasteBuddy;
bool m_pasteSuit;
bool m_pasteRating;
bool m_pasteVisibility;
bool m_pasteTags;
bool m_pasteCylinders;
bool m_pasteWeights;
location_t getGps(QString &gps);
QString m_pluggedInDeviceName;
bool m_showNonDiveComputers;
struct dive *m_copyPasteDive = NULL;
struct dive_components what;
struct dive_paste_data paste_data;
QAction *undoAction;
bool verifyCredentials(QString email, QString password, QString pin);