From 74f03e3537ee530000d4b11013bb12de91cb21dd Mon Sep 17 00:00:00 2001 From: Berthold Stoeger Date: Sun, 19 Apr 2020 16:48:53 +0200 Subject: media: move addition of pictures out of create_picture() If we want to make addition of pictures undoable, then create_picture() must not add directly to the dive. Instead, return the dive to which the picture should be added and let the caller perform the addition. This means that the picture-test has to be adapted. Signed-off-by: Berthold Stoeger --- desktop-widgets/divelistview.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'desktop-widgets/divelistview.cpp') diff --git a/desktop-widgets/divelistview.cpp b/desktop-widgets/divelistview.cpp index 403165759..fc7d34047 100644 --- a/desktop-widgets/divelistview.cpp +++ b/desktop-widgets/divelistview.cpp @@ -11,6 +11,7 @@ #include "desktop-widgets/divepicturewidget.h" #include "core/selection.h" #include "core/divefilter.h" +#include "core/divesite.h" // for dive_site_table. TODO: remove once adding pictures is undoified #include #include #include @@ -890,8 +891,16 @@ void DiveListView::matchImagesToDives(QStringList fileNames) return; updateLastImageTimeOffset(shiftDialog.amount()); - for (const QString &fileName: fileNames) - create_picture(qPrintable(fileName), shiftDialog.amount(), shiftDialog.matchAll()); + 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); + free(pic); + } mark_divelist_changed(true); copy_dive(current_dive, &displayed_dive); -- cgit v1.2.3-70-g09d2