From 4374605c1295ede804d1ae1355094f8a3e0429e9 Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 19 Apr 2020 18:48:23 +0200 Subject: undo: make adding of pictures undoable This one is a bit hairy, because two things might happen if the picture has a geo location: - A dive gets a newly generated dive site set. - The dive site of a dive is edited. Therefore the undo command has to store keep track of that. Oh my. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'desktop-widgets') diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index fc7d34047..a47c05b67 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -891,20 +891,27 @@ void DiveListView::matchImagesToDives(QStringList fileNames) return; updateLastImageTimeOffset(shiftDialog.amount()); + // Create the data structure of pictures to be added: a list of pictures per dive. + std::vector pics; for (const QString &fileName: fileNames) { struct dive *d; picture *pic = create_picture(qPrintable(fileName), shiftDialog.amount(), shiftDialog.matchAll(), &d); if (!pic) continue; - add_picture(&d->pictures, *pic); - dive_set_geodata_from_picture(d, pic, &dive_site_table); - invalidate_dive_cache(d); + PictureObj pObj(*pic); free(pic); + + auto it = std::find_if(pics.begin(), pics.end(), [d](const Command::PictureListForAddition &l) { return l.d == d; }); + if (it == pics.end()) + pics.push_back(Command::PictureListForAddition { d, { pObj } }); + else + it->pics.push_back(pObj); } - mark_divelist_changed(true); - copy_dive(current_dive, &displayed_dive); - DivePictureModel::instance()->updateDivePictures(); + if (pics.empty()) + return; + + Command::addPictures(pics); } void DiveListView::loadWebImages() -- cgit v1.2.3-70-g09d2