diff options
author | Berthold Stoeger <bstoeger@mail.tuwien.ac.at> | 2020-12-19 12:32:32 +0100 |
---|---|---|
committer | bstoeger <32835590+bstoeger@users.noreply.github.com> | 2020-12-19 20:19:51 +0100 |
commit | fceb3691d9b4ccccf1ebb76f83fb7d58067251d7 (patch) | |
tree | d6a145f13bf4fee7676d6874c0bc3e092194fe52 /profile-widget/profilewidget2.cpp | |
parent | 636c932dfe202c44b6f8d13433dd8fef1c302277 (diff) | |
download | subsurface-fceb3691d9b4ccccf1ebb76f83fb7d58067251d7.tar.gz |
profile: move picture removal from DivePictureItem to ProfileWidget2
On clicking the DivePictureItem "trash" icon, the item would delete
the picture it represents in the currently displayed dive. This needed
an access to the global "displayed_dive" variable, which we want
to get rid of to make the profile more flexible. For example, we
want to render the profile for printing without messing with global
state.
One solution would be to save the dive with every DivePictureItem.
This commit follows a more Qt-ish strategy by handling this via
signals: The close button emits a signal that is recast by the
DivePictureItem and ultimately handled by the ProfileWidget2,
which knows which dive it represents.
Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
Diffstat (limited to 'profile-widget/profilewidget2.cpp')
-rw-r--r-- | profile-widget/profilewidget2.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/profile-widget/profilewidget2.cpp b/profile-widget/profilewidget2.cpp index 09d1dc135..19819eae9 100644 --- a/profile-widget/profilewidget2.cpp +++ b/profile-widget/profilewidget2.cpp @@ -2091,17 +2091,19 @@ void ProfileWidget2::updateThumbnail(QString filename, QImage thumbnail, duratio } // Create a PictureEntry object and add its thumbnail to the scene if profile pictures are shown. -ProfileWidget2::PictureEntry::PictureEntry(offset_t offsetIn, const QString &filenameIn, QGraphicsScene *scene, bool synchronous) : offset(offsetIn), +ProfileWidget2::PictureEntry::PictureEntry(offset_t offsetIn, const QString &filenameIn, ProfileWidget2 *profile, bool synchronous) : offset(offsetIn), duration(duration_t {0}), filename(filenameIn), thumbnail(new DivePictureItem) { + QGraphicsScene *scene = profile->scene(); int size = Thumbnailer::defaultThumbnailSize(); scene->addItem(thumbnail.get()); thumbnail->setVisible(prefs.show_pictures_in_profile); QImage img = Thumbnailer::instance()->fetchThumbnail(filename, synchronous).scaled(size, size, Qt::KeepAspectRatio); thumbnail->setPixmap(QPixmap::fromImage(img)); thumbnail->setFileUrl(filename); + connect(thumbnail.get(), &DivePictureItem::removePicture, profile, &ProfileWidget2::removePicture); } // Define a default sort order for picture-entries: sort lexicographically by timestamp and filename. @@ -2181,7 +2183,7 @@ void ProfileWidget2::plotPicturesInternal(const struct dive *d, bool synchronous // Note that FOR_EACH_PICTURE handles d being null gracefully. FOR_EACH_PICTURE(d) { if (picture->offset.seconds > 0 && picture->offset.seconds <= d->duration.seconds) - pictures.emplace_back(picture->offset, QString(picture->filename), scene(), synchronous); + pictures.emplace_back(picture->offset, QString(picture->filename), this, synchronous); } if (pictures.empty()) return; @@ -2220,7 +2222,7 @@ void ProfileWidget2::picturesAdded(dive *d, QVector<PictureObj> pics) for (const PictureObj &pic: pics) { if (pic.offset.seconds > 0 && pic.offset.seconds <= d->duration.seconds) { - pictures.emplace_back(pic.offset, QString::fromStdString(pic.filename), scene(), false); + pictures.emplace_back(pic.offset, QString::fromStdString(pic.filename), this, false); updateThumbnailXPos(pictures.back()); } } @@ -2232,6 +2234,13 @@ void ProfileWidget2::picturesAdded(dive *d, QVector<PictureObj> pics) calculatePictureYPositions(); } +void ProfileWidget2::removePicture(const QString &fileUrl) +{ + struct dive *d = get_dive_by_uniq_id(displayed_dive.id); + if (d) + Command::removePictures({ { d, { fileUrl.toStdString() } } }); +} + void ProfileWidget2::profileChanged(dive *d) { if (!d || d->id != displayed_dive.id) @@ -2323,7 +2332,7 @@ void ProfileWidget2::pictureOffsetChanged(dive *d, QString filename, offset_t of // The parameters are passed directly to the contructor. // The call returns an iterator to the new element (which might differ from // the old iterator, since the buffer might have been reallocated). - newPos = pictures.emplace(newPos, offset, filename, scene(), false); + newPos = pictures.emplace(newPos, offset, filename, this, false); updateThumbnailXPos(*newPos); calculatePictureYPositions(); } |