diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-04-19 18:48:23 +0200 |
---|---|---|
committer | Dirk Hohndel <dirk@hohndel.org> | 2020-05-06 13:58:09 -0700 |
commit | 4374605c1295ede804d1ae1355094f8a3e0429e9 (patch) | |
tree | c1ab60086a08627a8b3d10f25aef14339e5bc792 /desktop-widgets | |
parent | 6ae2d36e381b4f676eb9d8c0e06245989ef16383 (diff) | |
download | subsurface-4374605c1295ede804d1ae1355094f8a3e0429e9.tar.gz |
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 <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'desktop-widgets')
-rw-r--r-- | desktop-widgets/divelistview.cpp | 19 |
1 files changed, 13 insertions, 6 deletions
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<Command::PictureListForAddition> 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() |